某次升级迁移中,由于客户ESXI未配置时间,导致虚拟机从ESXI同步到错误时间影响到了业务,故之后我们为客户新部署了一台NTP服务器用于同步内网服务器时间。

使用yum安装ntp服务器。

yum install -y ntp

编辑 /etc/ntp.conf文件,调整NTP服务器配置,推荐使用阿里云等国内云服务商的NTP服务器。

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    # 当外部时间服务器不可用,使用本机时间作为时间服务的标准
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

设置NTP服务器及服务自启动。

systemctl enable ntpd
systemctl start ntpd
systemctl status ntpd

验证NTP服务器。

ntpq -p
date -R

修改Linux系统时区。

rm -rf /etc/localtime    #删除当前默认时区
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

CentOS7中默认chronyd服务为自启动,这将会影响NTP自启动,所以需要将chronyd禁用启动。

systemctl disable chronyd

验证NTP服务器运行状态。

[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

相关新闻

联系我们

联系我们

400-0512-768

邮件:support@sworditsys.com

工作时间:周一至周五 8:00 - 21:00

分享本页
返回顶部