Linux tool to achieve using ntp time synchronization between cluster hosts

Foreword

  • NTP (Network Time Protocol, Network Time Protocol) is a protocol used to synchronize the computer time, which can make a computer or a server of its clock source (e.g., quartz, GPS, etc.) to make synchronized, it can provide highly accurate correction of the time (on the LAN standard is less than 1 ms, several tens of milliseconds on the WAN), and can be confirmed via the encrypted manner to prevent malicious protocol attacks. NTP is designed to provide accurate and robust time Internet service in disordered environments
  • You can achieve the system time and hardware time between each host by ntp synchronization tools on Linux
  • The experimental cluster host system is CentOS 7, cluster host 192.168.126.0/24 network segment

demand

  • Host time synchronization in the cluster to achieve

Specific steps:

1. Configure the time server cluster

(1) to check whether to install ntp

[tomandersen@hadoop101 ~]$ yum list installed | grep ntp
fontpackages-filesystem.noarch          1.44-8.el7                     @anaconda
ntp.x86_64                              4.2.6p5-29.el7.centos          @base    
ntpdate.x86_64                          4.2.6p5-29.el7.centos          @base    
python-ntplib.noarch                    0.3.2-1.el7                    @anaconda

Check ntp is installed

  • If you do not install the installation
[tomandersen@hadoop101 ~]$ sudo yum install ntp

(2) modify the configuration file /etc/ntp.conf ntp

  • You must use the root user to execute commands
[root@hadoop101 ~]# vim /etc/ntp.conf 
  • Modifications are as follows:

  • a) authorize the current network segment all the hosts can query this host and synchronize time
restrict 192.168.126.0 mask 255.255.255.0 nomodify notrap
  • Use local time b) No connection is provided to provide time synchronization for the cluster machine
server 127.127.1.0
fudge 127.127.1.0 stratum 10
  • Specifically as shown below

Ntp modify configuration files /etc/ntp.conf

(3) modify the ntp configuration file / etc / sysconfig / ntpd

  • Root user to edit the file / etc / sysconfig / ntpd, insert the following hardware and system time synchronization with
SYNC_HWCLOCK=yes

Hardware and system time synchronization with

(4) Restart ntp service

[root@hadoop101 /]# systemctl restart ntpd.service 

(5) set ntp service boot from Kai

[root@hadoop101 /]# systemctl enable ntpd.service

2. Configure all other client hosts

(1) create a scheduled task time synchronization

  • Create a scheduled task to use crontab tool on other hosts, set a time synchronization every minute
[root@hadoop102 ~]# crontab -e
  • Insert the following content, you can not have extra spaces
*/1 * * * * /usr/sbin/ntpdate hadoop101

(2) ensure crond.service and ntpd.service boot

sudo systemctl enable crond.service
sudo systemctl enable ntpd.service

3. Test synchronization results

  • Use the date command to modify at any time the client host
[root@hadoop103 TomAndersen]# date -s "2017-9-11 11:11:11"
  • 1 minute to check whether the automatic time synchronization is successful
[root@hadoop103 TomAndersen]# date
20200209日 星期日 21:51:11 CST

End~

Published 15 original articles · won praise 5 · views 10000 +

Guess you like

Origin blog.csdn.net/TomAndersen/article/details/104239795