Requirement: There are multiple servers on the Intranet. In cluster deployment, ensure time consistency of each server. In this document, NTP is used for time synchronization

A, environmental

System: Centos 7.4 The following uses two servers as an example. One server is server, and the other client is ntp_server IP address: 10.25.0.151 NTP_client IP address: 10.25.0.153Copy the code

Second, NTP installation service

Considering the company server in the network, not be able to connect to the network, USES the RPM installation, can download links at http://rpmfind.net/linux/rpm2html/search.php?query=ntp: Ntp-4.2.6 p5-29.el7.centos.2.src. RPM and upload it to the server. Install NTP on the server and client. Run the RPM -ivh ntp-4.2.6p5-12.el6.centos.2.x86_64. RPM commandCopy the code

3. Modify the /etc/ntp.conf file

Run the vim /etc/ntp.conf commandCopy the code
Server Server configuration:

Restrict 10.25.0.0 mask 255.255.255.0 nomodify notrap # indicates that cluster 10.25.0 is allowed. This network segment is connected to synchronize time and the client is refused to modify server time server 127.127.1.0 # Local time fudge 127.127.1.0 stratum 10 # Time server hierarchy. The value can be 0 to 15, or 0 indicates the top levelCopy the code
Client server configuration :(this configuration is also available if there are multiple client servers)

Server 10.25.0.151 # Time synchronization server Server address

4. Start NTP service & Startup Settings (including Server server and Client Server)

Systemctl start NTPD After the NTP service is restarted, check whether the NTP service is enabled upon startup (if the automatic startup fails, For details, see exception description.) Systemctl status NTPD After the system restarts, run the systemctl status NTPD command, as shown in the following figure:Copy the code

Indicates that the startup is successful

Configure the firewall on the server

Firewall-cmd --add-port=123/udp --permanentCopy the code

6. Client Server Manually synchronizes time from the server server

Run the date command on the server to view the time

For example, date -s “20190315 15:12:23” Runs the date command to display the time

If the timezone is incorrect, set timedatectl set-timezone Asia/Shanghai

Client The client server executes commands to synchronize time

Ntpdate -u 10.25.0.151Copy the code

7. Set a scheduled time synchronization task on the client server

Run the crontab command on the client to set the interval. The interval is synchronized every five minutes

crontab -e
Copy the code

10.25.0.151 is the IP address of the server

In this case, you can set any time on the client. For example, run the date -s “20190315 15:12:23” command to check whether the time is consistent with the server time every five minutes

Example View NTP service information
NTPQ -pCopy the code

If both the server server and client server are in the centos operating system, use the following Settings if the client is in the Window operating system

The configuration of the server remains unchanged. You only need to set Windows

First go to control Panel -> Clock and Region -> Date and Time (Set date and time) ->Internet Time -> Change Settings

Enter server server IP address, 10.25.0.151

Click “Update now”, there may be synchronization failure, try several times, click “OK” button after the following

After time synchronization succeeds, the system automatically synchronizes time by default and displays the time of the next synchronization

Nine, the installation may encounter abnormal conditions:

Warning: user mockbuild does not exist - using root warning: Group mockbuild does not exist - using root run the following command: Groupadd mockbuild useradd mockbuild -g mockbuild Then run RPM -ivh ntp-4.2.6p5-12.el6.centos.2.x86_64. RPM againCopy the code
Libedit.so.0()(64bit) dependency missing if install prompt. Download the appropriate libedit. RPM installation package: libedit - 3.0-12.20121213 CVS. El7. SRC. RPM libedit installation command: RPM - the ivh libedit - 3.0-12.20121213 CVS. El7. SRC. The RPM and then re-execute the RPM - the ivh NTP - 4.2.6 p5-12. El6. Centos. 2. X86_64. RPMCopy the code
3) If NTP startup fails: The service is chrony. Use systemctl IS-enabled chronyd to check the setting of chrony's startup state. As expected, it is also started upon startup. Run the systemctl disable chronyd command to disable the chrony service.Copy the code

After the server is restarted, the NTP service is started and the NTPD status is running

Refer to the article: https://blog.csdn.net/I_Demo/article/details/99673094Copy the code

X. Additional notes

Systemctl start NTPD # Start NTP server systemctl stop NTPD # Stop NTP server crontab -l Check scheduled tasks # Synchronize hardware time to system time: Hwclock --hctosys # Synchronize the system time to the hardware time hwclock --systohc # force the system time to be written to CMOS clock -w # display the hardware time hwclock --show # set the hardware time hwclock - set - date '08/02/2012 12:00:00' # change time zone ln - sf/usr/share/zoneinfor/Asia/Shanghai/etc/localtimeCopy the code

This parameter is available if the server can connect to the Internet or the local resource library has NTP packages

Yum install NTP -y #Copy the code

Other crontab command related: https://www.cnblogs.com/zmdComeOn/p/10330541.html

References:

https://www.cnblogs.com/su-root/p/11380198.html
https://cloud.tencent.com/developer/article/1333862
https://blog.csdn.net/apache2tomcat/article/details/89477732
https://www.cnblogs.com/actively/p/12988713.html
Copy the code