時間同步服務 chrony
[root@centos7 ~]#vim /etc/selinux/config
SELINUX=disabled
關閉防火墻
[root@centos7 ~]#systemctl stop firewalld
.=====================================================================.
[root@centos7 ~]#rpm -qi chrony //centOS7 上自帶chrony
Name : chrony
Version : 3.2
Release : 2.el7
Install Date: Sun 09 Dec 2018 10:15:41 PM CST
Group : System Environment/Daemons
Size : 487489
License : GPLv2
Signature : RSA/SHA256, Wed 25 Apr 2018 06:55:05 PM CST, Key ID 24c6a8a7f4a80eb5
Source RPM : chrony-3.2-2.el7.src.rpm
Build Date : Fri 13 Apr 2018 01:38:53 AM CST
Build Host : x86-01.bsys.centos.org
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : https://chrony.tuxfamily.org
Summary : An NTP client/server
Description :
A client/server for the Network Time Protocol, this program keeps your
computer‘s clock accurate. It was specially designed to support
in permanently connected environments. It can use also hardware reference
clocks, system real-time clock or manual input as time references.
[root@centos7 ~]#rpm -ql chrony
/etc/NetworkManager/dispatcher.d/20-chrony
/etc/chrony.conf //配置文件
/etc/chrony.keys
/etc/dhcp/dhclient.d/chrony.sh
/etc/logrotate.d/chrony
/etc/sysconfig/chronyd
/usr/bin/chronyc /usr/lib/systemd/ntp-units.d/50-chronyd.list
/usr/lib/systemd/system/chrony-dn***[email protected]
br/>/usr/lib/systemd/ntp-units.d/50-chronyd.list
/usr/lib/systemd/system/chrony-dn***[email protected]
/usr/lib/systemd/system/chrony-wait.service
/usr/lib/systemd/system/chronyd.service //chrony服務
/usr/libexec/chrony-helper
/usr/sbin/chronyd //chrony 二進制程序服務器端
/usr/share/doc/chrony-3.2
/usr/share/doc/chrony-3.2/COPYING
/usr/share/doc/chrony-3.2/FAQ
/usr/share/doc/chrony-3.2/NEWS
/usr/share/doc/chrony-3.2/README
/usr/share/man/man1/chronyc.1.gz
/usr/share/man/man5/chrony.conf.5.gz
/usr/share/man/man8/chronyd.8.gz
/var/lib/chrony
/var/lib/chrony/drift
/var/lib/chrony/rtc
/var/log/chrony
啟動chrony服務
[root@centos7 ~]#systemctl start chronyd.service //啟動chrony服務
[root@centos7 ~]#systemctl enable chronyd.service //設為開機啟動
[root@centos7 ~]#systemctl status chronyd.service //查看服務狀態
配置chrnoy客戶端
[root@centos7 ~]#vim /etc/chrony.conf
#以阿裏雲公共NTP服務器為準,來同步客戶端時間
server ntp.aliyun.com iburst
#註釋下面4行
#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
[root@centos7 ~]#chronyc sources -v //chronyc為客戶端命令, sources -v 顯示當前NTP服務器端信息
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
.==============================================================================================
^ 203.107.6.88 2 6 17 29 -2123us[-9477us] +/- 23ms
===============================================================================================
以centOS7 為ntp服務器端(192.168.21.104),配置centOS6 為chrony客戶端(192.168.21.103), 從centOS7上同步時間:
在centOS6上安裝chrony
[root@centOS6 ~]#yum install chrony -y
關閉ntpd服務,避免幹擾!
[root@centOS6 ~]#service ntpd status
ntpd is stopped
客戶端配置
[root@centOS6 ~]#vim /etc/chrony.conf
server 192.168.21.104 iburst //添加從centOS7上同步時間
#註釋下面4行
#server 0.rhel.pool.ntp.org iburst
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
[root@centOS6 ~]#service chronyd start //啟動chrony服務
[root@centOS6 ~]#chkconfig chronyd on //添加chrony為開機啟動
服務器端配置
[root@centos7 ~]#vim /etc/chrony.conf
server ntp.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
.# Allow NTP client access from local network.
#allow 192.168.0.0/16
allow 192.168.21.0/24 //添加允許哪個網段可以從服務器端同步時間
[root@centos7 ~]#systemctl restart chronyd //重啟chrony服務
在centOS6上測試
[root@centOS6 ~]#date -s "-2 year" //先把時間改錯
Tue Feb 14 09:49:54 EST 2017
[root@centOS6 ~]#date
Tue Feb 14 09:49:59 EST 2017
重啟服務後,時間已經同步
[root@centOS6 ~]#service chronyd restart
Stopping chronyd: [ OK ]
Starting chronyd: [ OK ]
[root@centOS6 ~]#date
Thu Feb 14 09:52:36 EST 2019
把EST改為CST
[root@centOS6 ~]#ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[root@centOS6 ~]#ll /etc/localtime
lrwxrwxrwx 1 root root 33 Feb 14 23:13 /etc/localtime -> /usr/share/zoneinfo/Asia/Shanghai
[root@centOS6 ~]#date
Thu Feb 14 23:13:28 CST 2019
時間同步服務 chrony