ubuntu 14.04 安裝ntp


 

 

安裝

sudo apt-get install ntp

修改ntp.conf配置文件

sudo vi /etc/ntp.conf

修改為如下內容

# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/    #也可以開啟NTP log

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

# Specify one or more NTP servers.

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
server 120.24.166.46   # 阿里雲NTP Server-----------
server 127.127.1.0     # 如果公網NTP不可用時,將使用Local時間作為NTP服務提供給NTP Client。

# Use Ubuntu's ntp server as a fallback.
server ntp.ubuntu.com

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
restrict 192.168.20.0 mask 255.255.255.0 nomodify   # 允許的NTP Client網段---------------
# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

 

重啟NTP服務,並在客戶端驗證

root@ntpserver:~/ceph-cluster# service ntp restart
 * Stopping NTP server ntpd                                           [ OK ] 
 * Starting NTP server ntpd                                           [ OK ] 
root@ntpclient:/etc/ceph# ntpdate ntpserver
14 Jan 10:55:51 ntpdate[5230]: adjust time server 192.168.20.177 offset 0.209691 sec
root@ntpclient:/etc/ceph# 

 

觀察時間同步狀況:

ntpq -p

remote:本機和上層ntp的ip或主機名,“+”表示優先,“*”表示次優先
refid:參考上一層ntp主機地址
st:stratum階層
when:多少秒前曾經同步過時間
poll:下次更新在多少秒后
reach:已經向上層ntp服務器要求更新的次數
delay:網絡延遲
offset:時間補償
jitter:系統時間與bios時間差

 

查看ntpd進程的狀態
【命令】watch "ntpq -p"
第一列中的字符指示源的質量。星號 ( * ) 表示該源是當前引用。
remote:列出源的 IP 地址或主機名。
when:指出從輪詢源開始已過去的時間(秒)。
poll:指出輪詢間隔時間。該值會根據本地時鍾的精度相應增加。
reach:是一個八進制數字,指出源的可存取性。值 377 表示源已應答了前八個連續輪詢。
offset:是源時鍾與本地時鍾的時間差(毫秒)。

 

 

設置開機啟動

chkconfig ntpd on

 

 


參考:
https://www.cnblogs.com/vincenshen/p/6284933.html
https://blog.csdn.net/willinge/article/details/79928726
https://www.cnblogs.com/quchunhui/p/7658853.html
https://blog.csdn.net/jinyuxiaoqiang/article/details/81634827
https://www.cnblogs.com/quchunhui/p/7658853.html

 


免責聲明!

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



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