Configuring NTP time server under Linux

Time synchronization of multiple linux servers

Time server function:

If the computer time is not synchronized, applications or operations such as E-MAIL information, file creation and access time, database processing time, etc. may not work properly.
Time synchronization is the basic guarantee for the correct processing of business.
In the Internet era, data communication within the entire processing and computing system is conducted through the network.
Time synchronization is to use the Internet to transmit standard time information to achieve time synchronization within the big data system.
Network Time Synchronization Protocol (NTP) is the technical basis for time synchronization.

(1) Confirm the installation of ntp

1) Confirm whether ntp is installed

$ rpm –qa | grep ntp
If there is only ntpdate but no ntp, you need to delete the original ntpdate. like:

ntpdate-4.2.6p5-22.el7_0.x86_64
fontpackages-filesystem-1.44-8.el7.noarch
python-ntplib-0.3.2-1.el7.noarch

2) Delete installed ntp

$ yum –y remove ntpdate-4.2.6p5-22.el7.x86_64

3) Reinstall ntp

$ yum –y install ntp

Install ntp offline:

Dependency packages that need to be prepared:

ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm
ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm
libedit-3.0-12.20121213cvs.el7.x86_64.rpm

rpm search URL:
Search the RPM

rpm -ivh libedit-3.0-12.20121213cvs.el7.x86_64.rpm  
rpm -ivh ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm  
rpm -ivh ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm

(2) Configure ntp service

1) Modify /etc/ntp.conf of all nodes

$ vi /etc/ntp.conf

【内容】
restrict 192.168.6.3 nomodify notrap nopeer noquery        #当前节点IP地址  
restrict 192.168.6.2 mask 255.255.255.0 nomodify notrap    #集群所在网段的网关(Gateway),子网掩码(Genmask)

Check the gateway:
1. route -n
2. ip route show
3. traceroute www.baidu.com -s 100 [The first line is your own gateway]
4. netstat -r
5. more /etc/network/interfaces [Debian/ Ubuntu Linux]
6. more /etc/sysconfig/network-scripts/ifcfg-eth0 [Red Hat Linux]

2) Select a master node and modify its /etc/ntp.conf

$ vi /etc/ntp.conf

【内容】在server部分添加以下部分,并注释掉server 0 ~ n
server 127.127.1.0
Fudge 127.127.1.0 stratum 10

Scheduled tasks:

$ crontab -e

【内容】 
30 * * * * /usr/sbin/ntpdate -u cn.ntp.org.cn
0 0 * * * /usr/sbin/ntpdate -u ntp.api.bz

3) Beyond the master node, continue to modify /etc/ntp.conf

$ vi /etc/ntp.conf

【内容】在server部分添加如下语句,将server指向主节点。
server 192.168.6.3
Fudge 192.168.6.3 stratum 10

Scheduled tasks:

$ crontab -e

【内容】
30 0 * * * /usr/sbin/ntpdate -u 192.168.6.3

=before fixing=

=After modification=
Node 1 (192.168.6.3):

Node 2 (192.168.6.4):

Node 3 (192.168.6.5):


View the ntp startup results:

watch ntpq -p

Check whether the NTP server is connected to the upper NTP server:

ntpstat

Start and set up startup:

systemctl start ntpd.service && systemctl enable ntpd.service
systemctl enable ntpdate.service

Check whether ntp is set to start automatically at boot:

systemctl is-enabled ntpd
enabled indicates that it has been set to start automatically at boot.
You can also use the following command to check the startup service:
systemctl list-unit-files | grep ntp
If ntp has been set to start automatically at boot, but the startup is not successful. The most common cause of this problem is that a tool that conflicts with NTP is installed on the system: chrony.
The solution is to stop starting this tool at boot time:
systemctl disable chronyd

Check the services started at startup:

systemctl list-unit-files | grep enable


The content is reproduced in: Time synchronization of multiple Linux servers

Guess you like

Origin blog.csdn.net/Laputa_Castle/article/details/117773960