时间同步服务器(默认)chrony和ntp
Rhel7時間同步服務器(默認)chrony??? 端口:323
chrony簡介:
是一個開源軟件,可實現系統時鐘和時鐘服務器同步,讓時間保持精確
兩部分組成:chronyd和chronyc
其中chronyd是后臺運行的守護進程,用于調整內核中運行的系統時鐘和時鐘服務器同步。
Chronyc提供了用戶界面,用于監控性能并進行多樣化的配置。
啟動chrony時,系統會自動讀取/etc/chronyd.conf配置文件中的設置
?
systemctl start chronyd
chronyc sources –v????? 查看時間同步源,查看時間同步進度
*說明時間同步完成,如果為?說明不成功,檢查防火墻再看看chronyd有沒有重啟。
chronyc sourcestats -v??? 查看時間同步源狀態
?
配置文件簡介:
vim /etc/chrony.conf
server 0.centos.pool.ntp.org iburst??????? //”必須以server “格式使用,添加的是時鐘服務器
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
?
# Ignore stratum in source selection.
stratumweight 0??????? //設置當chronyd從可用源中選擇同步源時,每個層應該添加多少距離到同步距離。默認設置為0,讓chronyd在選擇源時忽略源的層級。
?
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift????? //記錄系統時鐘增益/損耗時間的速率。
?
# Enable kernel RTC synchronization.
rtcsync?????? //該指令啟動一個內核模式,作用:系統時間每11分鐘會拷貝到實時時鐘????
?
# In first three updates step the system clock instead of slew
# if the adjustment is larger than 10 seconds.
makestep 10 3?????? //chronyd將根據需求通過減慢或加速時鐘,使得系統逐步糾正所有時間偏差。
?
# Allow NTP client access from local network.
#allow 192.168/16???????
#deny 192.168.25.100??? ?//這里可以指定一臺主機、子網或者網絡作為白/黑名單
allow表示允許哪些客戶端來共享本機的時間
?
# Listen for commands only on localhost.
bindcmdaddress 127.0.0.1????? //允許限制chronyc監聽哪個網絡接口的命令包
bindcmdaddress ::1
?
# Serve time even if not synchronized to any NTP server.
#local stratum 10?????? //這個功能開啟后,本機不去同步別人的時間到本機
?
keyfile /etc/chrony.keys??? //該配置文件中,參數generatecommandkey指定了產生一個SHA1或MD5加密的密碼,存放在/etc/chrony.keys中
?
服務器端配置:
vim /etc/chrony.conf
local stratum 10?? 打開該注釋,即開啟時間共享功能并設定共享級別
設置allow參數,設置允許的客戶端來共享本機時間
systemctl restart chronyd
?
客戶端配置:
vim /etc/chrony.conf
注釋掉默認配置的server參數,并添加:
server 服務器端ip iburst
systemctl restart chronyd
chronyc sources –v??? 查看時間同步進度,*表示時間同步完成,?表示未完成,可以檢查是否防火墻或者服務問題
可用watch –n 1 date進行監控看是否同步
?
Rhel6時間同步服務器(默認)ntp?? 端口:UDP/123
ntp簡介:
1、網絡時間協議,用來使計算機時間同步化的一種協議,可以使計算機對服務器或時鐘源做同步化,提供高準確度的時間矯正。
2、使用C/S模式,適用于一臺時間服務器接收上層時間服務器的信息,并提供時間信息給下層用戶。
?
yum install –y ntp
systemctl start ntpd
注意:iptables 、ntp、ntpdate 三者不能同時開啟,否則可能導致socket被占用
?
配置文件簡介:
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
?
driftfile /var/lib/ntp/drift??????? //設置保存漂移時間的文件
?
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery????? //拒絕IPv4所有用戶訪問
restrict -6 default kod nomodify notrap nopeer noquery?? //拒絕IPv6用戶訪問
?
# Permit all access over the loopback interface.? This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1???????? //允許本機查詢
restrict -6 ::1
?
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap??????? //設置訪問權限,default是指所有的IP
?
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
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 ??//自定義一個可用的同步IP地址(客戶端配置),格式:
server [IP|HOST Name] [prefer]?? ???//設置上層時間服務器, prefer表示優先被客戶端訪問
?
#broadcast 192.168.1.255 autokey??????? # broadcast server
#broadcastclient??????????????????????? # broadcast client
#broadcast 224.0.1.1 autokey??????????? # multicast server
#multicastclient 224.0.1.1????????????? # multicast client
#manycastserver 239.255.254.254???????? # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
?
環境:
本地系統時間服務器IP??? 服務端:10.5.193.38 ???客戶端:10.5.193.39
?
服務器端配置:
server 210.72.145.44??? //指定本ntp服務器的上游ntp服務器為210.72.145.44,
并且設置為優先服務器。同步時間為:從上到下,寫的越靠上,優先級越高。(若此服務器同步不了時間,尋找下一個ntp服務器)。該IP地址是中國國家授時中心ntp服務器。
?
server 10.5.193.38?? #local clock 如果上面的服務器都無法同步時間,就和本地系統時間同步,這里的10.5.193.38是一個IP地址,不是網段。
?
在默認的restrict 127.0.0.1后面加上以下內容:
restrict 10.5.193.39??????? //即允許10.5.193.39進行同步
restrict 10.5.193.0 mask 255.255.255.0 nomodify notrap //允許10.5.193.0/24網段同步
?
客戶端配置:
注釋掉默認的 server 參數,并加上我們的時間同步服務器端IP/域名,其中prefer選項表示優先使用該服務器。例:
server 10.5.193.38 prefer ?????//優先使用10.5.193.38這臺服務器進行時間同步
/etc/init.d/ntpd restart
總結
以上是生活随笔為你收集整理的时间同步服务器(默认)chrony和ntp的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: shell的数字、字符串处理
- 下一篇: ntp 、ntpdate 、chrony