Cluster time synchronization configuration
1. Configure the time server
1.1 Check if NTP is installed
[tpsky@master hadoop-2.5.2]$ sudo rpm -qa|grep ntp
ntp-4.2.6p5-10.el6.centos.2.x86_64
fontpackages-filesystem-1.41-1.1.el6.noarch
ntpdate-4.2.6p5-10.el6.centos.2.x86_64
1.2 Edit the /etc/ntp.conf configuration file
[tpsky@master hadoop-2.5.2]$ sudo vim /etc/ntp.conf
Step 1: Add the following content to the file
restrict 10.31.131.0 mask 255.255.255.0 nomodify notrap
Step 2: Annotate the following
#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
Step 3: Add the following content
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
1.3 Configure the BIOS time to synchronize with the system time
1.3.1 View /etc/sysconfig/ntpd content
[tpsky@master hadoop-2.5.2]$ cat /etc/sysconfig/ntpd
# Drop root to id 'ntp:ntp' by default.
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
1.3.2 Edit /etc/sysconfig/ntpd and add the following before [OPTIONS]
[tpsky@master hadoop-2.5.2]$ sudo vim /etc/sysconfig/ntpd
content:
SYNC_HWCLOCK=yes
1.4 Check the startup status of the NTP service and set it to start the machine
1.4.1 View the startup status of the NTP service
[tpsky@master hadoop-2.5.2]$ sudo service ntpd status
ntpd is stopped
1.4.2 Start the NTP service
[tpsky@master hadoop-2.5.2]$ sudo service ntpd start
Starting ntpd: [ OK ]
1.4.3 View the startup status of the NTP service machine
[tpsky@master hadoop-2.5.2]$ sudo chkconfig --list|grep ntp
ntpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
ntpdate 0:off 1:off 2:off 3:off 4:off 5:off 6:off
1.4.4 Set the NTP service machine to start
[tpsky@master hadoop-2.5.2]$ sudo chkconfig ntpd on
1.4.5 View the startup status of the NTP service machine
[tpsky@master hadoop-2.5.2]$ sudo chkconfig --list|grep ntp
ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
ntpdate 0:off 1:off 2:off 3:off 4:off 5:off 6:off
1.5 Test the NTP service
[tpsky@master hadoop-2.5.2]$ ntpstat
synchronised to local net at stratum 11
time correct to within 3948 ms
polling server every 64 s
2. Configure other machines in the cluster
2.1 Perform time synchronization (NTP server is configured and operated after 5 minutes, otherwise there will be an error)
[tpsky@yarn hadoop-2.5.2]$ sudo ntpdate master.tpsoft.com
22 Apr 16:23:59 ntpdate[14366]: adjust time server 10.31.131.101 offset 0.000083 sec
2.2 Set the cluster machine and the NTP time server to synchronize the time every 10 minutes (operate with the root user, I have tried the sudo operation too)
[tpsky@yarn hadoop-2.5.2]$ sudo crontab -e
Enter:
0-59/10 * * * * /usr/sbin/ntpdate master.tpsoft.com
2.3 View the task running log
[tpsky@secondary hadoop-2.5.2]$ ls /var/log/cron*
/ var / log / cron
[tpsky@secondary hadoop-2.5.2]$ sudo more /var/log/cron
Apr 22 17:01:01 secondary run-parts(/etc/cron.hourly)[13695]: finished 0anacron
Apr 22 17:10:01 secondary CROND[13958]: (root) CMD (/usr/sbin/ntpdate master.tpsoft.com)
Apr 22 17:10:01 secondary CROND[13957]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Apr 22 17:20:01 secondary CROND[14254]: (root) CMD (/usr/sbin/ntpdate master.tpsoft.com)