集群时间同步

集群时间同步

时间同步的方式:找一个机器,作为时间服务器,所有的机器与这台集群时间进行定时的同步,比如,每隔十分钟,同步一次时间。
在这里插入图片描述

1.配置时间同步具体实操:

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

1.1.1查看所有节点ntpd服务状态和开机自启动状态
sudo systemctl status ntpd
sudo systemctl is-enabled ntpd
1.1.2在所有节点关闭ntpd服务和自启动
sudo systemctl stop ntpd
sudo systemctl disable ntpd
1.1.3修改hadoop102的ntp.conf配置文件(要将hadoop102作为时间服务器)
sudo vim /etc/ntp.conf

修改内容如下
a)修改1(授权192.168.1.0-192.168.1.255网段上的所有机器可以从这台机器上查询和同步时间)

#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)添加3(当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步)

server 127.127.1.0
fudge 127.127.1.0 stratum 10
1.1.4修改hadoop102的/etc/sysconfig/ntpd 文件
sudo vim /etc/sysconfig/ntpd
增加内容如下(让硬件时间与系统时间一起同步)
SYNC_HWCLOCK=yes
1.1.5重新启动ntpd服务 +设置ntpd服务开机启动
sudo systemctl start ntpd
sudo systemctl enable ntpd

1.2)其他机器配置(必须root用户)

1.2.1在其他机器配置10分钟与时间服务器同步一次
sudo crontab -e

编写定时任务如下:

*/10 * * * * /usr/sbin/ntpdate 192.168.2.231
1.2.2修改任意机器时间
sudo date -s "2011-11-11 11:11:11"
1.2.3十分钟后查看机器是否与时间服务器同步
sudo date

说明:测试的时候可以将10分钟调整为1分钟,节省时间。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

北凉-徐凤年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值