配置chrony或ntp时间同步服务(推荐chrony)

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

猜你喜欢

转载自www.cnblogs.com/bytefish/p/10106743.html