目录
1. 关闭selinux、firewall
# 注意:生产环境,要开启防火墙,并仅允许 ntp的协议和端口
# ntp使用UDP协议的123端口
sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
setenforce 0
systemctl disable firewalld.service
systemctl stop firewalld.service
systemctl status firewalld.service
2. 关闭chronyd时间服务
systemctl stop chronyd.service
systemctl disable chronyd.service
3. 调整系统时区为亚洲上海【shanghai】
timedatectl set-timezone Asia/Shanghai
4. 安装ntp服务
yum -y install ntp
5. 配置并启动ntp
egrep -v "^#|^$" /etc/ntp.conf
driftfile /var/lib/ntp/drift restrict default nomodify # 允许任何IP进行时间同步 restrict 127.0.0.1 restrict ::1 server 0.cn.pool.ntp.org iburst server 1.cn.pool.ntp.org iburst server 2.cn.pool.ntp.org iburst server 3.cn.pool.ntp.org iburst includefile /etc/ntp/crypto/pw keys /etc/ntp/keys disable monitor |
systemctl enable ntpd.service
systemctl start ntpd.service
6. 查看ntp是否与上层ntp连通
ntpstat
# 由上可知我们处于地3层,因为我们是从第2层同步时间的
7. 查看ntp与上层的状态
ntpq -p
8. 手动与ntp服务器同步时间
ntpdate -u 0.cn.pool.ntp.org
9. 将时间写入BIOS
hwclock -r # 查看BIOS时间
hwclock -w # 将系统时间写入到BIOS
10. 总结
# ntpd 同步是平滑同步
# ntpdate 依赖ntp服务器,是立即同步,不管之前的时间是多少