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 --容许哪些服务器到这台服务器来同步时间
客户端spa
#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服务,并开机自启rest
[root@rhel2 ~]# systemctl restart chronyd.service
[root@rhel2 ~]# systemctl enable chronyd.service
其余code
查看时间同步server
[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.blog
[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时,表示关闭自动同步时间。io
[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