"Hadoop" Synchronizes cluster time

Source: Internet
Author: User
Tags local time
test environment:

192.168.217.130 master master.hadoop
192.168.217.131 node1 node1.hadoop
192.168.217.132 node2 node2.hadoop
First, set the master server time
View local time and time zone

[root @ master ~] # date
Mon Feb 27 09:54:09 CST 2017
Select time zone

[root @ master ~] # tzselect




 [root @ master ~] # cp / usr / share / zoneinfo / Asia / Shanghai / etc / localtime
Modified time (date -s 00:00:00 or network synchronization: apt-get install ntpdate; ntpdate cn.pool.ntp.org)
Write hard disk time (hwclock -w)

Second, check whether the time service is installed on the master server
[root @ node1 ~] # rpm -q ntp
ntp-4.2.4p8-2.el6.x86_64
If not installed, install with yum

[root @ node1 ~] # yum install ntp
Install the NTP software package on each server on the internal network according to the installation method above.
After completion, you need to configure the NTP service as self-starting

[root @ master ~] # chkconfig ntpd on
[root @ master ~] # chkconfig --list ntpd
ntpd 0: off1: off2: on3: on4: on5: on6: off
Third, change the relevant configuration file on the master
[root @ master ~] # vim /etc/ntp.conf
Make the following changes:





The first addition, which means that the server with IP address 192.168.217.1-192.168.217.254 and default gateway 255.255.255.0 can use our NTP server to synchronize time

The second is added, indicating the IP of the NTP server in the Internet and LAN

The third is the modification, which removes the original comments, and provides the client with time service in local time when the server loses contact with the public time server.

After the configuration file is modified, save and exit, and start the service.

[root @ master ~] # service ntpd start
After starting, it usually takes about 5-10 minutes to start synchronizing time with an external time server. You can query the status of the NTPD service through commands.

View service connections and listeners

[root @ master ~] # netstat -tlunp | grep ntp
udp 0 0 192.168.217.130:123 0.0.0.0:* 4990 / ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 4990 / ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 4990 / ntpd
udp 0 0 fe80 :: 20c: 29ff: fee7: 123 ::: * 4990 / ntpd
udp 0 0 :: 1: 123 ::: * 4990 / ntpd
udp 0 0 ::: 123 ::: * 4990 / ntpd
Restart service

[root @ master ~] # service ntpd restart
You can set crontab to synchronize with the NTP server once a day (taking synchronization with the Internet time as an example)

[root @ master ~] # crontab -l
10 23 * * * root (/ usr / sbin / ntpdate cn.pool.ntp.org && / sbin / hwclock -w) &> /var/log/ntpdate.log
Fourth, synchronize the time of other nodes with the master
Run the command on every other node

[root @ node1 ~] # ntpdate master
27 Feb 10:10:15 ntpdate [32724]: adjust time server 192.168.217.130 offset -0.170230 sec
[root @ node2 ~] # ntpdate master
27 Feb 10:10:23 ntpdate [30874]: adjust time server 192.168.217.130 offset -0.149563 sec
At this time, it is found that the time between the nodes is synchronized, but ntpdate is only running at startup. If we want to set it to synchronize once an hour

[root @ node1 ~] # crontab -l
* * / 1 * * * / usr / sbin / ntpdate master
Original source: cnblogs-> http://www.cnblogs.com/zjp719325616/p/6530705.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.