一、所有服务器安装时间同步程序

yum install ntp ntpdate -y

二、选择一个主服务器同步外网时间,修改配置

编辑文件 ​​/etc/ntp.conf​​,该服务器的IP地址例如为 ​​192.168.1.64​

注释原有的 ntp server 配置,然后添加新的,如下:

# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#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 ntp3.aliyun.com iburst

如下内容,取消掉 ​​restrict​​​ 前面的注释,保证 ​​192.168.1.0​​ 为本机所属网段一致

#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

三、其他服务配置

编辑文件 ​​/etc/ntp.conf​

注释原有的 ntp server 配置,然后添加新的,如下:

# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#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 192.168.1.64 prefer

四、所有服务器重启 ntp 服务

service ntpd restart
systemctl disable chronyd.service
systemctl enable ntpd.service

五、在除主服务器之外的其他服务器进行测试

输入 ​​ntpq -p​​ 出现以下结果:

[root@server3 soft]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
192.168.1.64 203.107.6.88 3 u 43 64 0 0.000 0.000 0.000

说明时间已经同步。


(END)