在時(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)边灭。
上面這個(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