关闭selinux
[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 Architecture: x86_64 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 Relocations : (not relocatable) 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 systems with intermittent internet connections, but it also works well 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***v@.service
/usr/lib/systemd/system/chrony-dn***v@.timer
/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