I. Environmental Preparation
Two virtual machines
2. Server side configuration:
1. Install ntp service# 192.168.30.139 [root@hadoop1 opt]# yum install -y ntp # 192.168.30.143 [root@hadoop2 opt]# yum install -y ntp2. Service and Set Up Startup
[root@hadoop1 opt]# service ntpd start # Starting ntpd:[OK] [root@hadoop1 opt]# chkconfig ntpd on3. Check whether the port is started
[root@hadoop1 ~]# netstat -anput| grep 123 udp 0 0 192.168.30.139:123 0.0.0.0:* 8239/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 8239/ntpd udp 0 0 0.0.0.0:123 0.0.0.0:* 8239/ntpd udp 0 0 fe80::20c:29ff:fea8:b66b:123 :::* 8239/ntpd udp 0 0 ::1:123 :::* 8239/ntpd udp 0 0 :::123 :::* 8239/ntpd4. Modify the configuration file:
driftfile /var/lib/ntp/drift restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery restrict 127.0.0.1 restrict -6 ::1 #Allow access to 192.168.30.0 segments restrict 192.168.30.0 mask 255.255.255.0 server 127.127.1.0 fudge 127.127.1.0 stratum 10 server 0.centos.pool.ntp.org iburst server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst server 3.centos.pool.ntp.org iburst includefile /etc/ntp/crypto/pw keys /etc/ntp/keys5. Restart ntpd service [root@hadoop1 ~]# service ntpd restart Turn off ntpd:[OK] Starting ntpd:[OK]
3. Client Configuration
1. Do the same in 192.168.30.143The client does not need to restart.
IV. Verification Operation
1. Before testing, check if the firewall and selinux are off!!!#Firewall off [root@hadoop1 opt]# service iptables stop #selinux off [root@hadoop1 opt]# cat /etc/selinux/config |grep -v ^# SELINUX=disabled SELINUXTYPE=targeted2. Time Synchronization
[root@hadoop1 opt]# date 2017year 12month 17Sunday and Sunday 03:33:13 CST # There is a significant difference between setting time on hadoop2 and hadoop1 [root@hadoop2 ~]# date -s '2017-12-10 15:14:23' 2017year 12month 10Sunday and Sunday 15:14:23 CST #Execute Synchronization Instructions [root@hadoop2 ~]# ntpdate 192.168.30.139 17 Dec 03:35:11 ntpdate[4405]: step time server 192.168.30.139 offset 562786.980472 sec [root@hadoop2 ~]# date 2017year 12month 17Sunday and Sunday 03:35:12 CST
5. Add to Timed Tasks
# Synchronize information at zero every day [root@hadoop2 ~]# crontab -e 0 0 * * * ntpd 192.168.30.139