linux設(shè)置ntp時間同步

NTP時鐘同步方式說明

創(chuàng)新互聯(lián)公司是專業(yè)的興山網(wǎng)站建設(shè)公司,興山接單;提供成都網(wǎng)站設(shè)計、成都網(wǎng)站制作,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行興山網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!

NTP在linux下有兩種時鐘同步方式,分別為直接同步和平滑同步:
直接同步
使用ntpdate命令進(jìn)行同步,直接進(jìn)行時間變更。如果服務(wù)器上存在一個12點(diǎn)運(yùn)行的任務(wù),當(dāng)前服務(wù)器時間是13點(diǎn),但標(biāo)準(zhǔn)時間時11點(diǎn),使用此命令可能會造成任務(wù)重復(fù)執(zhí)行。因此使用ntpdate同步可能會引發(fā)風(fēng)險,因此該命令也多用于配置時鐘同步服務(wù)時第一次同步時間時使用。
平滑同步
使用ntpd進(jìn)行時鐘同步,可以保證一個時間不經(jīng)歷兩次,它每次同步時間的偏移量不會太陡,是慢慢來的,這正因?yàn)檫@樣,ntpd平滑同步可能耗費(fèi)的時間比較長。

1、安裝ntp

yum install ntp

2、設(shè)置ntp服務(wù)開機(jī)啟動

systemctl  restart ntp.service

3、設(shè)置服務(wù)器

3.1. vi /etc/ntp.conf,內(nèi)容如下:

driftfile /var/lib/ntp/ntp.drift #草稿文件

# 允許內(nèi)網(wǎng)其他機(jī)器同步時間

restrict 192.168.137.0(替換成自己的ip) mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.

# 中國這邊最活躍的時間服務(wù)器 :

[http://www.pool.ntp.org/zone/cn](http://www.pool.ntp.org/zone/cn)

server 210.72.145.44 perfer   # 中國國家受時中心

server 202.112.10.36             # 1.cn.pool.ntp.org

server 59.124.196.83             # 0.asia.pool.ntp.org  

# allow update time by the upper server

# 允許上層時間服務(wù)器主動修改本機(jī)時間

restrict 210.72.145.44 nomodify notrap noquery

restrict 202.112.10.36 nomodify notrap noquery

restrict 59.124.196.83 nomodify notrap noquery  

# 外部時間服務(wù)器不可用時,以本地時間作為時間服務(wù)

server  127.127.1.0     # local clock

fudge   127.127.1.0 stratum 10

3.2 重啟服務(wù):service ntpd restart

3.3查看同步狀態(tài):netstat -tlunp | grep ntp

4、設(shè)置同步

4.1 vim /etc/ntp.conf,內(nèi)容如下:

driftfile /var/lib/ntp/ntp.drift # 草稿文件

statsdir /var/log/ntpstats/

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

#讓NTP Server為內(nèi)網(wǎng)的ntp服務(wù)器

server 192.168.137.110 (master節(jié)點(diǎn)ip)

fudge 192.168.137.110 stratum 5

#不允許來自公網(wǎng)上ipv4和ipv6客戶端的訪問

restrict -4 default kod notrap nomodify nopeer noquery

restrict -6 default kod notrap nomodify nopeer noquery

#Local users may interrogate the ntp server more closely.

restrict 127.0.0.1

restrict ::1

4.2重啟服務(wù):service ntpd restart

4.3手動同步:ntpdate -u 192.168.124.146

新聞名稱:linux設(shè)置ntp時間同步
網(wǎng)站鏈接:http://muchs.cn/article6/jojdig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、品牌網(wǎng)站制作、自適應(yīng)網(wǎng)站微信公眾號、服務(wù)器托管、移動網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營