Multi-host collaboration work is that the time synchronization of each host is very important. Time inconsistency will cause many important application failures, such as encryption protocol, log, cluster and so on. NTP protocol is used to synchronize the time of each computer in the network. Currently, NTP protocol is a prerequisite in the operations and maintenance infrastructureOne of the services.
Time synchronization implementation: ntp,chrony
ntp
ntp synchronizes UTC when system time is coordinated with the world. The accuracy can reach 0.1ms in LAN and 1-50ms in most places on Internet. The ntp service is currently used on CentOS 6.
Deployment of ntp
Experiments show that: Host A synchronizes time from the host on the Internet and serves as a time server in the LAN. Host B automatically goes to Host A to synchronize time. Experimental preparation Prepare A, B and two hosts |
Host | system | ip |
---|---|---|---|
A | CentOS6 | 192.168.73.137 | |
B | CentOS6 | 192.168.73.136 |
Slow down the time of host B
[root@HostB ~]# date -s "-10 days" Sun Apr 7 10:50:51 CST 2019 [root@HostB ~]# date Sun Apr 7 10:50:58 CST 2019
Check Host A Time
[root@HostA ~]# date Wed Apr 17 10:53:35 CST 2019
Setting Host A as a Time Server
1. Modify/etc/ntp
[root@HostA ~]# vim /etc/ntp.conf ... #restrict default kod nomodify notrap nopeer noquery #Note this line in the file, or modify it to the following line restrict default kod nomodify ... #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 172.22.0.1 iburst #Point the time server to the external time server. ...
2. Synchronize Host A with Outer Network Time Server
[root@HostA ~]# ntpdate 172.22.0.1 18 Apr 10:27:53 ntpdate[3825]: adjust time server 172.22.0.1 offset 0.004437 sec
3. Start ntp service and set ntp service to boot
[root@HostA ~]# service ntpd start Starting ntpd: [ OK ] [root@HostA ~]# chkconfig ntpd on
2. Modify Host B Configuration File to Automatic and Host A Synchronization Time
1. Modify the configuration file to point the time server to host A
#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 192.168.73.140 iburst #Add this trip
2. Start the service.
[root@HostB ~]# service ntpd start Starting ntpd: [ OK ] [root@HostB ~]# date #Because ntp service synchronization speed is slow, it takes a long time to synchronize hard press Mon Apr 8 10:34:43 CST 2019 [root@HostB ~]# service ntpd restart Shutting down ntpd: [ OK ] Starting ntpd: [ OK ] [root@HostB ~]# date #Restart the service again, and the time is automatically synchronized. Thu Apr 18 10:34:54 CST 2019
CentOS7 chrony
Experiments show that:
Host A just configured is used as the time server in the Internet. Host 7A synchronizes time from Host A and serves as time server in LAN. Host 7B automatically goes to Host 7A to synchronize time.
chrony deployment
Experimental preparation Prepare 7A, 7B, two mainframes |
host name | system | IP |
---|---|---|---|
7A | CentOS7 | 192.168.73.150 | |
7B | CentOS7 | 192.168.73.139 |
Configuration of time servers
1. Modify Host 7A Configuration File to Modify / etc/chrony.conf
[root@7a ~]# vim /etc/chrony.conf ... server 192.168.73.140 iburst #Add this line to the time server in the network ... allow 192.168.73.0/24 #Added segments that are allowed to be accessed when you are a time server ... local stratum 10 #Remove the notes before this trip
2. Start the chronyd service and set it to boot
[root@7a ~]# systemctl start chronyd.service [root@7a ~]# systemctl enable chronyd.service Created symlink from /etc/systemd/system/multi-user.target.wants/chronyd.service to /usr/lib/systemd/system/chronyd.service.
2. Configure the server in LAN and point the time server to 7A
1. Modify the configuration file
[root@7b ~]# 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 192.168.73.150 iburst #Add this trip
2. Start the chrony service and set it to boot automatically
[root@7b ~]# systemctl start chronyd [root@7b ~]# systemctl enable chronyd Created symlink from /etc/systemd/system/multi-user.target.wants/chronyd.service to /usr/lib/systemd/system/chronyd.service.
3. View time synchronization
[root@7b ~]# chronyc sources 210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* 192.168.73.150 5 6 177 31 +50us[ +77us] +/- 218ms [root@7b ~]#