-
NTP簡介
NTP(Network Time Protocol,網絡時間協議)是用來使網絡中的各個計算機時間同步的一種協議,它的用途是把計算機的時鍾同步到世界協調時UTC,其精度在局域網內可達0.1ms,在互聯網上絕大多數的地方其精度可以達到1-50ms。
NTP服務器就是利用NTP協議提供時間同步服務的。
-
NTP時間服務器搭建
-
實驗環境
-
操作系統及內核版本
-
[root@m01 ~]# cat /etc/redhat-release
-
CentOS release 6.9 (Final)
-
[root@m01 ~]# uname -r
-
2.6.32-696.el6.x86_64
-
主機IP地址規划
-
-
主機名 |
操作系統版本 |
外網IP |
內網IP |
用途 |
|
m01 |
CentOS release 6.9 |
10.0.0.71/24 |
172.16.1.71/24 |
時間服務器 |
-
安裝ntp
yum -y install ntp
-
修改/etc/ntp.conf:
-
在文件中將restrict default kod nomodify notrap nopeer noquery 注釋掉(前添加"#"),這個應該是對客戶端的限制太多,所以把它去掉。
-
restrict default kod notrap nomodify
-
注釋掉默認的server同步,添加新的同步時間服務器
-
server 0.cn.pool.ntp.org
-
server 1.cn.pool.ntp.org
-
server 2.cn.pool.ntp.org
-
server 3.cn.pool.ntp.org
-
-
啟動ntp服務
-
[root@m01 /]# /etc/init.d/ntpd start
-
-
查看ntp服務狀態
-
[root@m01 /]# ntpstat
-
synchronised to NTP server (101.6.6.172) at stratum 3
-
time correct to within 329 ms
-
polling server every 64 s
-
-
客戶端測試
-
[root@tomcat ~]# ntpdate 172.16.1.61
-
27 Jul 09:16:43 ntpdate[16670]: step time server 172.16.1.61 offset -46031.777540 sec
-
-
添加到定時任務
-
echo "*/5 * * * * /usr/sbin/ntpdate ntp 172.16.1.71 &>/dev/null"
-
注釋 :配置好服務器后,需要一段時間才能同步 !在客戶端測試的時候后會出現一下問題。過 10 到 15 分鍾就好了