关注微信公共号:小程在线

如果服务器在公网环境(能连接外网),可以不采用集群时间同步
需要使用root用户
1.查看所有节点ntpd服务状态和开机自启动状态
[root@hadoop102 atguigu]# systemctl status ntpd

[root@hadoop102 atguigu]# systemctl start ntpd
[root@hadoop102 atguigu]# systemctl status ntpd

开机启动ntpd
[root@hadoop102 atguigu]# systemctl is-enabled ntpd
disabled
2. 修改hadoop102的ntp.conf配置文件
修改1:
#restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap修改为:
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
修改3:
在文件的最后增加:
server 127.127.1.0
fudge 127.127.1.0 stratum 10
3.修改/etc/sysconfig/ntpd 文件
[root@hadoop102 atguigu]# vim /etc/sysconfig/ntpd
4.重启
[root@hadoop102 atguigu]# systemctl restart ntpd
5.设置开机启动
[root@hadoop102 atguigu]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
6.修改103的时间
关闭所有节点上ntp服务和自启动
[atguigu@hadoop103 module]$ sudo systemctl stop ntpd
[atguigu@hadoop103 module]$ sudo systemctl disable ntpd
在其他机器配置1分钟与时间服务器同步一次
[atguigu@hadoop103 module]$ sudo crontab -e
crontab: installing new crontab

[atguigu@hadoop103 module]$ date
2022年 05月 10日 星期二 16:39:57 CST
修改任意机器时间
[atguigu@hadoop103 module]$ sudo date -s "2021-9-11 11:11:11"
2021年 09月 11日 星期六 11:11:11 CST
[atguigu@hadoop103 module]$ date
2021年 09月 11日 星期六 11:11:36 CST
1分钟后查看机器是否与时间服务器同步
[atguigu@hadoop103 module]$ date
2022年 05月 10日 星期二 16:46:04 CST