centos-8安裝時間服務器chrony


在時間服務器領域,一直擔當杠把子角色的NTP,其實確切的說是ntpd程序,它跟chrony一樣,是NTP(network time protocol網絡時間協議)協議的程序實現。總體上來說,chrony更為簡單,比如,客戶端安裝好chrony之后,並不需要設定crontab任務來定時同步時間,它是自動的,同步的時間間隔在chrony.conf配置文件中設定即可。

chrony是在centos-8里才出現的,用來替代ntpd程序。一開始我也並不知道,所以有了下面這個坑。。。

[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 

當時就活見鬼了,怎么會這樣呢,哎,只能慨嘆IT領域的變化實在太快了。

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

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

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

與NTP不同的是,chrony不分服務器端和客戶端。chrony可以同時扮演服務器端和客戶端角色。

修改配置文件中這一行

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

改成時間同步的目標服務器地址

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

保存退出,重啟chronyd服務即可。

[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

配置防火牆

firewall-cmd --zone=public --add-port=123/udp --permanent
firewall-cmd --reload

啟動chrony服務

systemctl restart chronyd



作者:liuxiaolin
鏈接:https://www.jianshu.com/p/dc9e49cfe956
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM