CentOS7 使用chrony搭建集群中的時間同步服務


一、集群環境:

  系統:CentOS7-minimal

  集群中的兩台主機ip:10.132.226.103/24  10.132.226.104/24

二、CentOS7中時間相關命令timedatectl例子介紹:

  1.查看主機中的時間信息:timedatectl

1 [root@controller ~]# timedatectl
2       Local time: Tue 2018-07-24 00:27:53 CST
3   Universal time: Mon 2018-07-23 16:27:53 UTC
4         RTC time: Tue 2018-07-24 00:27:53
5        Time zone: Asia/Shanghai (CST, +0800)
6      NTP enabled: yes
7 NTP synchronized: yes         //NTP時間同步開啟
8  RTC in local TZ: yes
9       DST active: n/a

  2.查看可獲取的時區:timedatectl list-timezones

1 [root@controller ~]# timedatectl list-timezones
2 Africa/Abidjan
3 Africa/Accra
4 Africa/Addis_Ababa
5 ........

  3.設置本地時區:timedatectl set-timezone Asia/Shanghai

1 # timedatectl set-timezone Asia/Shanghai

  4.設置時間日期等:

1 [root@controller ~]# timedatectl set-time "2018-07-19 18:08:08"
2 [root@controller ~]# timedatectl set-time "2018-07-19"
3 [root@controller ~]# timedatectl set-time "18:08:08"

  5.將硬件時鍾設置為本地時區:

1 [root@controller ~]# timedatectl set-local-rtc 1

  6.將硬件時鍾設置為協調世界時(UTC):

[root@controller ~]# timedatectl set-local-rtc 0

 三、安裝配置chrony

  1.主節點安裝:

1 [root@controller ~]# yum install -y chrony

 

    2.主節點配置:編輯 /etc/chrony.conf文件

[root@controller ~]# 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).
#以下0.centos.pool.ntp.org等為遠程時間同步服務器可自行更改
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 iburst  
#~~~~~~~~~~~省略若干~~~~~~~~#
# Allow NTP client access from local network.
#allow 192.168.0.0/16
#修改!!!
#此處添加子節點的IP
allow 10.132.226.104/24
#~~~~~~~~~~~省略若干~~~~~~~~#

  3.主節點重啟NTP服務

1 [root@controller ~]# systemctl enable chronyd.service
2 [root@controller ~]# systemctl start chronyd.service

  4.子節點安裝:

1 [root@compute1 ~]# yum install -y chrony

  5.子節點配置:編輯 /etc/chrony.conf文件

 1 [root@compute1 etc]# vim /etc/chrony.conf
 2 
 3 # Use public servers from the pool.ntp.org project.
 4 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
 5 #修改 把其他遠程同步節點全部注釋,並添加主節點ip或者hosts
 6 #server 0.centos.pool.ntp.org iburst
 7 #server 1.centos.pool.ntp.org iburst
 8 #server 2.centos.pool.ntp.org iburst
 9 #server 3.centos.pool.ntp.org iburst
10 server controller iburst

四、驗證同步服務是否搭建成功:

  1.使用命令 chronyc sources

1 [root@compute1 etc]# chronyc sources
2 210 Number of sources = 1
3 MS Name/IP address         Stratum Poll Reach LastRx Last sample               
4 ===============================================================================
5 ^* controller                    3   6   377    22  -5232us[-6125us] +/-   47ms

    注意:如果controller前為^? 可能是主節點防火牆開啟,導致子節點無法進行時間同步。

  可以也可以通過timedatectl命令查看:

1 [root@compute1 etc]# timedatectl
2       Local time: Mon 2018-07-23 23:41:49 CST
3   Universal time: Mon 2018-07-23 15:41:49 UTC
4         RTC time: Mon 2018-07-23 23:41:49
5        Time zone: Asia/Shanghai (CST, +0800)
6      NTP enabled: yes
7 NTP synchronized: yes           //此處如果為no說明NTP時鍾為開啟
8  RTC in local TZ: yes
9       DST active: n/a

  解決方法:關閉主節點防火牆

 

 

 

 


免責聲明!

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



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