Ubuntu 集群时间同步配置时间服务器及;error:Unit ntpd.service could not be found.

  集群时间同步

如果服务器在公网环境(能连接外网),可以不采用集群时间同步,因为服务器会定期和公网时间进行校准;

如果服务器在内网环境,必须要配置集群时间同步,否则时间久了,会产生时间偏差,导致集群执行任务时间不同步。

1)需求

找一个机器,作为时间服务器,所有的机器与这台集群时间进行定时的同步,生产环境根据任务对时间的准确程度要求周期同步。测试环境为了尽快看到效果,采用1分钟同步一次。

hadoop@hadoop102:~$ sudo systemctl status ntpd

error:Unit ntpd.service could not be found.

原因:缺少ntpd服务,使用apt安装

sudo apt update

sudo apt install ntp 

检查运行状态 systemctl status ntp 显示这样就是安装成功

 检查是否是开机自启,如果是自启就关闭

#查看

systemctl is-enabled ntp

#关闭

systemctl disable ntp

修改内容如下

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

#restrict 192.168.123.0 mask 255.255.255.0 notrust

将上面的注释去掉(并将192.168.1.0改成192.168.10.0

restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap

       ②修改2(集群在局域网中,不使用其他互联网上的时间)给上面的内容添加注释

#pool 0.ubuntu.pool.ntp.org iburst
#pool 1.ubuntu.pool.ntp.org iburst
#pool 2.ubuntu.pool.ntp.org iburst
#pool 3.ubuntu.pool.ntp.org iburst

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

server 127.127.1.0

fudge 127.127.1.0 stratum 10

(3)修改hadoop102的/etc/sysconfig/ntpd 文件(ubuntu没有sysconfig文件夹此配置应该在/etc/sysconfig/ntp)为了同步硬件与系统时间

hadoop@hadoop102:~$ sudo vim /etc/sysconfig/ntpd

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

SYNC_HWCLOCK=yes

(4)重新启动ntpd服务

hadoop@hadoop102:~$ sudo systemctl start ntpd

(5)设置ntpd服务开机启动

hadoop@hadoop102:~$ sudo systemctl enable ntpd

 

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

[root@hadoop103 ~]$ sudo crontab -e

编写定时任务如下:

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

(3)修改任意机器时间

[root@hadoop103 ~]$ date -s "2021-9-11 11:11:11"

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

[root@hadoop103 ~]$ date

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

北方569

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

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

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

打赏作者

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

抵扣说明:

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

余额充值