前言
在实际生产环境中集群的各节点的时间,在运行中时间的偏差会逐渐增大。这时我们可以通过搭建NTP服务来保证所有节点的时间同步。
1、环境
2台(CentOS7.X),NTP服务器IP:10.10.35.116,客户端IP:10.10.35.114
2、配置yum源,服务端安装ntp并配置
vim /etc/yum.repos.d/CentOS-Base.repo
----清理yum源
yum clean all
----查看源
yum list all
----安装NTP
yum install ntp
----修改配置文件:
vim /etc/ntp.conf
在restrict ::1下面添加如下几行
restrict default nomodify
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
logfile /var/log/ntp.log #日志文件
注释掉下面几行:
#Please consider joining the pool (http://www.pool.ntp.org/join.html).
#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服务,并且记得关闭防火墙
systemctl restart ntpd.service
systemctl enable ntpd.service
3、客户端配置
----安装NTP
yum install ntp
----编辑NTP配置文件,添加内容如下
vim /etc/ntp.conf
server 10.10.35.116 iburst
fudge 127.127.1.0 stratum 10
logfile /var/log/ntp.conf
接着启动ntp服务,并且关闭防火墙
systemctl restart ntpd.service
systemctl enable ntpd.service
大概3-5分钟就会自动同步了。