使用阿里云鏡像站NTP服務(wù)搭建NTP服務(wù)器(基于CentOS 7系統(tǒng))

參考鏈接:

[阿里巴巴開源鏡像站](https://developer.aliyun.com/mirror/?spm=a2c6h.13651102.0.0.38221b11i1SzUL&serviceType=mirror)

[NTP下載安裝教程](https://developer.aliyun.com/mirror/NTP?spm=a2c6h.13651102.0.0.38221b11LFNKaZ)

一、NTP服務(wù)器介紹

網(wǎng)絡(luò)時間協(xié)議(Network Time Protocol据德,NTP)服務(wù)器翠拣,也就是日常所說的NTP服務(wù)器厅篓,用來提供同步時間服務(wù)宵呛。在生產(chǎn)環(huán)境中握巢,很多人都會忽略時間問題,實(shí)際上服務(wù)器压怠、網(wǎng)絡(luò)設(shè)備等池充,特別是Linux操作系統(tǒng)和虛擬化平臺的時間不同步會導(dǎo)致很多問題桩引。那么搭建一臺NTP服務(wù)器就非常重要,生產(chǎn)環(huán)境中的設(shè)備可以直接與NTP服務(wù)器進(jìn)行時間同步收夸,NTP服務(wù)器本身也可以訪問互連的NTP服務(wù)器進(jìn)行同步坑匠。NTP服務(wù)器可以是物理服務(wù)器,也可以是虛擬機(jī)卧惜。

二厘灼、安裝NTP服務(wù)組件

在Linux服務(wù)器(如,CentOS咽瓷、Ubuntu等操作系統(tǒng))上设凹,使用命令進(jìn)行安裝。

本實(shí)驗(yàn)以CentOS 7 Linux環(huán)境進(jìn)行演示操作記錄忱详。

YUM源已更新成阿里云開源鏡像站里的CentOS鏡像围来,加速快捷訪問。

```

[root@ntp ~]# yum clean allLoaded plugins: fastestmirror

Cleaning repos: base extras updates

Cleaning up list of fastest mirrors

[root@ntp ~]# yum repolistLoaded plugins: fastestmirror

Determining fastest mirrors

* base: mirrors.aliyun.com

* extras: mirrors.aliyun.com

* updates: mirrors.aliyun.com

base? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 3.6 kB? 00:00:00? ?

extras? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 2.9 kB? 00:00:00? ?

updates? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 2.9 kB? 00:00:00? ?

(1/4): base/7/x86_64/group_gz? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 153 kB? 00:00:00? ?

(2/4): extras/7/x86_64/primary_db? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 243 kB? 00:00:00? ?

(3/4): updates/7/x86_64/primary_db? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |? 12 MB? 00:00:01? ?

(4/4): base/7/x86_64/primary_db? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 6.1 MB? 00:00:03? ?

repo id? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? repo name? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? status

base/7/x86_64? ? ? ? ? ? ? ? ? ? ? ? ? ? CentOS-7 - Base - mirrors.aliyun.com? ? ? ? ? ? ? ? ? ? ? ? ? ? 10,072

extras/7/x86_64? ? ? ? ? ? ? ? ? ? ? ? ? CentOS-7 - Extras - mirrors.aliyun.com? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 500

updates/7/x86_64? ? ? ? ? ? ? ? ? ? ? ? ? CentOS-7 - Updates - mirrors.aliyun.com? ? ? ? ? ? ? ? ? ? ? ? ? 2,963

repolist: 13,535

[root@ntp ~]#

```

執(zhí)行yum install -y ntp命令匈睁,進(jìn)行ntp組件安裝监透。

```

[root@ntp ~]# yum install -y ntpLoaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

* base: mirrors.aliyun.com

* extras: mirrors.aliyun.com

* updates: mirrors.aliyun.com

Resolving Dependencies

--> Running transaction check

---> Package ntp.x86_64 0:4.2.6p5-29.el7.centos.2 will be installed

--> Processing Dependency: ntpdate = 4.2.6p5-29.el7.centos.2 for package: ntp-4.2.6p5-29.el7.centos.2.x86_64

--> Processing Dependency: libopts.so.25()(64bit) for package: ntp-4.2.6p5-29.el7.centos.2.x86_64

--> Running transaction check

---> Package autogen-libopts.x86_64 0:5.18-5.el7 will be installed

---> Package ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2 will be installed

--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================

Package? ? ? ? ? ? ? ? ? ? ? Arch? ? ? ? ? ? ? ? Version? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Repository? ? ? ? Size

=================================================================================================================

Installing:

ntp? ? ? ? ? ? ? ? ? ? ? ? ? x86_64? ? ? ? ? ? ? 4.2.6p5-29.el7.centos.2? ? ? ? ? ? ? ? base? ? ? ? ? ? ? 549 k

Installing for dependencies:

autogen-libopts? ? ? ? ? ? ? x86_64? ? ? ? ? ? ? 5.18-5.el7? ? ? ? ? ? ? ? ? ? ? ? ? ? base? ? ? ? ? ? ? 66 k

ntpdate? ? ? ? ? ? ? ? ? ? ? x86_64? ? ? ? ? ? ? 4.2.6p5-29.el7.centos.2? ? ? ? ? ? ? ? base? ? ? ? ? ? ? 87 k

Transaction Summary

=================================================================================================================

Install? 1 Package (+2 Dependent packages)

Total download size: 701 k

Installed size: 1.6 M

Downloading packages:

(1/3): autogen-libopts-5.18-5.el7.x86_64.rpm? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |? 66 kB? 00:00:00? ?

(2/3): ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |? 87 kB? 00:00:00? ?

(3/3): ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 549 kB? 00:00:00? ?

-----------------------------------------------------------------------------------------------------------------

Total? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1.7 MB/s | 701 kB? 00:00:00? ?

Running transaction check

Running transaction testTransaction test succeeded

Running transaction

? Installing : autogen-libopts-5.18-5.el7.x86_64? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1/3

? Installing : ntpdate-4.2.6p5-29.el7.centos.2.x86_64? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 2/3

? Installing : ntp-4.2.6p5-29.el7.centos.2.x86_64? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 3/3

? Verifying? : ntpdate-4.2.6p5-29.el7.centos.2.x86_64? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1/3

? Verifying? : ntp-4.2.6p5-29.el7.centos.2.x86_64? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 2/3

? Verifying? : autogen-libopts-5.18-5.el7.x86_64? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 3/3

Installed:

? ntp.x86_64 0:4.2.6p5-29.el7.centos.2? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

Dependency Installed:

? autogen-libopts.x86_64 0:5.18-5.el7? ? ? ? ? ? ? ? ? ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2? ? ? ? ? ? ? ?

Complete!

[root@ntp ~]#

```

三、配置阿里云鏡像站NTP服務(wù)

配置之前航唆,測試服務(wù)器是否能夠訪問到阿里云NTP服務(wù)器胀蛮。

```

ping ntp.aliyun.com -c 5

```


修改/etc/ntp.conf配置文件。

注釋掉原來配置文件中的NTP服務(wù)器地址糯钙,添加阿里云NTP服務(wù)器地址粪狼。


[root@ntp ~]# vi /etc/ntp.conf[root@ntp ~]# cat /etc/ntp.conf# 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 nomodify notrap nopeer noquery# 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 ::1# Hosts on local network are less restricted.#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# Use public servers from the pool.ntp.org project.# Please consider joining the pool ().#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 iburstserver ntp.aliyun.com#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# Enable public key cryptography.#cryptoincludefile /etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operating# with symmetric key cryptography. keys /etc/ntp/keys# Specify the key identifiers which are trusted.#trustedkey 4 8 42# Specify the key identifier to use with the ntpdc utility.#requestkey 8# Specify the key identifier to use with the ntpq utility.#controlkey 8# Enable writing of statistics records.#statistics clockstats cryptostats loopstats peerstats# Disable the monitoring facility to prevent amplification attacks using ntpdc# monlist command when default restrict does not include the noquery flag. See# CVE-2013-5211 for more details.# Note: Monitoring will not be disabled with the limited restriction flag.disable monitor

[root@ntp ~]#

```

四退腥、啟動NTP服務(wù)

啟動ntp服務(wù)

```

systemctl start ntpd

```

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

```

systemctl enable ntpd

```

查看ntp服務(wù)是否正常

```

systemctl status ntpd

```

```

[root@ntp ~]# systemctl start ntpd[root@ntp ~]# systemctl enable ntpdCreated symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.

[root@ntp ~]# systemctl status ntpd● ntpd.service - Network Time Service

? Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)

? Active: active (running) since Sun 2021-11-28 19:06:34 CST; 23h left

Main PID: 1988 (ntpd)

? CGroup: /system.slice/ntpd.service

? ? ? ? ? └─1988 /usr/sbin/ntpd -u ntp:ntp -g

Nov 28 19:06:34 ntp ntpd[1988]: Listen normally on 3 ens32 192.168.1.50 UDP 123

Nov 28 19:06:34 ntp ntpd[1988]: Listen normally on 4 lo ::1 UDP 123

Nov 28 19:06:34 ntp ntpd[1988]: Listen normally on 5 ens32 fe80::e4b:3ef:613c:8741 UDP 123

Nov 28 19:06:34 ntp ntpd[1988]: Listening on routing socket on fd #22 for interface updatesNov 28 19:06:34 ntp ntpd[1988]: 0.0.0.0 c016 06 restart

Nov 28 19:06:34 ntp ntpd[1988]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM

Nov 28 19:06:34 ntp ntpd[1988]: 0.0.0.0 c011 01 freq_not_set

Nov 28 19:09:51 ntp ntpd[1988]: 0.0.0.0 c61c 0c clock_step -86398.982768 s

Nov 27 19:09:52 ntp ntpd[1988]: 0.0.0.0 c614 04 freq_mode

Nov 27 19:09:53 ntp ntpd[1988]: 0.0.0.0 c618 08 no_sys_peer

[root@ntp ~]#

```

五、查看NTP源

```

ntpq -p

```


即[203.107.6.88]地址為阿里云NTP服務(wù)器的IP地址再榄。


```

[root@ntp ~]# ntpq -p

remote refid st t when poll reach delay offset jitter

203.107.6.88 100.107.25.114 2 u 56 64 7 13.685 -0.002 0.415

```

六狡刘、查看NTP服務(wù)狀態(tài)

#輸出如下內(nèi)容,表示在同步中困鸥,需要耐心等待一下

[root@ntp ~]# ntpstatunsynchronised

? time server re-starting

? polling server every 8 s# 輸出如下內(nèi)容嗅蔬,表示同步成功

```

? [root@ntp ~]# ntpstatsynchronised to NTP server (203.107.6.88) at stratum 3

? time correct to within 958 ms

? polling server every 64 s

```


七、將客戶端與NTP服務(wù)器同步


```

[root@client ~]# ntpdate -d 192.168.1.5028 Nov 19:37:54 ntpdate[2880]: ntpdate 4.2.6p5@1.2349-o Tue Jun 23 15:38:19 UTC 2020 (1)

Looking for host 192.168.1.50 and service ntp

host found : 192.168.1.50

transmit(192.168.1.50)

receive(192.168.1.50)

transmit(192.168.1.50)

receive(192.168.1.50)

transmit(192.168.1.50)

receive(192.168.1.50)

transmit(192.168.1.50)

receive(192.168.1.50)

server 192.168.1.50, port 123

stratum 3, precision -25, leap 00, trust 000

refid [192.168.1.50], delay 0.02652, dispersion 0.00000

transmitted 4, in filter 4

reference time:? ? e54c9534.6f868aa9? Sat, Nov 27 2021 19:29:56.435

originate timestamp: e54c9719.4617ce7f? Sat, Nov 27 2021 19:38:01.273

transmit timestamp:? e54de898.b45bc870? Sun, Nov 28 2021 19:38:00.704

filter delay:? 0.02658? 0.02655? 0.02652? 0.02660

? ? ? ? 0.00000? 0.00000? 0.00000? 0.00000

filter offset: -86399.4 -86399.4 -86399.4 -86399.4

? ? ? ? 0.000000 0.000000 0.000000 0.000000

delay 0.02652, dispersion 0.00000

offset -86399.431479

28 Nov 19:38:00 ntpdate[2880]: step time server 192.168.1.50 offset -86399.431479 sec

[root@client ~]#

```

八疾就、將系統(tǒng)時間同步到硬件

```

[root@client ~]# hwclock -w

[root@client ~]# dateSun Nov 28 19:39:10 CST 2021

```

【阿里云官方鏡像站:? ? https://developer.aliyun.com/mirror/?utm_content=g_1000307095? ? 】

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末澜术,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子猬腰,更是在濱河造成了極大的恐慌鸟废,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,406評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件姑荷,死亡現(xiàn)場離奇詭異盒延,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)鼠冕,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,395評論 3 398
  • 文/潘曉璐 我一進(jìn)店門兰英,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人供鸠,你說我怎么就攤上這事≡赡郑” “怎么了楞捂?”我有些...
    開封第一講書人閱讀 167,815評論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長趋厉。 經(jīng)常有香客問我寨闹,道長,這世上最難降的妖魔是什么君账? 我笑而不...
    開封第一講書人閱讀 59,537評論 1 296
  • 正文 為了忘掉前任繁堡,我火速辦了婚禮,結(jié)果婚禮上乡数,老公的妹妹穿的比我還像新娘椭蹄。我一直安慰自己,他們只是感情好净赴,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,536評論 6 397
  • 文/花漫 我一把揭開白布绳矩。 她就那樣靜靜地躺著,像睡著了一般玖翅。 火紅的嫁衣襯著肌膚如雪翼馆。 梳的紋絲不亂的頭發(fā)上割以,一...
    開封第一講書人閱讀 52,184評論 1 308
  • 那天,我揣著相機(jī)與錄音应媚,去河邊找鬼严沥。 笑死,一個胖子當(dāng)著我的面吹牛中姜,可吹牛的內(nèi)容都是我干的消玄。 我是一名探鬼主播,決...
    沈念sama閱讀 40,776評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼扎筒,長吁一口氣:“原來是場噩夢啊……” “哼莱找!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起嗜桌,我...
    開封第一講書人閱讀 39,668評論 0 276
  • 序言:老撾萬榮一對情侶失蹤奥溺,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后骨宠,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體浮定,經(jīng)...
    沈念sama閱讀 46,212評論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,299評論 3 340
  • 正文 我和宋清朗相戀三年层亿,在試婚紗的時候發(fā)現(xiàn)自己被綠了桦卒。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,438評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡匿又,死狀恐怖方灾,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情碌更,我是刑警寧澤裕偿,帶...
    沈念sama閱讀 36,128評論 5 349
  • 正文 年R本政府宣布,位于F島的核電站痛单,受9級特大地震影響嘿棘,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜旭绒,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,807評論 3 333
  • 文/蒙蒙 一鸟妙、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧挥吵,春花似錦重父、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,279評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至脉幢,卻和暖如春歪沃,著一層夾襖步出監(jiān)牢的瞬間嗦锐,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,395評論 1 272
  • 我被黑心中介騙來泰國打工沪曙, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留奕污,地道東北人。 一個月前我還...
    沈念sama閱讀 48,827評論 3 376
  • 正文 我出身青樓液走,卻偏偏與公主長得像碳默,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子缘眶,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,446評論 2 359

推薦閱讀更多精彩內(nèi)容