NTP time server configuration under Linux

Time:2020-3-25

In the big data environment, the time requirement is very high, so synchronization time is needed in the cluster. This example uses one master to synchronize the external time, and the other two slave to synchronize the master time.

Time zone selection

On three machines

timedatectl set-timezone "Asia/Shanghai"

Set time zone uniformly

Install NTP

Execute on three machines respectively

yum install -y ntp
Configure NTP service
(1) The master (192.168.21.161) modifies the / etc / ntp.conf file

restrict 192.168.21.161 nomodify notrap nopeer noquery

192.168.21.161 is the IP address of the master

restrict 192.168.21.1 mask 255.255.255.0 nomodify notrap

Gateway and subnet mask

Note out the server 0 ~ n and add the synchronization time server address

server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server ntp3.aliyun.com iburst
server ntp4.aliyun.com iburst
server ntp5.aliyun.com iburst
server ntp6.aliyun.com iburst
server ntp7.aliyun.com iburst

The details are as follows
NTP time server configuration under Linux

(2) Slave1 (192.168.21.162) modify the / etc / ntp.conf file

restrict 192.168.21.162 nomodify notrap nopeer noquery

192.168.21.162 is the host IP address of slave1

restrict 192.168.21.1 mask 255.255.255.0 nomodify notrap

Gateway and subnet mask

Note out the server 0 ~ n and specify the master as the server

server 192.168.21.161
Fudge 192.168.21.161 stratum 10

The details are as follows
NTP time server configuration under Linux
(3) Slave2 (192.168.21.163) modify the / etc / ntp.conf file
Similar to slave1

restrict 192.168.21.163 nomodify notrap nopeer noquery

192.168.21.163 is the host IP address of slave2

restrict 192.168.21.1 mask 255.255.255.0 nomodify notrap

Gateway and subnet mask

Note out the server 0 ~ n and specify the master as the server

server 192.168.21.161
Fudge 192.168.21.161 stratum 10

The details are as follows
NTP time server configuration under Linux

Start NTP service

systemctl start ntpd.service

Set startup

systemctl enable ntpd.service

View state

ntpstat
synchronised to NTP server (192.168.21.161) at stratum 4
   time correct to within 84 ms
   polling server every 1024 s

NTP service will not synchronize time immediately after startup, so ntpstat status will not be synchronized immediately. It will be synchronized after 5-10 minutes

PS:
View gateway commands

ip route show

Turn off the firewall, otherwise port 123 of NTP service may be blocked

systemctl stop firewalld

View firewall status

systemctl status firewalld