欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

hadoop--集群时间同步(可不同步)

发布时间:2025/3/17 编程问答 41 豆豆
生活随笔 收集整理的这篇文章主要介绍了 hadoop--集群时间同步(可不同步) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

集群时间同步

如果服务器在公网环境(能连接外网),可以不采用集群时间同步,因为服务器会定期和公网时间进行校准;
如果服务器在内网环境,必须要配置集群时间同步,否则时间久了会产生时间偏差,导致集群执行任务时间不同步。

1.需求
找一个机器,作为时间服务器,所有的及其与这台集群时间进行定时同步,生产环境根据任务对时间的准确度要求周期同步。

2.时间服务器配置(必须root用户)

1). 查看所有节点ntpd服务状态和开机自启动状态:

[xiaobai@hadoop102 ~]$ sudo systemctl status ntpd [xiaobai@hadoop102 ~]$ sudo systemctl start ntpd [xiaobai@hadoop102 ~]$ sudo systemctl is-enabled ntpd

2). 修改hadoop102的ntp.conf配置:

[xiaobai@hadoop102 ~]$ sudo vim /etc/ntp.conf

修改内容如下:

a. 修改1(授权192.168.10.0-192.168.10.255网段上的所有机器可以从这台机器上查询和同步时间)

#restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap

restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap

b. 修改2(集群在局域网中,不适用其他互联网上的时间)

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 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

c. 天剑3(当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步)

server 127.127.1.0 fudge 127.127.1.0 stratum 10

3). 修改hadoop102的/etc/sysconfig/ntpd文件:

[xiaobai@hadoop102 ~]$ sudo vim /etc/sysconfig/ntpd

增加内容如下(让硬件时间与系统时间一起同步)

SYNC_HWCLOCK=yes

4). 重新启动ntpd服务:

[xiaobai@hadoop102 ~]$ sudo systemctl start ntpd

5). 设置ntpd服务开机启动:

[xiaobai@hadoop102 ~]$ sudo systemctl enable ntpd

3.其他机器配置(必须root用户):

1). 关闭所有节点上ntp服务和自启动

[xiaobai@hadoop103 ~]$ sudo systemctl stop ntpd [xiaobai@hadoop103 ~]$ sudo systemctl disable ntpd [xiaobai@hadoop104 ~]$ sudo systemctl stop ntpd [xiaobai@hadoop104 ~]$ sudo systemctl disable ntpd

2). 在其他及其配置1分钟与时间服务器同步一次:

[xiaobai@hadoop103 ~]$ sudo crontab -e

编写定时任务如下:

*/1 * * * * /usr/sbin/ntpdate hadoop102

3). 修改任意机器时间:

[xiaobai@hadoop103 ~]$ sudo date -s "2021-6-15 22:00:59"

4). 1分钟后查看机器是否与时间服务器同步:

[xiaobai@hadoop103 ~]$ sudo date

总结

以上是生活随笔为你收集整理的hadoop--集群时间同步(可不同步)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。