【笔记】集群时间同步

前言

通过ntp命令,实现集群间时间同步

配置主机

修改ntp配置文件

  • 为以下内容去除注释
/etc/ntp.conf
1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
  • 为以下内容添加注释
/etc/ntp.conf
1
2
3
4
#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服务从本地时钟获取时间
/etc/ntp.conf
1
2
server 127.127.1.0
fudge 127.127.1.0 stratum 10

修改ntpd配置文件

  • 添加以下内容,同步硬件时钟
/etc/sysconfig/ntpd
1
SYNC_HWCLOCK=yes

重启ntp服务

1
service ntpd restart

设置ntp服务开机启动

1
chkconfig ntpd on

配置从机

  • 每隔1分钟同步一次时间
1
crontab -e

<ip>:主机IP地址

1
*/1 * * * * /usr/sbin/ntpdate <ip>

完成

参考文献

哔哩哔哩——zhvsvd