centos-8安裝時(shí)間服務(wù)器chrony

在時(shí)間服務(wù)器領(lǐng)域泡躯,一直擔(dān)當(dāng)杠把子角色的NTP列敲,其實(shí)確切的說是ntpd程序母怜,它跟chrony一樣,是NTP(network time protocol網(wǎng)絡(luò)時(shí)間協(xié)議)協(xié)議的程序?qū)崿F(xiàn)箍邮≤运В總體上來說,chrony更為簡單锭弊,比如堪澎,客戶端安裝好chrony之后,并不需要設(shè)定crontab任務(wù)來定時(shí)同步時(shí)間味滞,它是自動(dòng)的樱蛤,同步的時(shí)間間隔在chrony.conf配置文件中設(shè)定即可。

chrony是在centos-8里才出現(xiàn)的剑鞍,用來替代ntpd程序昨凡。一開始我也并不知道,所以有了下面這個(gè)坑蚁署。便脊。。

[root@hadoop02 yum.repos.d]# yum -y install ntp ntpdate
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
Last metadata expiration check: 0:07:08 ago on Thu 12 Mar 2020 08:32:10 AM EDT.
No match for argument: ntp
No match for argument: ntpdate
Error: Unable to find a match: ntp ntpdate

當(dāng)時(shí)就活見鬼了光戈,怎么會(huì)這樣呢哪痰,哎,只能慨嘆IT領(lǐng)域的變化實(shí)在太快了久妆。

OK晌杰,回歸正題,以下是chrony的安裝配置過程:

1筷弦、用yum安裝chrony

[root@hadoop02 yum.repos.d]# yum -y install chrony
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
CentOS-8 - AppStream                                                                                                                                                                       1.0 MB/s | 6.5 MB     00:06    
CentOS-8 - Extras                                                                                                                                                                          364  B/s | 2.1 kB     00:05    
CentOS-8 - Base - mirrors.aliyun.com                                                                                                                                                       1.5 MB/s | 5.0 MB     00:03    
Package chrony-3.5-1.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

毫無難度肋演,傻瓜式安裝,一行命令搞定烂琴。

2爹殊、配置chrony
chrony的配置文件是/etc/chrony.conf

 [root@hadoop02 etc]# vim  /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
pool 2.centos.pool.ntp.org iburst

# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3

# Enable kernel synchronization of the real-time clock (RTC).
rtcsync

# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *

# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2

# Allow NTP client access from local network.
#allow 192.168.0.0/16

# Serve time even if not synchronized to a time source.
#local stratum 10

# Specify file containing keys for NTP authentication.
keyfile /etc/chrony.keys

# Get TAI-UTC offset and leap seconds from the system tz database.
leapsectz right/UTC

# Specify directory for log files.
logdir /var/log/chrony

# Select which information is logged.
#log measurements statistics tracking

配置文件里的注釋清晰的說明了各個(gè)配置選項(xiàng)的功能,如果看不懂英文奸绷,下面是我在網(wǎng)上找到的中文翻譯版本(https://blog.csdn.net/dengshulei/article/details/103749922)边灭。

image.png

上面這個(gè)中文注釋基本上把各個(gè)主要的配置功能說清楚了。

與NTP不同的是健盒,chrony不分服務(wù)器端和客戶端绒瘦。chrony可以同時(shí)扮演服務(wù)器端和客戶端角色。

修改配置文件中這一行

# Please consider joining the pool (http://www.pool.ntp.org/join.html).
pool 2.centos.pool.ntp.org iburst

改成時(shí)間同步的目標(biāo)服務(wù)器地址

# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 192.168.129.1 iburst

保存退出扣癣,重啟chronyd服務(wù)即可惰帽。

[root@hadoop02 etc]# systemctl restart chronyd
[root@hadoop02 etc]# systemctl status chronyd
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-03-12 09:04:51 EDT; 14h ago
     Docs: man:chronyd(8)
           man:chrony.conf(5)
  Process: 9146 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS)
  Process: 9140 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 9144 (chronyd)
    Tasks: 1 (limit: 9643)
   Memory: 1.8M
   CGroup: /system.slice/chronyd.service
           └─9144 /usr/sbin/chronyd

Mar 12 09:04:51 hadoop02 systemd[1]: Starting NTP client/server...
Mar 12 09:04:51 hadoop02 chronyd[9144]: chronyd version 3.5 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +SECHASH +IPV6 +DEBUG)
Mar 12 09:04:51 hadoop02 chronyd[9144]: Frequency -1.509 +/- 0.597 ppm read from /var/lib/chrony/drift
Mar 12 09:04:51 hadoop02 chronyd[9144]: Using right/UTC timezone to obtain leap second data
Mar 12 09:04:51 hadoop02 systemd[1]: Started NTP client/server.
Mar 12 09:04:56 hadoop02 chronyd[9144]: Selected source 162.159.200.123
Mar 12 09:04:56 hadoop02 chronyd[9144]: System clock TAI offset set to 37 seconds
Mar 12 09:04:56 hadoop02 chronyd[9144]: System clock wrong by 50818.862032 seconds, adjustment started
Mar 12 23:11:55 hadoop02 chronyd[9144]: System clock was stepped by 50818.862032 seconds
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市父虑,隨后出現(xiàn)的幾起案子该酗,更是在濱河造成了極大的恐慌,老刑警劉巖士嚎,帶你破解...
    沈念sama閱讀 211,884評(píng)論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件呜魄,死亡現(xiàn)場離奇詭異,居然都是意外死亡莱衩,警方通過查閱死者的電腦和手機(jī)爵嗅,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,347評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來笨蚁,“玉大人睹晒,你說我怎么就攤上這事±ㄏ福” “怎么了伪很?”我有些...
    開封第一講書人閱讀 157,435評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長奋单。 經(jīng)常有香客問我锉试,道長,這世上最難降的妖魔是什么览濒? 我笑而不...
    開封第一講書人閱讀 56,509評(píng)論 1 284
  • 正文 為了忘掉前任呆盖,我火速辦了婚禮,結(jié)果婚禮上匾七,老公的妹妹穿的比我還像新娘絮短。我一直安慰自己,他們只是感情好昨忆,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,611評(píng)論 6 386
  • 文/花漫 我一把揭開白布丁频。 她就那樣靜靜地躺著,像睡著了一般邑贴。 火紅的嫁衣襯著肌膚如雪席里。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,837評(píng)論 1 290
  • 那天拢驾,我揣著相機(jī)與錄音奖磁,去河邊找鬼。 笑死繁疤,一個(gè)胖子當(dāng)著我的面吹牛咖为,可吹牛的內(nèi)容都是我干的秕狰。 我是一名探鬼主播,決...
    沈念sama閱讀 38,987評(píng)論 3 408
  • 文/蒼蘭香墨 我猛地睜開眼躁染,長吁一口氣:“原來是場噩夢啊……” “哼鸣哀!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起吞彤,我...
    開封第一講書人閱讀 37,730評(píng)論 0 267
  • 序言:老撾萬榮一對情侶失蹤我衬,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后饰恕,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體挠羔,經(jīng)...
    沈念sama閱讀 44,194評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,525評(píng)論 2 327
  • 正文 我和宋清朗相戀三年埋嵌,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了破加。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,664評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡莉恼,死狀恐怖拌喉,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情俐银,我是刑警寧澤尿背,帶...
    沈念sama閱讀 34,334評(píng)論 4 330
  • 正文 年R本政府宣布,位于F島的核電站捶惜,受9級(jí)特大地震影響田藐,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜吱七,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,944評(píng)論 3 313
  • 文/蒙蒙 一汽久、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧踊餐,春花似錦景醇、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,764評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至窜管,卻和暖如春散劫,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背幕帆。 一陣腳步聲響...
    開封第一講書人閱讀 31,997評(píng)論 1 266
  • 我被黑心中介騙來泰國打工获搏, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人失乾。 一個(gè)月前我還...
    沈念sama閱讀 46,389評(píng)論 2 360
  • 正文 我出身青樓常熙,卻偏偏與公主長得像纬乍,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子症概,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,554評(píng)論 2 349

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