centos7配置ntp服务器和客户端同步

环境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 #查看时间同步源

posted @ 2020-07-10 16:19  苍茫宇宙  阅读(938)  评论(0编辑  收藏  举报