1. NTP server configuration

1. Install NTP and NTPDate
yum -y install ntp ntpdate
Copy the code
2. Edit the NTP service configuration file

Synchronize time from the external server preferentially. If the external connection fails, synchronize time from the local server.

Conf file driftfile /var/lib/ntp/drift # chown NTP: NTP /var/log/ntpd.log # chcon-t Log # Default log path of the NTP server /var/log/messages logfile /var/log/ntpd.log # Permit time synchronization with our time source, but do not # permit the source to query or modify the service on this system. restrict default nomodify notrap nopeer noquery # Permit all access over the loopback interface. This could # be tightened as well, But to do so would effect some of # the administrative functions. Restrict 127.0.0.1 RESTRICT ::1 Restrict 192.168.33.0 mask 255.255.255.0 nomodify notrap # Synchronize time server from the following list of time servers  0.asia.pool.ntp.org iburst server 1.asia.pool.ntp.org iburst server 2.asia.pool.ntp.org iburst server 3.asia.pool.ntp.org iBurst # When the external time server is unavailable, Use local server time server 127.127.1.0 iburst fudge 127.127.1.0 stratum 10 # to allow upper-layer servers to change restrict 0.asia.pool.ntp.org nomodify notrap noquery restrict 1.asia.pool.ntp.org nomodify notrap noquery restrict 2.asia.pool.ntp.org nomodify notrap noquery  restrict 3.asia.pool.ntp.org nomodify notrap noquery includefile /etc/ntp/crypto/pw keys /etc/ntp/keys disable monitorCopy the code
3. Run the command
[root@ironman ~]# systemctl is-enabled Hwclock -w # Test [root@ironman ~]# ntpstat synchronised to NTP Server (192.46.215.60) at stratum 3 time correct to within 137 ms polling server every 64 sCopy the code

4. Client configuration

1. Install NTP and NTPDate
yum -y install ntp ntpdate
Copy the code
2. Run the command
Hwclock -w # set timer, Synchronize the time once a day crontab -e 00 01 * * * (/usr/sbin/ntpdate -u 192.168.10.200&& /sbin/hwclock -w) &> /var/log/ntpdate.log [root@mark2 ~]# ntpdate -u ironman 25 Jun 18:27:44 ntpDate [2162]: Adjust Time Server 192.168.37.37 Offset 0.001191 SECCopy the code