一、开启ntpd服务

sudo systemctl start ntpd

二、.修改/etc/ntp.conf配置文件

修改一:(授权 192.168.10.0-192.168.10.255 网段上的所有机器可以从这台机器上查
询和同步时间)
#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

三、修改 /etc/sysconfig/ntpd文件

vim /etc/sysconfig/ntpd
增加内容如下:(让硬件时间与系统时间一起同步)
SYNC_HWCLOCK=yes

重启ntpd服务
sudo systemctl restart ntpd
设置ntpd服务开机启动
sudo systemctl enable ntpd

四、其他机器配置

关闭所有节点机器上的ntpd服务与自启动
sudo systemctl stop ntpd
sudo systemctl disable ntpd

所有节点机器设置定时任务1 分钟与时间服务器同步一次
sudo crontab -e
编写定时任务如下:

*/1 * * * * /usr/sbin/ntpdate 时间服务器主机名

任意修改系统时间
sudo date -s “2035-6-6 06:06:06”

1 分钟后查看机器是否与时间服务器同步
sudo date

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐