Linux server time synchronization configuration
CentOS7 time to do the server, other servers (Centos 6, RHEL7) to synchronize the server time
RHEL 7, CentOS 7 default network time protocol Chrony
This tutorial time server server host name: CentOS7-Node3 IP: 192.168.231.130
1 client hostname: RHEL7-Node1
2 client hostname: CentOS6-Node2
Server:
First check the service status under chrony
[root@CentOS7-Node3 ~]# systemctl status chronyd
Unit chronyd.service could not be found.
If the query is not the service, you can install yum
[root@CentOS7-Node3 ~]# yum install -y chrony
Start chrony Service
[root@CentOS7-Node3 ~]# systemctl start chronyd
Check status
[root@CentOS7-Node3 ~]# systemctl status chronyd
● chronyd.service - NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2018-06-07 10:20:28 CST; 2s ago Docs: man:chronyd(8) man:chrony.conf(5) Process: 6031 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS) Process: 6027 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS) Main PID: 6029 (chronyd) CGroup: /system.slice/chronyd.service └─6029 /usr/sbin/chronyd Jun 07 10:20:28 CentOS7-Node3 systemd[1]: Starting NTP client/server... Jun 07 10:20:28 CentOS7-Node3 chronyd[6029]: chronyd version 3.2 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +...DEBUG) Jun 07 10:20:28 CentOS7-Node3 chronyd[6029]: Initial frequency -29.914 ppm Jun 07 10:20:28 CentOS7-Node3 systemd[1]: Started NTP client/server. Jun 07 10:20:33 CentOS7-Node3 chronyd[6029]: Selected source 37.218.240.198 Jun 07 10:20:33 CentOS7-Node3 chronyd[6029]: System clock wrong by -3.020089 seconds, adjustment started Jun 07 10:20:30 CentOS7-Node3 chronyd[6029]: System clock was stepped by -3.020089 seconds Hint: Some lines were ellipsized, use -l to show in full.
Time server configuration as follows:
[root@CentOS7-Node3 ~]# vim /etc/chrony.conf
25 # Allow NTP client access from local network.
26 allow 192.168.231.0/24
27
28 # Serve time even if not synchronized to a time source. 29 local stratum 10
Three servers time, CentOS7-Node3 normal time
Client Configuration:
Client 1:
The server 0.rhel.pool.ntp.org iburst --- server 3.rhel.pool.ntp.org iburst delete or comment
Add \ modify the configuration:
server 192.168.231.130 iburt
allow 192.168.231.0/24
[root@RHEL7-Node1 ~]# vim /etc/chrony.conf
1 # Use public servers from the pool.ntp.org project.
2 # Please consider joining the pool (http://www.pool.ntp.org/join.html). 3 #server 0.rhel.pool.ntp.org iburst 4 #server 1.rhel.pool.ntp.org iburst 5 #server 2.rhel.pool.ntp.org iburst 6 #server 3.rhel.pool.ntp.org iburst 7 server 192.168.231.130 iburst 8 # Ignore stratum in source selection. 9 stratumweight 0 10 11 # Record the rate at which the system clock gains/losses time. 12 driftfile /var/lib/chrony/drift 13 14 # Enable kernel RTC synchronization. 15 rtcsync 16 17 # In first three updates step the system clock instead of slew 18 # if the adjustment is larger than 10 seconds. 19 makestep 10 3 20 21 # Allow NTP client access from local network. 22 allow 192.168.231.0/24
After editing, save, restart the service to take effect chrony
[root@RHEL7-Node1 ~]# systemctl restart chronyd
Client 2 CentOS6-Node2
CentOS 6 is NTP
Execute ntpdate 192.168.231.130
[root@CentOS6-Node2 ~]# ntpdate 192.168.231.130
7 Jun 16:59:34 ntpdate[1563]: the NTP socket is in use, exiting
If the above error occurs, the ntp service stops, and then execute ntpdate 192.168.231.130
[root@CentOS6-Node2 ~]# service ntpd stop
Shutting down ntpd: [ OK ] [root@CentOS6-Node2 ~]# ntpdate 192.168.231.130 7 Jun 17:00:19 ntpdate[1578]: step time server 192.168.231.130 offset -13589998.9 54539 sec[root@CentOS6-Node2 ~]# service ntpd status ntpd is stopped [root@CentOS6-Node2 ~]# date Thu Jun 7 17:00:37 CST 2018
Then add time synchronization in the scheduled task
[root@CentOS6-Node2 ~]# crontab -e
0-59/10 * * * * /usr/sbin/ntpdate 192.168.231.130
10 minutes Synchronization once
Now see the next three servers is consistent with the time