例有如下主机:
1 2 3 |
192.168.18.203 hadoop101 192.168.18.204 hadoop102 192.168.18.205 hadoop103 |
我们以102机器的时间为准,其他机器向他同步。
建议root操作
1、先同步所有服务器的时区(3台)
1 2 3 4 5 6 7 8 9 |
timedatectl set-timezone Asia/Shanghai systemctl enable chronyd systemctl start chronyd timedatectl status #查看同步状态 # 将当前的 UTC 时间写入硬件时钟 timedatectl set-local-rtc 0 # 重启依赖于系统时间的服务 systemctl restart rsyslog systemctl restart crond |
2、检查ntp是否安装 rpm -qa |grep ntp
1 2 3 4 5 |
ntp-4.2.6p5-29.el7.centos.2.x86_64 python-ntplib-0.3.2-1.el7.noarch fontpackages-filesystem-1.44-8.el7.noarch ntpdate-4.2.6p5-29.el7.centos.2.x86_64 看到上面4个内容就是ok |
3、修改npt配置文件
1 |
vim /etc/ntp.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
修改1: (授权192.168.18.0-192.168.18.255 网段上得所有机器可以从这台机器上查询和同步时间) restrict 192.168.18.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 ntp1.aliyun.com 修改3: 当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步 #粘贴如下内容至文件末尾 server 127.127.1.0 fudge 127.127.1.0 stratum 10 |
4、修改/etc/sysconfig/ntpd文件(让硬件时间与系统时间一起同步)
1 |
vim /etc/sysconfig/ntpd |
1 2 |
增加内容如下:(让硬件时间与系统时间一起同步) SYNC_HWCLOCK=yes |
5.重启ntpd服务
1 2 |
service ntpd status service ntpd start |
6.设置ntpd服务开机启动
1 |
chkconfig ntpd on |
7、查看 service ntpd status
8、在其他2台机器做如下设置
crontab -e
1 2 |
*/10 * * * * /usr/sbin/ntpdate hadoop101 #向101主机同步时间 service crond restart |
测试(修改主机时间)
1 |
date -s "2021-10-10 11:11:11" |
修改后等10分钟会同步一下时间。注意检查时间是否同步。
也可以使用chrony设置时间服务器(案例如下)
1 2 3 4 5 |
#大佬写的很好了,就不赘述了 https://www.jianshu.com/p/9c8d1104c58d #更新系统时间(单台) https://blog.csdn.net/phxzxt/article/details/123720099 |
- 本文固定链接: https://www.yoyoask.com/?p=8282
- 转载请注明: shooter 于 SHOOTER 发表