服务端IP 10.0.0.200 客户端IP 10.0.0.240 服务端安装 yum install chrony -y 查看配置文件 rpm -ql chrony /var/lib/chrony 客户端 /usr/sbin/chronyd 服务端 主配置文件 /etc/chrony.conf 编辑配置文件添加时间服务器 vim /etc/chrony.conf 默认是centos官方的 server 0.centos.pool.ntp.org iburst server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst server 3.centos.pool.ntp.org iburst 输入i进入编辑模式,再来粘贴以下内容 添加以下阿里云的 server ntp1.aliyun.com iburst server ntp2.aliyun.com iburst server 0.centos.pool.ntp.org iburst server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst server 3.centos.pool.ntp.org iburst #添加运行同步时间的客户端IP段或者所有原内容 # Allow NTP client access from local network. #allow 192.168.0.0/16 #修改过后的内容,允许10.0.0.0/24这个网段内的所有客户端同步时间 # Allow NTP client access from local network. allow 10.0.0.0/24 如果是所有ip都运行访问格式入下 #0.0.0.0/0 或者是192.168.1.0/24 根据自己的实际IP填写 服务器在不链网络的情况下是无法同步时间的,为了不给客户端提供错误的时间,服务器在不联的情况是拒绝给客户端同步时间的,所以我们可以添加自己的做为网络服务器,让客户端同步 我们需要启用以下功能 原内容 #local stratum 10 修改后 local stratum 10 #我这里是10.0.0.0的网段内的所有服务器都运行同步 保存退出 先按esc键 再按shift+:(冒号)wq回车 w保存 q退出 启动服务 systemctl start chronyd 开机自启动 systemctl enable chronyd 查看服务状态 systemctl status chronyd 返回结果 ● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2020-05-05 22:07:23 EDT; 37min ago Docs: man:chronyd(8) man:chrony.conf(5) Main PID: 7020 (chronyd) CGroup: /system.slice/chronyd.service └─7020 /usr/sbin/chronyd May 05 22:07:23 centos7.6-1 systemd[1]: Starting NTP clien... May 05 22:07:23 centos7.6-1 chronyd[7020]: chronyd version... May 05 22:07:23 centos7.6-1 chronyd[7020]: Frequency -2662... May 05 22:07:23 centos7.6-1 systemd[1]: Started NTP client... May 05 22:07:31 centos7.6-1 chronyd[7020]: Selected source... May 05 22:07:32 centos7.6-1 chronyd[7020]: Source 193.182.... May 05 22:14:02 centos7.6-1 chronyd[7020]: Selected source... Hint: Some lines were ellipsized, use -l to show in full. 以上是返回结果 客户端同步时间,这种同步中 先来安装软件,自己做服务端也做客户端 yum install chrony -y 编辑配置文件添加时间服务器 vim /etc/chrony.conf 源内容 server 0.centos.pool.ntp.org iburst server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst server 3.centos.pool.ntp.org iburst 修改以后 #server 0.centos.pool.ntp.org iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst server 10.0.0.200 iburst Centos7 启动方法 启动服务 systemctl start chronyd 开机自启动 systemctl enable chronyd Centos6启动方法 启动服务 service chronyd start 开机自启动 chkconfig chronyd on 查看时间同步状态 [root@ldap ~]# chronyc 返回结果 chronyc> chronyc> sources 返回结果 210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* 10.0.0.200 3 6 377 1 +212us[ +97us] +/- 17ms 可以看到同步的服务器和时间等信息 看时间同步状态,有没有完成同步 chronyc> sourcestats 210 Number of sources = 1 Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev ============================================================================== 10.0.0.200 6 5 323 +0.013 0.952 +415ns 29us 退出交互模式 chronyc> exit 非交互模式下显示更详细的信息 [root@ldap ~]# chronyc sources -v 返回结果 210 Number of sources = 1 .-- Source mode '^' = server, '=' = peer, '#' = local clock. / .- Source state '*' = current synced, '+' = combined , '-' = not combined, | / '?' = unreachable, 'x' = time may be in error, '~' = time too variable. || .- xxxx [ yyyy ] +/- zzzz || Reachability register (octal) -. | xxxx = adjusted offset, || Log2(Polling interval) --. | | yyyy = measured offset, || \ | | zzzz = estimated error. || | | \ MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* 10.0.0.200 3 6 377 59 -2775ns[ -41us] +/- 18ms 参数解释:chrony.conf server 指明时间服务器地址 allow NETADD/NETMASK allow all 允许所有客户端主机 deny NETADD/NETMASK bindcmdaddress 命令管理接口监听地址 local stratum 10 即使自己未能通过网络时间服务器同步时间,也允许将本地时间作为标准时间授时给其他客户端