Environmental Science:
Now there are three virtual machines of CentOS 7, namely, Hadoop 102, Hadoop 103 and Hadoop 104. Now configure ntp service (central server) on Hadoop 102. Hadoop 103 and 104 pull the time on Hadoop 102 respectively
1. Check whether ntp is installed (check and install all 3 sets, and make sure they are not running. If they are already running, stop them)
Switch to root
If ntp is not installed, install it all at once
[root@hadoop104 ~]# rpm -qa|grep ntp [root@hadoop104 ~]# [root@hadoop104 ~]# [root@hadoop104 ~]# [root@hadoop104 ~]# [root@hadoop104 ~]# yum -y install ntp Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.lzu.edu.cn * extras: ap.stykers.moe * updates: ap.stykers.moe base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package ntp.x86_64 0:4.2.6p5-29.el7.centos will be installed --> Processing Dependency: ntpdate = 4.2.6p5-29.el7.centos for package: ntp-4.2.6p5-29.el7.centos.x86_64 --> Processing Dependency: libopts.so.25()(64bit) for package: ntp-4.2.6p5-29.el7.centos.x86_64 --> Running transaction check ---> Package autogen-libopts.x86_64 0:5.18-5.el7 will be installed ---> Package ntpdate.x86_64 0:4.2.6p5-29.el7.centos will be installed --> Finished Dependency Resolution Dependencies Resolved =================================================================================================== Package Arch Version Repository Size =================================================================================================== Installing: ntp x86_64 4.2.6p5-29.el7.centos base 548 k Installing for dependencies: autogen-libopts x86_64 5.18-5.el7 base 66 k ntpdate x86_64 4.2.6p5-29.el7.centos base 86 k Transaction Summary =================================================================================================== Install 1 Package (+2 Dependent packages) Total download size: 701 k Installed size: 1.6 M Downloading packages: (1/3): autogen-libopts-5.18-5.el7.x86_64.rpm | 66 kB 00:00:00 (2/3): ntp-4.2.6p5-29.el7.centos.x86_64.rpm | 548 kB 00:00:00 (3/3): ntpdate-4.2.6p5-29.el7.centos.x86_64.rpm | 86 kB 00:00:00 --------------------------------------------------------------------------------------------------- Total 1.6 MB/s | 701 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : autogen-libopts-5.18-5.el7.x86_64 1/3 Installing : ntpdate-4.2.6p5-29.el7.centos.x86_64 2/3 Installing : ntp-4.2.6p5-29.el7.centos.x86_64 3/3 Verifying : ntp-4.2.6p5-29.el7.centos.x86_64 1/3 Verifying : ntpdate-4.2.6p5-29.el7.centos.x86_64 2/3 Verifying : autogen-libopts-5.18-5.el7.x86_64 3/3 Installed: ntp.x86_64 0:4.2.6p5-29.el7.centos Dependency Installed: autogen-libopts.x86_64 0:5.18-5.el7 ntpdate.x86_64 0:4.2.6p5-29.el7.centos Complete! [root@hadoop104 ~]#
It's OK to have the following
[root@hadoop104 ~]# [root@hadoop104 ~]# [root@hadoop104 ~]# rpm -qa|grep ntp ntp-4.2.6p5-29.el7.centos.x86_64 ntpdate-4.2.6p5-29.el7.centos.x86_64 [root@hadoop104 ~]# [root@hadoop104 ~]#
2. Configure Hadoop 102
[root@hadoop103 ~]# vi /etc/ntp.conf
The amendment is as follows:
1. Remove the following comments and change to your own segment
# Hosts on local network are less restricted. restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
2. Comment out the time taken from the public network
# Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #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
3. When the node loses the network connection, the local time can still be used as the time server to provide time synchronization for other nodes in the cluster
Find a place to add:
server 127.127.1.0 fudge 127.127.1.0 stratum 10
4. Configure vi /etc/sysconfig/ntpd
[root@hadoop102 hadoop-2.7.7]# [root@hadoop102 hadoop-2.7.7]# vi /etc/sysconfig/ntpd [root@hadoop102 hadoop-2.7.7]#
Add a line:
SYNC_HWCLOCK=yes
5. Restart the ntpd service
[root@hadoop102 hadoop-2.7.7]# [root@hadoop102 hadoop-2.7.7]# systemctl start ntpd [root@hadoop102 hadoop-2.7.7]# [root@hadoop102 hadoop-2.7.7]# systemctl enable ntpd
To see if it started successfully:
[root@hadoop102 hadoop-2.7.7]# [root@hadoop102 hadoop-2.7.7]# systemctl status ntpd ● ntpd.service - Network Time Service Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2020-01-29 23:02:59 EST; 1min 22s ago Main PID: 17717 (ntpd) CGroup: /system.slice/ntpd.service └─17717 /usr/sbin/ntpd -u ntp:ntp -g Jan 29 23:02:59 hadoop102 ntpd[17717]: Listen and drop on 1 v6wildcard :: UDP 123 Jan 29 23:02:59 hadoop102 ntpd[17717]: Listen normally on 2 lo 127.0.0.1 UDP 123 Jan 29 23:02:59 hadoop102 ntpd[17717]: Listen normally on 3 ens33 192.168.1.102 ...23 Jan 29 23:02:59 hadoop102 ntpd[17717]: Listen normally on 4 lo ::1 UDP 123 Jan 29 23:02:59 hadoop102 ntpd[17717]: Listen normally on 5 ens33 fe80::e804:aa7...23 Jan 29 23:02:59 hadoop102 ntpd[17717]: Listening on routing socket on fd #22 for...es Jan 29 23:02:59 hadoop102 ntpd[17717]: 0.0.0.0 c016 06 restart Jan 29 23:02:59 hadoop102 ntpd[17717]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM Jan 29 23:02:59 hadoop102 ntpd[17717]: 0.0.0.0 c011 01 freq_not_set Jan 29 23:03:00 hadoop102 ntpd[17717]: 0.0.0.0 c514 04 freq_mode Hint: Some lines were ellipsized, use -l to show in full. [root@hadoop102 hadoop-2.7.7]# [root@hadoop102 hadoop-2.7.7]#
Configuration of other machines (required by Hadoop 103 and 104) (root user is required)
Configure the timing task to synchronize with the time server once
[root@hadoop103 ~]# crontab -e
Add the following (synchronize every 10 minutes):
*/10 * * * * /usr/sbin/ntpdate hadoop102
After saving, the following contents are displayed, indicating success: