Linux cluster time synchronization


foreword

Since building a hadoop cluster requires cluster time synchronization, record the specific operation process.
Here my cluster environment is 192.168.184.129 (master), 192.168.184.130 (slave), 192.168.184.131 (slave), set the slave machine to synchronize time from the master machine, so as to keep the time consistent.


1. Synchronization method

  • The machine can access the network, and this kind of regular synchronization of network time is enough, such as synchronizing the time provided by Ali.
  • The slave node synchronizes the time of the master node, and other machines do not connect to the network, but only synchronize from the master node.

2. Check whether the time zone is correct

2.1 Check time zone

date -R

insert image description here
If it is not +8, you need to set the time zone of the machine first.
Execute the following command, and it will take effect after restarting.

rm -f /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

3. Cluster modification

Here I choose the second one. Real clusters generally cannot directly connect to the external network, and usually synchronize time from the master node.

3.1 Check whether the ntp service has been installed

rpm -qa|grep ntp

As shown in the figure below, the service is installed. If not, install the time service.
insert image description here
The command to install the ntp service is as follows

yum –y install ntp

3.2 192.168.184.129 master node modification

Modify the following files

vi /etc/ntp.conf

Modify as follows

#授权 192.168.184.2-192.168.184.255 网段上的所有机器可以从这台机器上查询和同步时间
 
restrict 192.168.184.2 mask 255.255.255.0 nomodify notrap
 
#集群在局域网中,不使用其他互联网上的时间
#注释以下内容:
#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
 
#当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为其他节点提供时间同步
server 127.127.1.0 
fudge 127.127.1.0 stratum 10

3.4 All node modification

modify file

vi /etc/sysconfig/ntpd
#让硬件时间与系统时间一起同步
SYNC_HWCLOCK=yes

Or this can also be
synchronized using the command

hwclock -w

Restart the ntp service after modification

service ntpd stop
service ntpd start

3.5 The slave node sets the timing task to synchronize the master node regularly

Stop the ntpd service from the node 192.168.184.130/192.168.184.131

service ntpd stop
systemctl disable ntpd

Set a scheduled task to synchronize time from the master node

crontab -e

Synchronize the master node every hour, hadoop1 is the host name and 192.168.184.129

0 0 */1 * * ? /usr/sbin/ntpdate hadoop1  #hadoop1是主机名

4. Verification

1. Manually execute the command synchronization first,
the error is as follows

/usr/sbin/ntpdate hadoop1
 3 May 12:42:26 ntpdate[11507]: no server suitable for synchronization found

Solution:
After viewing, the hadoop1 ntpd service is not started, just start the service.
2. Modify the slave machine time

sudo date -s "2022-05-03 12:24:36"

3. After 1 hour, check whether the machine is synchronized with the time server

sudo date

Summarize

It shows how to synchronize the cluster time. The premise is that the time zone of the machine is correct and the time zone must be modified first. If the article is helpful to you, please like it.

Guess you like

Origin blog.csdn.net/qq_34526237/article/details/130107797