CentOS配置ntp时间同步服务器

ntp服务端:

1、设置本地服务器时间时区

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

或者

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

2、设置时区立即生效

timedatect set-timezone "Asia/Shanghai"

date   #查看时间

3、使用hwclock将时间同步到bios

hwclock

4、安装ntp服务

rpm -qa |grep ntp

yum install -y ntp ntpdate         #ntpdate是时间同步客户端

5、修改配置文件/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

server 127.127.1.0          
fudge 127.127.1.0 stratum 0
 

6、启动ntp服务并开机自启

CentOS7:systemctl start ntpd

                   systemctl enable ntpd

CentOS6:service ntpd start

                   chkconfig ntp on

7、查看是否同步

[root@172 Asia]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*LOCAL(0)        .LOCL.           0 l   31   64  377    0.000    0.000   0.000
[root@172 Asia]# 
 

8、若防火墙开启,可打开udp123端口

CentOS7:firewalld-cmd --permanent --add-port=123/udp

CentOS6:iptales -A INPUT -p udp -dport 123 -j ACCEPT

                  iptales -A OUTPUT -p udp -sport 123 -j ACCEPT

                  service iptables save

客户端配置

1、安装ntp服务

rpm -qa |grep ntp

yum install -y ntp ntpdate         #ntpdate是时间同步客户端

2、修改配置文件/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

#restrict 127.0.0.1 
#restrict ::1
 

#配置上游时间服务器为本地的ntpd Server服务器

server 172.16.31.110                          #server ntp1.aliyun.com     阿里云ntp服务器域名

fudge 172.16.31.110 stratum 0

 

#配置允许上游时间服务器主动修改本机的时间

restrict hadoop101.com nomodify notrap noquery

 

3、与本地ntpd server同步

ntpdate -u 172.16.31.110

 

4、启动ntp服务,加入开机自启

systemctl start ntpd

systemctl enable ntpd

 

5、查看状态

[root@localhost ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*172.16.31.110   .LOCL.           1 u   17   64  377    0.384   -0.163   0.423
[root@localhost ~]# 

猜你喜欢

转载自blog.csdn.net/qq_40836555/article/details/105556107