九、Hadoop集群同步时间

本文档详细介绍了如何在Linux环境中设置时间服务器并确保多台服务器间时间一致。首先,通过yum安装ntp,然后在选定的时间服务器(hadoop102)上配置ntp.conf文件,关闭外部NTP服务器,启用本地时间作为时间源。接着,更新ntpd配置文件以同步硬件时间,并重启ntpd服务。最后,在其他服务器上设置定时任务,每分钟与时间服务器同步一次,从而实现整个集群的时间一致性。
摘要由CSDN通过智能技术生成

目的:为了后续数据版本的一致性,保证多台服务器的时间是一致的。
设置一台时间服务器,其他服务器同步时间服务器的时间。
1)安装ntp
yum install ntp -y
2)时间服务器配置(必须是root用户)
(1)在所有节点关闭ntp服务和自启动
sudo systemctl stop ntpd
sudo systemctl disable ntpd
(2)在hadoop102上修改ntp配置文件(hadoop102为时间服务器)
vim /etc/ntp.conf
(a)修改1
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
改为(去掉注释#)
restrict 192.168.1.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)添加配置(当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步)
server 127.127.1.0
fudge 127.127.1.0 stratum 10
(3)修改/etc/sysconfig/ntpd文件
vim /etc/sysconfig/ntpd
添加内容(让硬件时间和系统时间一起同步)
SYNC_HWCLOCK=yes
(4)重新启动ntpd服务(在hadoop102,时间服务器启动)
systemctl start ntpd
(5)设置ntpd服务开机启动(在hadoop102,时间服务器启动)
systemctl enable ntpd
(6)查看状态
systemctl is-enabled ntpd
systemctl status ntpd
3)其他机器配置定时任务(必须root用户)
(1)在其他机器配置1分钟与时间服务器同步一次
sudo crontab -e
编写定时任务如下:
*/1 * * * * /usr/sbin/ntpdate hadoop102
查看任务
crontab -l (没有任务,因为是root用户创建的)
sudo crontab -l(有定时任务)
(2)删除定时任务
sudo crontab -r

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值