CentOS7搭建chrony时间服务器

CentOS7搭建时间服务器chrony

    时间服务器:master IP:10.1.1.1 客户端: node1 IP:10.1.1.17
  1. 使用yum安装chrony
[root@master ~]# yum install -y chrony
    查看chrony软件信息
[root@master ~]# rpm -qi chrony
    查看chrony相关文件
[root@master ~]# rpm -ql chrony
  1. 配置chrony作为时间服务器
[root@master ~]# 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).
#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
server ntp2.aliyun.com iburst     #指定互联网上的ntp时间同步服务器,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
allow 10.1.1.0/24      #允许10.1.1.0/24网段作为客户端向本时间服务器同步时间

# Serve time even if not synchronized to a time source.
local stratum 10         #允许客户端接受不精确时间,当本服务器无法向其他时间服务器如ntp2.aliyun.com同步时间,依然能为客户端提供时间服务                                 

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

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

# Select which information is logged.
#log measurements statistics tracking
    启动chrony服务
[root@node1 ~]# systemctl start chronyd.service
    查看chrony服务状态
[root@node1 ~]# systemctl status chronyd.service
    设置chrony开机自启动
[root@node1 ~]# systemctl status chronyd.service
    防火墙放开chronyd默认端口123/udp 323/udp
chronyd监听323/udp 123/udp端口
[root@master ~]# firewall-cmd --permanent --zone=public --add-port 123/udp
[root@master ~]# firewall-cmd --permanent --zone=public --add-port 323/udp
[root@master ~]# firewall-cmd --reload
  1. 利用chrony作为客户端
    编辑chrony配置文件
[root@node1 ~]# 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).
#server 0.centos.pool.ntp.org iburst      #默认指定CentOS官方的时间服务器地址 
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 10.1.1.1 iburst     #此处指定时间server地址

# 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

# Specify directory for log files.
logdir /var/log/chrony
    启动chrony服务
[root@node1 ~]# systemctl start chronyd.service
客户端修改chrony.conf文件并开启chronyd服务,就能向时间服务器同步时间了
    查看chrony服务状态
[root@node1 ~]# systemctl status chronyd.service
    设置chrony开机自启动
[root@node1 ~]# systemctl enable chronyd.service
查看同步状态 [root@master ~]# chronyc sources
经验分享 程序员 微信小程序 职场和发展