2018.12.12
ubuntu1604,CentOS7 及以上版本适用, 红帽官方已使用 chronyd 取代 ntpd 服务程序.
一, 配置 chrony:
1, 停止, 禁用 ntpd 服务 (避免启动了 ntpd 而冲突):
- systemctl disable ntpd
- systemctl stop ntpd
2, 编辑 / etc/chrony.conf:
外网服务器则参考增加以下几行:
- server 0.cn.pool.ntp.org iburst
- server 1.cn.pool.ntp.org iburst
- server 2.cn.pool.ntp.org iburst
- server 3.cn.pool.ntp.org iburst
- server time.Windows.com iburst
3, 允许 chronyd 服务自动启动并启动 chronyd 服务:
- systemctl enable chronyd
- systemctl start chronyd
查看本机是否开始连接时间服务器的 123 端口:
ss -un4a | grep ':123'
4, 查看同步状态:
查看 ntp_servers 状态
chronyc sources -v
查看 ntp_sync 状态
chronyc sourcestats -v
查看 ntp_servers 是否在线
chronyc activity -v
查看 ntp 详细信息
chronyc tracking -v
二, 配置 ntp
1, 停止 chrony 服务 (避免启动了 chrony 而冲突):
- systemctl disable chronyd
- systemctl stop chronyd
2, 编辑 / etc/ntp.conf
外网服务器则参考增加以下几行:
- server 0.cn.pool.ntp.org iburst
- server 1.cn.pool.ntp.org iburst
- server 2.cn.pool.ntp.org iburst
- server 3.cn.pool.ntp.org iburst
- server time.Windows.com iburst
3, 允许 ntpd 服务自动启动并启动 ntpd 服务:
- systemctl enable ntpd
- systemctl start ntpd
查看是否连接服务器 123 端口:
ss -un4a | grep ':123'
4, 查看同步状态:
- [root@svr24 ~]# ntpq -p
- remote refid st t when poll reach delay offset jitter
- ==============================================================================
- x10.1.1.18 LOCAL(0) 11 u 23 64 17 0.798 0.052 0.108
- x10.1.1.19 10.33.0.35 5 u 35 64 17 1.048 -618.28 1.384
- [root@svr24 ~]# ntpstat #初次运行, 尚未同步
- unsynchronised
- polling server every 64 s
- [root@svr24 ~]# ntpstat #等待几分钟后再次运行, 已开始同步.
- synchronised to NTP server (10.33.48.18) at stratum 6
- time correct to within 387 ms
- polling server every 64 s
来源: http://www.bubuko.com/infodetail-2881359.html