linux运维、架构之路-内网NTP时间服务器

一、环境

[root@m01 tmp]# cat /etc/redhat-release
CentOS release 6.9 (Final)
[root@m01 tmp]# hostname -I
10.0.0.61(外网) 172.16.1.61(内网)

二、检查服务软件是否安装

[root@m01 tmp]# rpm -qa ntp
ntp-4.2.6p5-10.el6.centos.2.x86_64

三、修改ntp配置文件

sed -i '8c restrict default nomodify' /etc/ntp.conf替换配置文件的第8行内容,也可以使用vim
vim /etc/ntp.conf # restrict default kod nomodify notrap nopeer noquery restrict default nomodify#允许局域网时间同步 # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #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 ntp1.aliyun.com server time.nist.gov

四、启动ntp服务(这台服务器是需要外网的)

[root@m01 tmp]# /etc/init.d/ntpd start
Starting ntpd:                                             [  OK  ]

注:

启动后会自动更新时间

如果原来有同步时间的任务,关闭,否则会报如下的错误。

ntpdate[118978]: the NTP socket is in use, exiting

服务端执行ntpstat结果如下证明时间已同步

[root@m01 ~]# ntpstat 
synchronised to NTP server (182.92.12.11) at stratum 3 
   time correct to within 204 ms
   polling server every 64 s

五、无外网的服务器同步时间

[root@nfs01 ~]# ntpdate 172.16.1.61
10 Oct 14:49:18 ntpdate[21609]: adjust time server 172.16.1.61 offset 0.000652 sec
#时间服务器启动后,需要过几分钟才能进行同步。
ntpdate[5687]: no server suitable for synchronization found

六、把同步命令放入定时任务

[root@nfs01 ~]# crontab -l
#time sync by yanxinjiang at 2017-10-10
*/5 * * * * /usr/sbin/ntpdate 172.16.1.61  >/dev/null 2>&1
posted @ 2017-10-10 14:52  闫新江  阅读(1463)  评论(0编辑  收藏  举报