ntpd服务安装
[root@hps-1 custom]# yum install -y ntp
如果安装失败存在如下冲突:
请先卸载系统自带ntpdate,重新再执行安装即可:
[root@RQH-TEST-01 yum.repos.d]# yum remove ntpdate -y
[root@hps-1 custom]# yum install -y ntp
修改配置文件,添加并确保以下内容未被注释即可
[root@hps-1 custom]# grep -v ^# /etc/ntp.conf |grep -v ^$
[root@hps-1 custom]# vim /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
restrict 10.1.245.0 mask 255.255.255.0 nomodify notrap
server 127.127.1.0
fudge 127.127.1.0 stratum 8
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
注意:红色加粗部分,需要修改为NTP服务器网段地址、子网掩码。
设置随机启动并启动ntp服务
[root@hps-1 ~]# systemctl enable ntpd
[root@hps-1 ~]# systemctl start ntpd
[root@hps-1 ~]# systemctl status ntpd
验证:
在已经安装ntpdate服务的其他服务器(假设NTP服务器IP为10.1.245.105)上执行:
[root@hps-2 ~]#ntpdate 10.1.245.105
结果类似如下内容表明同步成功。
注:
由于NTP Server自身或与其他NTP Server的同步大概需要5分钟左右,因此请在ntp服务启动五分钟后执行以上验证操作。
如果其他服务器上的时间与NTP Server上的相差很大的话,必须先手动在其他服务器上修改时间后才能同步成功。修改方法为:
[root@hps-1 ~]# date -s “YYYY-MM-DD HH:MM:SS”
[root@hps-1 ~]# hwclock -w