由于多台服务器中只有服务器A能访问互联网,故用该服务器搭建ntp时钟同步服务,自动同步网络时间,其余的服务器皆作为客户端,自动同步服务器A的时间。
服务器A
-
确认是否安装ntp
rpm -qa|grep ntp
-
若未安装,则安装ntp
yum -y install ntp
-
修改ntp配置文件
vim /etc/ntp.conf # ** 新增配置 ** restrict 服务器A的ip mask 255.255.252.0 nomodify notrap server 127.127.1.0 fudge 127.127.1.0 stratum 10 # ** 将配置文件中的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.conf配置文件详解: https://blog.csdn.net/qq_35663625/article/details/103064495
查看时间,并校验
启动ntp的服务:service ntpd start 或者 systemctl start ntpd
-
设置ntp服务开机自启动:systemctl enable ntpd
ntp服务器查看状态: https://blog.csdn.net/kingzdd/article/details/80106081
其他服务器
-
配置crontab,使用命令:crontab -e, 然后添加:
*/1 * * * * /usr/sbin/ntpdate 服务器A的ip