CentOS 7 部署NTP服务器

1、为服务器和客户机安装ntp、ntpdate(默认已安装可检查更新)

[root@NTP ~]# yum install ntp ntpdate -y 

2、查找可用时间同步服务器

参考资料: http://www.pool.ntp.org/zone/asia

3、修改配置文件:

[root@NTP ~]# vi /etc/ntp.conf
server time.windows.com

server s2m.time.edu.cn

server 0.asia.pool.ntp.org

server 1.asia.pool.ntp.org

server 2.asia.pool.ntp.org

server 3.asia.pool.ntp.org

server 127.127.1.0 iburst  local clock 当外部时间不可用时,使用本地时间

restrict 192.168.137.1 mask 255.255.255.0 nomodify  允许更新的IP地址段

4、启动NTP服务:

[root@NTP ~]# systemctl start ntpd
[root@NTP ~]# systemctl enable ntpd.service

5、验证服务:

[root@NTP ~]# ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter

==============================================================================

 52.173.193.166  128.138.141.172  2 u    9   64    1  192.440    0.871   0.000

 85.199.214.101  .GPS.            1 u    3   64    1  210.590   -0.249   0.048

 119.79-161-57.c 129.242.4.241    2 u    3   64    1  359.665    0.900   8.887

 2001:da8:d800:: 85.199.214.100   2 u    6   64    1   10.720   -0.381   0.123

 85.199.214.100  .GPS.            1 u   16   64    1  188.947   10.128   0.358

*LOCAL(0)        .LOCL.           5 l   24   64    1    0.000    0.000   0.000

 ntp.wdc1.us.lea .INIT.          16 u    -   64    0    0.000    0.000   0.000

 time5.aliyun.co 10.137.38.86     2 u   24   64    1   27.304   -1.010   0.000

 ntp1.ams1.nl.le 130.133.1.10     2 u   22   64    1  208.639    3.970   0.000

6、远程客户端时间同步:

[root@NTP ~]# date
2018年 06月 07日 星期四 08:01:46 CST

7、客户端设置计划任务,假设每天晚上1点同步时间:

crontab -e 00 01 * * * root /usr/sbin/ntpdate 192.168.105.190; /sbin/hwclock -w
上一篇
下一篇