Linux集群时间同步

一、说明:

1.机器能连接网络可以不采用集群时间同步(因为机器会定期和网络时间进行校准);
2.机器不 能连接网络 ,必须要配置集群时间同步,因为时间久了,会产生时间偏差,导致集群执行任务时间不同步。

二、前期准备

1.找一个机器,作为时间服务器,所有的机器与这台集群时间进行定时的同步,采用 1 分钟同步一次。

三、配置同步

1.ntpd 
sudo systemctl status ntpd  #查看所有节点 ntpd 服务状态
sudo systemctl start ntpd   #开启ntpd
sudo systemctl is-enabled ntpd  #开机自启动状态。

2.修改时间服务器的ntp.conf配置

sudo vi /etc/ntp.conf

#授权 192.168.17.0-192.168.17.255 网段上的所有机器可以从这台机器上查询和同步时间

restrict 192.168.17.0 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.修改/etc/sysconfig/ntpd 文件

sudo vi /etc/sysconfig/ntpd

#让硬件时间与系统时间一起同步
SYNC_HWCLOCK=yes

4.重新启动 ntpd 服务

sudo systemctl start ntpd
5. 设置 ntpd 服务开机启动
sudo systemctl enable ntpd
6. 关闭所有节点上 ntpd 服务和自启动
sudo systemctl stop ntpd
sudo systemctl disable ntpd

7.在其他机器配置 1 分钟与时间服务器同步一次

sudo crontab -e
编写定时任务如下:
*/1 * * * * /usr/sbin/ntpdate hadoop01  #hadoop01是主机名

四、验证

1.修改任意机器时间
sudo date -s "2022-05-03 12:24:36"
2.1 分钟后查看机器是否与时间服务器同步
sudo date
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值