NTP安装
服务端和客户端都需要安装,需关闭防火墙或开通端口
# 安装
yum install ntp ntpdate -y
# 设置开机自启动
systemctl enable ntpd
NTP服务端
# 修改配置
vim /etc/ntp.conf
# 注释默认的,改成本地IP
#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.0.0.1 iburst
# 重启服务
systemctl restart ntpd
systemctl status ntpd
# 查看同步情况
ntpq -p
NTP客户端
# 修改配置
vim /etc/ntp.conf
# 注释掉默认的
#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
#修改为本地的ntpd Server服务器
server 192.168.3.13 iburst
#配置允许上游时间服务器主动修改本机的时间
restrict 192.168.3.13 nomodify notrap noquery
# 重启服务
systemctl restart ntpd
systemctl status ntpd
# 查看同步情况
ntpq -p
timedatectl
# timedatectl显示synchronized一直处于no状态
[root@node2 ~]# timedatectl
Local time: Mon 2021-07-12 10:27:02 CST
Universal time: Mon 2021-07-12 02:27:02 UTC
RTC time: Mon 2021-07-12 02:27:02
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
# 解决办法,等一会儿就好了
systemctl stop ntpd
ntpd -gq
systemctl start ntpd