如果服务器在公网环境(能连接外网),可以不采用集群时间同步,因为服务器会定期和公网时间进行校准。
如果没有ntp服务,可以使用yum install ntp或者apt-get install ntp命令来安装ntp服务。
sudo systemctl status ntpd sudo systemctl start ntpd sudo systemctl is-enabled ntpd
sudo vim /etc/ntp.conf
#restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap 为restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap
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 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 127.127.1.0 fudge 127.127.1.0 stratum 10
sudo vim /etc/sysconfig/ntpd
增加内容如下(让硬件时间与系统时间一起同步)
SYNC_HWCLOCK=yes
sudo systemctl start ntpd
sudo systemctl enable ntpd
(1)关闭所有节点上ntp服务和自启动
sudo systemctl stop ntpd sudo systemctl disable ntpd sudo systemctl stop ntpd sudo systemctl disable ntpd
(2)在其他机器配置1分钟与时间服务器同步一次
sudo crontab -e
编写定时任务如下:
*/1 * * * * /usr/sbin/ntpdate ip
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70024433/viewspace-2978501/ ,如需转载,请注明出处,否则将追究法律责任。