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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM