chrony实现局域网时间同步

chrony基于cs架构实现,配置一台服务主机与其他客户主机即可

服务端

#yum install chrony --RHEL7默认已安装chrony,而没有安装ntpd.

#systemctl status chronyd --查看chronyd服务状态
#systemctl enable chronyd --开机启动

#vi /etc/chrony.conf    --修改配置文件

#server 0.rhel.pool.ntp.org iburst   --注释这4行,由于是内网环境,所以无法跟外部时间服务器进行时间同步。
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
server 192.168.100.1 iburst    --添加这一行,表示与本机同步时间
 

# Allow NTP client access from local network.
allow 192.168.100.0/24   --允许哪些服务器到这台服务器来同步时间

客户端

#server 0.rhel.pool.ntp.org iburst  --注释这4行
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
server 192.168.100.1 iburst    ---添加该行,表示到这台服务器去同步时间。

重启chrony服务,并开机自启

[root@rhel2 ~]# systemctl restart chronyd.service 
[root@rhel2 ~]# systemctl enable chronyd.service

其他

查看时间同步

[root@rhel2 ~]# timedatectl 
       Local time: Sat 2017-10-07 11:15:43 CST
   Universal time: Sat 2017-10-07 03:15:43 UTC
         RTC time: Sat 2017-10-07 03:02:26
        Time zone: Asia/Shanghai (CST, +0800)
      NTP enabled: no
NTP synchronized: yes   --为yes表示已同步
  RTC in local TZ: no
       DST active: n/a

手动修改时间时,必须把NTP enabled 设置为no.

[root@rhel1 ~]# date
Sun Oct  8 11:00:51 CST 2017
[root@rhel1 ~]# timedatectl
       Local time: Sat 2017-10-07 11:31:45 CST
   Universal time: Sat 2017-10-07 03:31:45 UTC
         RTC time: Sun 2017-10-08 03:01:57
        Time zone: Asia/Shanghai (CST, +0800)
      NTP enabled: no
NTP synchronized: no
  RTC in local TZ: no
       DST active: n/a

如果把NTP enabled 修改为yes时,表示开启自动同步时间,此时,是不能手动修改时间的。

如果为No时,表示关闭自动同步时间。

[root@rhel1 ~]# timedatectl set-ntp yes
[root@rhel1 ~]# timedatectl set-time "2017-10-08 11:00:50"
Failed to set time: Automatic time synchronization is enabled
[root@rhel1 ~]# timedatectl set-ntp no
[root@rhel1 ~]# timedatectl set-time "2017-10-08 11:00:50"
[root@rhel1 ~]# date
Sun Oct  8 11:00:51 CST 2017

猜你喜欢

转载自www.cnblogs.com/soymilk2019/p/10821284.html