目录
1、保证集群可以互相访问
尝试互相ping
ping [ IP ]
2、开放防火墙
-A INPUT -p udp -m state --state NEW -m udp --sport 123 -j ACCEPT
-A OUTPUT -p udp -m state --state NEW -m udp --dport 123 -j ACCEPT
重启防火墙生效
systemctl restart iptables
3、NTP服务器设置
## 服务端这里会安装ntp 以及ntpdata
yum -y install ntp
/etc/ntp.conf 修改配置如下:(标有注释部分就是我修改了的部分)
grep -Ev "^#|^$" /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 192.168.0.0 mask 255.255.0.0 ## 允许访问ntp的网段
server 210.72.145.44 ## 中国国家授时中心ntp服务器
server 133.100.11.8 #当上面服务器同步不了,则寻找第二个ntp服务器。
restrict 127.0.0.1
restrict ::1
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 127.127.1.0 ## local clock 将本地ip作为ntp服务器
fudge 127.127.1.0 stratum 10 #127.127.1.0 为第10层。
# ntp 和127.127.1.0同步完后,就变成了11层。
# ntp是层次阶级的。同步上层服务器的stratum 大小不能超过或等于16
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
重启:
systemctl status ntpd
systemctl restart ntpd
systemctl status ntpd
## 加入自启动
systemctl enable ntpd
## 定时外网ntp服务器同步
*/60 * * * * /usr/sbin/ntpdate ntp.sjtu.edu.cn >> /var/log/cron.log 2>&1
检查ntp
root 16:15:52~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
210.72.145.44 .INIT. 16 u - 1024 0 0.000 0.000 0.000
133.100.11.8 .INIT. 16 u - 1024 0 0.000 0.000 0.000
+de-user.deepini 9.193.143.114 3 u 23 64 335 277.914 6.282 7.315
*tick.ntp.infoma .GPS. 1 u 13 64 377 229.410 -4.652 12.599
+ntp.ix.ru .GPS. 1 u 86 64 376 293.050 -3.191 8.175
LOCAL(0) .LOCL. 10 l 1904 64 0 0.000 0.000 0.000
root 16:15:52~]# ntpstat
synchronised to NTP server (84.16.73.33) at stratum 2
time correct to within 203 ms
polling server every 64 s
4、NTP客户端设置
## 客户端只需安装ntpdata,如果有客户端还在运行ntp 则需要关闭、卸载ntp
yum install ntpdate.x86_64 -y
手动同步:
ntpdate 192.168.5.182
6 Jul 15:49:52 ntpdate[22046]: step time server 192.168.5.182 offset 619.772641 sec
设置定时同步:
crontab -e
*/20 * * * * /sbin/ntpdate 192.168.5.182 > /dev/null 2>&1
ntpdata 报错:
6 Jul 16:22:11 ntpdate[3626]: the NTP socket is in use, exiting
分析:这个客户端未关闭ntp服务 关闭重新手动同步即可
修改 BIOS 时间
查看硬件BIOS时间:
hwclock -r 读出BIOS的时间参数
hwclock -w 将当前系统时间写入BIOS中 修改BIOS的时间