centos 6.9 ntp/ntpdate

1、 國家授時ntp服務器 ntp.ntsc.ac.cn 114.118.7.163

2、yum install ntp
[root@centos6 yum.repos.d]# rpm -qa |grep ntp 
fontpackages-filesystem-1.41-1.1.el6.noarch
ntpdate-4.2.6p5-10.el6.centos.2.x86_64
ntp-4.2.6p5-10.el6.centos.2.x86_64

3、[root@centos6 ~]# ntpdate 114.118.7.163  同步本地時間ntpd 服務需要停止,否則會報錯端口占用


[root@centos6 ~]# service ntpd stop 

Shutting down ntpd:                                        [  OK  ]


4、[root@centos6 yum.repos.d]# iptables -I INPUT -p udp -m udp --sport 123 -j ACCEPT 開放123 端口

/etc/init.d/ntpd status 

service  ntpd status 


5、netstat -nupl |grep 123 

blob.png


6、[root@centos6 yum.repos.d]# rpm -ql ntp  查看配置文件;


7、ntpstat 

[root@centos6 yum.repos.d]# ntpstat 
synchronised to NTP server (185.255.55.20) at stratum 3 
   time correct to within 117 ms
   polling server every 128 s
[root@centos6 yum.repos.d]# nslookup 185.255.55.20
Server:         192.168.2.1
Address:        192.168.2.1#53

Non-authoritative answer:
20.55.255.185.in-addr.arpa      name = ntp.xtom.nl.


8、ntpq -np 

[root@centos6 yum.repos.d]# ntpq -np               
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
-94.237.64.20    218.186.3.36     2 u  164  128  376  200.998  -59.444   2.932
+5.79.108.34     130.133.1.10     2 u  164  128  276  212.569   -3.185   4.901
+162.159.200.1   10.20.12.67      3 u   37  128  177  234.257    2.056   3.873
*185.255.55.20   194.80.204.184   2 u   92  128  377  175.768    5.440   2.843

*表示:目前選擇的同步服務器
+ 表示同步精度的次要服務器


9、配置文件:

/etc/ntp.conf

chkconfig ntpd on 

/etc/init.d/ntpd start 

/etc/init.d/ntpd stop 


[root@centos6 yum.repos.d]# egrep -v "^#|^$" /etc/ntp.conf
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
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

server 0.centos.pool.ntp.org iburst # 服務器地址

retrict  192.168.30.1 mask 255.255.255.0 nomodify #在192.168.30.1/24 網段內的服務器就可以通過這臺ntp server 進行時間同步了

參數:prefer:表示我們的ntp主機主要以該部主機作爲時間校正


https://blog.csdn.net/vic_qxz/article/details/80344855
[root@linux ~]# vi /etc/ntp.conf 
# 1. 關於權限設定部分 
#   權限的設定主要以 restrict 這個參數來設定,主要的語法爲: 
#   restrict IP mask netmask_IP parameter 
#   其中 IP 可以是軟件地址,也可以是 default ,default 就類似 0.0.0.0 #   至於 paramter 則有: 
#   ignore :關閉所有的 NTP 聯機服務 
#   nomodify:表示 Client 端不能更改 Server 端的時間參數,不過,

#   Client 端仍然可以透過 Server 端來進行網絡校時。 
#   notrust :該 Client 除非通過認證,否則該 Client 來源將被視爲不信任網域 
#   noquery :不提供 Client 端的時間查詢

#   notrap :不提供trap這個遠程事件登入

#  如果 paramter 完全沒有設定,那就表示該 IP (或網域)“沒有任何限制”

restrict default nomodify notrap noquery # 關閉所有的 NTP 要求封包 
restrict 127.0.0.1    #這是允許本級查詢
restrict 192.168.0.1 mask 255.255.255.0 nomodify 
#在192.168.0.1/24網段內的服務器就可以通過這臺NTP Server進行時間同步了 
# 2. 上層主機的設定 
#  要設定上層主機主要以 server 這個參數來設定,語法爲:
#  server [IP|HOST Name] [prefer]
#  Server 後面接的就是我們上層 Time Server 囉!而如果 Server 參數 
#  後面加上 perfer 的話,那表示我們的 NTP 主機主要以該部主機來作爲 
#  時間校正的對應。另外,爲了解決更新時間封包的傳送延遲動作, 
#  所以可以使用 driftfile 來規定我們的主機 
#  在與 Time Server 溝通時所花費的時間,可以記錄在 driftfile  
#  後面接的文件內,例如下面的範例中,我們的 NTP server 與  
#  cn.pool.ntp.org聯機時所花費的時間會記錄在 /etc/ntp/drift文件內 
server 0.pool.ntp.org

server 1.pool.ntp.org

server 2.pool.ntp.org

server cn.pool.ntp.org prefer

#其他設置值,以系統默認值即可

server  127.127.1.0     # local clock

fudge   127.127.1.0 stratum 10driftfile /var/lib/ntp/drift
broadcastdelay  0.008keys /etc/ntp/keys




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章