1. 程式人生 > >配置chrony或ntp時間同步服務(推薦chrony)

配置chrony或ntp時間同步服務(推薦chrony)

ats root 停止 自動 cor etc 信息 conf 等待

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

配置chrony或ntp時間同步服務(推薦chrony)