集群之间在执行任务的时候需要时间同步,分两种情况:
- 如果集群连接了外网,那么每个节点都可以和外网进行时间同步,不需要处理
- 如果集群没连接外网,需要配置集群中一台节点为时间服务器,其他节点同步它的时间
- 切换root用户
- 查看节点ntpd服务:
systemctl status ntpd - 查看是否开机自启动:
systemctl is-enabled ntpd - 修改参考时间节点的ntp.conf配置文件:
vim /etc/ntp.conf,内容如下:
(1)192.168.31.0-192.168.31.255 网段的节点都可以查询当前节点并同步时间
#restrict 192.168.31.0 mask 255.255.255.0 nomodify notrap
改为
restrict 192.168.31.0 mask 255.255.255.0 nomodify notrap
(2)集群在局域网中不使用其他外网同步时间:
server 0.centos.pool.ntp.org iburst
server 1centos.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 1centos.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
- 让当前节点的系统时间和硬件时间一起同步:
vim /etc/sysconfig/ntpd
#加内容
SYNC_HWCLOCK=yes
- 重启ntpd服务:
systemctl start ntpd - 配置ntpd服务开机自启动:
systemctl enable ntpd - 其他节点上关闭ntpd服务和自启动:
systemctl stop ntpd``systemctl disable ntpd - 在其他节点上配置每1分钟和时间服务器跟新一次时间:
crontab -e
*/1 * * * * /usr/sbin/ntpdate hadoop1
测试:修改时间服务器节点时间:date -s "2021-3-15 11:11:11",1分钟后在其他节点上执行date命令看是否执行了时间同步
1782

被折叠的 条评论
为什么被折叠?



