Linux下ntp时间服务器搭建
环境准备
- 系统:CenOS7.5
- 虚拟机:172.8.10.140-147
- 主:172.8.10.140 从:172.8.10.141-147
一、确认ntp的安装
1、确认是否已安装ntp
rpm -qa|grep -i ntp
2、删除已安装ntp
rpm -ev xxx —nodeps #强制性卸载xx服务
rpm -ev fontpackages-filesystem-1.44-8.el7.noarch ntpdate-4.2.6p5-28.el7.centos.x86_64 ntp-4.2.6p5-28.el7.centos.x86_64 —nodeps
3、重新安装ntp
yum install ntp
- 如出现以上内容,说明yum服务被占用,杀死原先yum占用的进行,然后重新安装
ps -aux | grep yum
kill -9 pid
二、配置ntp服务
1、修改所有节点的/etc/ntp.conf
vim /etc/ntp.conf
- 加入以下内容
restrict 172.8.10.140 nomodify notrap nopeer noquery #当前节点IP地址
restrict 172.8.10.1 mask 255.255.255.0 nomodify notrap #集群所在网段的网关(Gateway),子网掩码(Genmask)
- 查看网关和子网掩码
route -n
- 其他节点同上
2、在主节点上,修改/etc/ntp.conf
vim /etc/ntp.conf
- 在server部分添加一下部分,并注释掉server 0 ~ n
server 127.127.1.0
Fudge 127.127.1.0 stratum 10
3、从节点上,修改/etc/ntp.conf
vim /etc/ntp.conf
- 在server部分添加如下语句,将server指向主节点。并注释掉server 0 ~ n
server 172.8.10.140
Fudge 172.8.10.140 stratum 10
三、启动ntp服务、查看状态
1、启动服务(所有节点)
service ntpd start
- 查看状态
service ntpd status
2、查看ntp服务器有无和上层ntp连通
ntpstat
- 查看ntp状态时,可能会出现如下所示情况
unsynchronised time server re-starting polling server every 8 s
unsynchronised polling server every 8 s
- 这种情况属于正常,ntp服务器配置完毕后,需要等待5-10分钟才能与/etc/ntp.conf中配置的标准时间进行同步。等一段时间之后,再次使用ntpstat命令查看状态,就会变成如下正常结果:
3、查看ntp服务器与上层ntp的状态
ntpq -p
- remote:本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先
- refid:参考上一层ntp主机地址
- st:stratum阶层
- when:多少秒前曾经同步过时间
- poll:下次更新在多少秒后
- reach:已经向上层ntp服务器要求更新的次数
- delay:网络延迟
- offset:时间补偿
- jitter:系统时间与bios时间差
四、设置开机启动
chkconfig ntpd on
参考:https://www.cnblogs.com/quchunhui/p/7658853.html
还没有评论,来说两句吧...