環境centos7.6
服務端:ip:172.21.210.27
1、安裝ntp、禁用chronyd時間同步服務
yum -y install ntp #安裝ntp服務
timedatectl set-ntp 0
2、配置ntp服務器
vi /etc/ntp.conf
restrict default nomodify #去掉后面的 notrap nopeer noquery
restrict 172.21.210.0 mask 255.255.255.0 nomodify notrap #以前是注釋的,修改ip段
server 127.127.1.0 #local clock #配置自己為時間同步服務器,注意不是127.0.0.1
fudge 127.127.1.0 stratum 10
#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、重啟服務
systemctl start ntpd && systemctl enable ntpd
客戶端同步時間
方式一、ntp模式(一般redhat用)
yum -y install ntp #安裝ntp服務
vi /etc/ntp.conf #配置server服務地址
server 172.21.210.27
systemctl start ntpd && systemctl enable ntpd #重啟服務
驗證:
ntpdate -d 172.21.210.27 #查看同步情況
ntpq -p #查看同步的服務器
ntpstat #查看是否同步
方式二、chronyd方式(一般centos用)
yum -y install chrony
sed -i 's/0.centos.pool.ntp.org/172.21.210.27/' /etc/chrony.conf
驗證:
timedatectl
chronyc sources -v #查看時間同步源
