An application scenario of NTP timing server

An application scenario
of NTP time service server An application scenario of NTP time service server

One, build ntp time server

(1) Why build ntp time server

      因为Hadoop 对集群中各个机器的时间同步要求比较高, 要求各个机器的系统时间不能相差太多, 不然会造成很多问题。比如,最常见的连接超时问题。所以需要配置集群中各个机器和互联网的时间服务器进行时间同步, 但是在实际生产环境中, 集群中大部分服务器是不能连接外网的, 这时候可以在内网搭建一个自己的时间服务器( NTP 服务器),然后让集群的各个机器与这个时间服务器定时的进行时间同步。 

(2) How to build a time server
Take the machine with the host name node01 as an example
1. First, check the time of the machine and
enter the command date.
From the results, we can see that the current time is EST (Eastern Standard Time, New York Time) and we are in China, so we can change the time to CST (Central Standard Time, Shanghai Time).
2. How to modify the time standard?
Just execute the command on all nodes: cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime. In fact, copy the files of Shanghai time to localtime.
Note: The above operations must be performed on all three nodes to ensure that the current time standard of the system is Shanghai time.
OK, then proceed to the clock synchronization configuration.
3. Configure NTP server.
We choose the first machine (node01) as the NTP server, and other machines will synchronize time with this machine.
(1) Check whether the NTP service has been installed.
Enter the command: rpm -qa | grep ntp.
If it is not installed, enter the command yum install -y ntp to install it.
In fact, two softwares are installed, of which ntpdate-4.2.6p5-1.el6.centos.x86_64 is used to synchronize with a server and
ntp-4.2.6p5-1.el6.centos.x86_64 is used to provide time Synchronous service.
(2) Modify the configuration file ntp.conf and
enter the command: vi /etc/ntp.conf, and then make the following modifications:
1) Enable restrict to limit the network segment of the machine. The specific operation is as follows:
remove the comment from the restrict 192.168.74.136 mask 255.255.255.0 nomodify notrap line, and change the network segment to the network segment of your own machine. Here we are 74 network segment . Of course, you can also directly enter the IP address of the machine.
2) Comment out the server domain name configuration
#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 The 4 servers
above .ntp.org iburst are the domain names of the time server. There is no need to connect to the Internet here, so comment them out.
3) Add the following two lines to the file to synchronize the time of the local machine and the local hardware.
server 127.127.1.0
fudge 127.127.1.0 stratum 10
These two are commented out in the default configuration file. The NTP server will use its own time as the time of the NTP server according to the configuration here, that is, synchronize with itself. Taking into account that some LANs cannot access the external network, this configuration item needs to be configured here.
(3) Start the NTP service.
Enter the command chkconfig ntpd on
so that every time the machine starts, the NTP service will automatically start.
4. Configure timing time synchronization of other machines
Other machine configuration actually time server clock is not difficult, just enter the command corresponding to the machine: crontab -e can then enter 0-59 / 10 * * * * / usr / sbin / ntpdate node01 session in
the A brief explanation of the meaning of this line of content:
(1) Among them, 0-59/10 * * * * means that the clock is synchronized every 10 minutes, and the five segments separated by spaces are the time periods in the crontab syntax format, totaling 5 paragraphs, where the * sign represents any time, the specific meaning of each time period is as follows:

     (2)其中/usr/sbin/ntpdate node01表示执行的命令,即本机和主机名为node01的机器进行定时的时钟同步。
         (3)在其他节点进行同样的操作,然后过10分钟之后再次查看3台机器的时间,如果3台机器的时间一致就表示实现了时间的定时同步。

Guess you like

Origin blog.csdn.net/weixin_44990608/article/details/108662379