Linux:集群时间同步

迷南。 2024-03-17 18:36 182阅读 0赞

集群时间同步

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

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

2)时间服务器配置(必须root用户)
(1)查看hadoop102服务状态和开机自启动状态(如果开着就关掉)
[atguigu@hadoop102 ~]$ sudo systemctl status ntpd
[atguigu@hadoop102 ~]$ sudo systemctl is-enabled ntpd

(2)修改hadoop102的ntp.conf配置文件
[atguigu@hadoop102 ~]$ sudo vim /etc/ntp.conf
修改内容如下
①修改1(授权192.168.10.0-192.168.10.255网段上的所有机器可以从这台机器上查询和同步时间)
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
将上面的注释去掉(并将192.168.1.0改成192.168.10.0)
restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap
②修改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
③添加3(当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步)
server 127.127.1.0
fudge 127.127.1.0 stratum 10

(3)修改hadoop102的/etc/sysconfig/ntpd 文件
[atguigu@hadoop102 ~]$ sudo vim /etc/sysconfig/ntpd
增加内容如下(让硬件时间与系统时间一起同步)
SYNC_HWCLOCK=yes

(4)重新启动ntpd服务
[atguigu@hadoop102 ~]$ sudo systemctl start ntpd

(5)设置ntpd服务开机启动
[atguigu@hadoop102 ~]$ sudo systemctl enable ntpd

3)其他机器配置(必须root用户)
(1)关闭所有节点上ntp服务和自启动
[root@hadoop103 ~]$ systemctl stop ntpd
[root@hadoop103 ~]$ systemctl disable ntpd

[root@hadoop104 ~]$ systemctl stop ntpd
[root@hadoop104 ~]$ systemctl disable ntpd

(2)查看时间服务状态
[root@hadoop103 ~]$ systemctl status crond

(3)在其他机器配置1分钟与时间服务器同步一次
[root@hadoop103 ~]$ sudo crontab -e
编写定时任务如下:
*/1 * * * * /usr/sbin/ntpdate hadoop102

(4)修改任意机器时间
[root@hadoop103 ~]$ date -s “2021-9-11 11:11:11”

(5)1分钟后查看机器是否与时间服务器同步
[root@hadoop103 ~]$ date

发表评论

表情:
评论列表 (有 0 条评论,182人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Linux时间同步

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

    相关 时间同步

    集群之间在执行任务的时候需要时间同步,分两种情况: 如果集群连接了外网,那么每个节点都可以和外网进行时间同步,不需要处理 如果集群没连接外网,需要配置集群中一台节

    相关 Oracle时间同步

    在RAC中集群的时间应该是保持同步的,否则可能导致很多问题,比如:依赖于时间的应用会造成数据的错误,各种日志打印的顺序紊乱,这将会影响问题的诊断,严重的可能会导致集群宕机或者重