CentOS 6下配置NTP網絡時間服務器

NTP服務簡介:
NTP(網絡時間協議)服務器,是用來保證網絡中各個主機的時間的保持同步的,其時間來源一般是原子時鐘,也可以是Internet上的其他NTP服務器。
安裝軟件包:

yum install -y ntp

配置服務:
打開配置文件

vim /etc/ntp.conf

轉到第18行,可以看到如下語句,這條語句是用來定義允許訪問NTP服務器的主機的,如果不配置則默認任何主機都可以訪問。

 #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

這裏我將其修改成只允許192.168.1.0網段的用户訪問。

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

轉到第22行,可以看到下面四行內容。

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

這是用來定義NTP服務器的時間來源的,默認這四個服務器因為天朝特殊的網絡環境所有訪問起來有點吃力,我們可以將其改為天朝自己的網絡時間服務器。如果是在局域網下的話NTP是訪問不了外網的,我們可以指定其與自己進行時間同步,將上方四行註釋掉,並在其後加入一行新的。

#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                    #我是新加的,聚光燈往這兒打!

不要問我上邊的IP地址為什麼是127.127.1.0,我也不知道~~~照做就是啦,否則的話NTP是沒辦法正常工作的。
保存並退出後在保證防火牆與selinux均關閉的情況下啓動NTP服務。

service ntpd start

測試服務:
參考此篇文章。

CentOS 6設置系統時間與網絡時間服務器同步


同步成功後會有類似如下提示:

[root@localhost ~]# ntpdate 192.168.2.11
2 Oct 20:00:30 ntpdate[1538]: adjust time server 192.168.1.11 offset -0.000002 sec