CentOS6 自己動手搭建開放NTP服務器


第一步:

1. 安裝NTP服務程序:

[root@host ~]# rpm -qa | grep ntp #查詢是否安裝ntp服務程序
[root@host ~]# yum install -y ntp #安裝ntp服務程序 

2. 配置NTP服務程序:

以下紅色是新增的配置,黑色是默認配置

[root@host ~]# cp /etc/ntp.conf{,.bak} #備份ntp配置文件
[root@host ~]# vim /etc/ntp.conf  #使用vim編輯ntp配置文件 見vim使用方法
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1 
restrict -6 ::1
restrict 192.168.5.0 mask 255.255.255.0 nomodify notrap  #允許該網段內的主機可以進行校時 
restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap 
restrict default #default指所有的IP server 210.72.145.39 prefer #上層NTP服務器地址,prefer表示優先 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 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys

3. 設置NTP服務器控制操作:

# chkconfig ntpd on  #設置為開機啟動
# /etc/init.d/ntpd start #啟動NTP服務器
# /etc/init.d/ntpd stop #關閉NTP服務器
# /etc/init.d/ntpd restart #重啟NTP服務器                

 查看NTP端口

[root@host ~]# netstat -tlunp | grep ntp
udp        0      0 192.168.5.180:123            0.0.0.0:*      28331/ntpd   #這里的ip地址是本地IP,如果開放公共NTP的話是NTP服務器的IP       
udp        0      0 127.0.0.1:123                0.0.0.0:*      28331/ntpd          
udp        0      0 0.0.0.0:123                  0.0.0.0:*      28331/ntpd          
udp        0      0 fe80::20c:29ff:fe2b:9990:123 :::*           28331/ntpd          
udp        0      0 ::1:123                      :::*           28331/ntpd          
udp        0      0 :::123                       :::*           28331/ntpd

  

4.

現在ntp服務器已經啟動了,不過與上層服務器連接則還需要一些時間,通常啟動NTP后在15分鍾內才會和上層NTP服務器順利連接上。

如何確定NTP服務器順利地更新了自己的時間呢?可以使用以下幾個命令查看

[root@host ~]# ntpstat
synchronised to NTP server (72.5.72.15) at stratum 3 
   time correct to within 80 ms
   polling server every 128 s  
這個命令列出NTP服務器是否已經與上層NTP服務器連接,由上述的輸出結果可以知道,時間已經校正約80ms,且每隔128秒會主動去更新============================================================================================================================================

ntpq -p命令可以列出當前我們的NTP服務器與上層NTP服務器的連接狀態:

[root@host ~]# ntpd -p
    remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 210.72.145.39   .INIT.          16 u    - 1024    0    0.000    0.000   0.000
*mirror1.sjc02.s 162.213.2.253    2 u    1  128  377   10.196    0.945   2.653
+clocka.ntpjs.or 142.66.101.13    2 u   68  128  377   32.037    0.300   3.040
+96-83-113-171-s 172.16.23.153    2 u  132  128  377   77.364    3.457   3.268
-tesla.selinc.co 74.117.214.3     2 u  465  128   70   40.243    7.171   5.293

以上幾個字段的意義如下:

remote: NTP主機的IP或主機名;

注意左邊的符號: *:表示正在使用的NTP服務器

+:表示已經連接成功,但是作為備用提供時間更新的NTP服務器;

refid: 上層NTP服務器地址;

st: 就是stratum階層;

when:幾秒鍾前做過時間同步更新操作;

pool:下次更新在幾秒鍾之后;

reach:已經向上層NTP服務器要求更新的次數;

delay: 網絡傳輸過程中延遲的時間,單位為10-6秒;

offset:時間補償結果,單位為10-3秒;

jitter:系統時間與BIOS硬件時間的差異時間,單位為10-6秒;

 

PS:

國家授時中心服務器網址: http://www.time.ac.cn/stime.asp

          IP: 210.72.145.39

配置NTP時可以同步硬件時鍾指令如下:

同步硬件時鍾 SYNC_HWCLOCK=yes

 


免責聲明!

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



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