某次升級遷移中,由于客戶ESXI未配置時間,導致虛擬機從ESXI同步到錯誤時間影響到了業(yè)務(wù),故之后我們?yōu)榭蛻粜虏渴鹆艘慌_NTP服務(wù)器用于同步內(nèi)網(wǎng)服務(wù)器時間。
使用yum安裝ntp服務(wù)器。
yum install -y ntp
編輯 /etc/ntp.conf文件,調(diào)整NTP服務(wù)器配置,推薦使用阿里云等國內(nèi)云服務(wù)商的NTP服務(wù)器。
vim /etc/ntp.conf
server ntp.aliyun.com
server ntp1.aliyun.com
server ntp2.aliyun.com
server ntp3.aliyun.com
server 127.127.1.0 iburst # 當外部時間服務(wù)器不可用,使用本機時間作為時間服務(wù)的標準
fudge 127.127.1.0 stratum 10 #這個值不能太高0-15,太高會報錯
#添加允許訪問的ip段
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.2.0 mask 255.255.255.0 nomodify notrap
firewalld-cmd放行ntp端口。
firewall-cmd --permanent --zone=public --add-port=123/udp
firewall-cmd --reload
設(shè)置NTP服務(wù)器及服務(wù)自啟動。
systemctl enable ntpd
systemctl start ntpd
systemctl status ntpd
驗證NTP服務(wù)器。
ntpq -p
date -R
修改Linux系統(tǒng)時區(qū)。
rm -rf /etc/localtime #刪除當前默認時區(qū)
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
CentOS7中默認chronyd服務(wù)為自啟動,這將會影響NTP自啟動,所以需要將chronyd禁用啟動。
systemctl disable chronyd
驗證NTP服務(wù)器運行狀態(tài)。
[root@ntp ~]# systemctl status ntpd
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2021-04-07 12:11:43 CST; 10h ago
Process: 753 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 763 (ntpd)
CGroup: /system.slice/ntpd.service
└─763 /usr/sbin/ntpd -u ntp:ntp -g
Apr 07 12:11:45 ntp.haobro.cn ntpd_intres[774]: DNS ntp1.aliyun.com -> 120.25.115.20
Apr 07 12:11:47 ntp.haobro.cn ntpd[763]: Listen normally on 4 ens192 192.168.1.217 UDP 123
Apr 07 12:11:47 ntp.haobro.cn ntpd[763]: Listen normally on 5 ens192 fe80::15ba:407:6285:c813 UDP 123
Apr 07 12:11:47 ntp.haobro.cn ntpd[763]: new interface(s) found: waking up resolver
Apr 07 12:29:19 ntp.haobro.cn ntpd[763]: 0.0.0.0 0612 02 freq_set kernel 75.478 PPM
Apr 07 12:29:19 ntp.haobro.cn ntpd[763]: 0.0.0.0 0615 05 clock_sync
Apr 07 13:52:55 ntp.haobro.cn ntpd[763]: 0.0.0.0 0613 03 spike_detect -0.132985 s
Apr 07 14:08:00 ntp.haobro.cn ntpd[763]: 0.0.0.0 061c 0c clock_step -0.132493 s
Apr 07 14:08:00 ntp.haobro.cn ntpd[763]: 0.0.0.0 0615 05 clock_sync
Apr 07 14:08:02 ntp.haobro.cn ntpd[763]: 0.0.0.0 c618 08 no_sys_peer