赞
踩
设置服务器集群的时间同步,一台机器同时间服务器对时,其他机器与这台服务器对时,就是发生断网等情况,也可以保证内部所有服务器都时间统一;
时间同步方式:找一个机器,作为时间服务器,所有的机器与这台集群时间进行定时的同步,比如,每隔十分钟,同步一次时间;
$ sudo systemctl status ntpd
如果没有安装,则先安装:
$ sudo yum install ntp -y
$ sudo systemctl is-enabled ntpd
$ sudo systemctl stop ntpd
$ sudo systemctl disable ntpd
$ sudo vim /etc/ntp.conf
在
restrict ::1
行下添加如下一行,授权网段 10.2.179.* 上的所有机器可以从这台机器上查询和同步时间
restrict 10.2.179.0 mask 255.255.255.0
$ sudo vim /etc/sysconfig/ntpd
添加如下一行配置:
SYNC_HWCLOCK=yes
重启 ntpd 服务
$ sudo systemctl start ntpd
设置 ntpd 服务开机启动
$ sudo systemctl enable ntpd
在其他服务器上通过 crontab 定期从 ns1 上面同步时间
如:ns2、ns3 等服务器中执行:
$ sudo crontab -e
编写定时任务,每 10 分钟和 ns1 服务器同步一次时间
*/10 * * * * /usr/sbin/ntpdate ns1
修改任意一台机器的时间
$ sudo date -s "2022-8-30 12:00:00"
观察 10 分钟后是否恢复到了正确的时间
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。