ntp 时间同步

假设有3台服务器

  1. 192.168.1.10(ntp服务端)

  2. 192.168.1.11(ntp客户端)

  3. 192.168.1.12(ntp客户端)

ntp 服务端

/etc/ntp.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 注释原有的server
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst

# 第一种:读取远端服务器时钟
server 远端IP

# 第二种:以本机时钟为准。注意:不是127.0.0.1,而是127.127.1.0
server 127.127.1.0

# 如果启用了chronyd,需要禁用 chronyd 否则 ntpd 配置开机启动会不生效
## 查看是否开机启动
# systemctl is-enabled chronyd
# sudo systemctl disable chronyd
# 开机启动
sudo systemctl enable ntpd
sudo systemctl start ntpd
sudo systemctl restart ntpd
systemctl status ntpd
ntpq -p
ntpstat

ntp 客户端

分别在192.168.1.11192.168.1.12做以下配置

/etc/ntp.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 注释原有的server
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst

# 配置允许NTP Server时间服务器主动修改本机的时间
restrict 192.168.1.10 nomodify notrap noquery
# 读取内网ntp服务器时间
server 192.168.1.10

sudo systemctl start ntpd;
sudo systemctl restart ntpd;
sudo systemctl enable ntpd;
systemctl status ntpd;
ntpq -p;
ntpstat;

查看状态

1
2
3
4
5
6
7
8
9
[yl@192.168.1.11 home]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
192.168.1.10 LOCAL(0) 6 u 46 64 3 0.622 -158833 0.014

[yl@192.168.1.11 home]# ntpstat
synchronised to NTP server (192.168.1.10) at stratum 7
time correct to within 20 ms
polling server every 128 s

说明配置成功

  • 本文作者: forever杨
  • 本文链接: https://blog.yl-online.top/posts/b3b5b23f.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。如果文章内容对你有用,请记录到你的笔记中。本博客站点随时会停止服务,请不要收藏、转载!