环境介绍
server | 192.168.6.241 |
chlient1 | 192.168.3.75 |
chlient2 | 192.168.3.22 |
所有主机
yum -y install chrony
server主机
配置文件 /etc/chrony.conf
#修改local stratum 12 修改stratum系统的时钟源级别从较低的级别提升到较高的级别
#需改allow 192.168.0.0/16 允许192.168.0.0/16网段同步时间
sed -i 's/#local stratum 10/local stratum 12/' /etc/chrony.conf
sed -i 's/#allow 192.168.0.0\/16/allow 192.168.0.0\/16/' /etc/chrony.conf
systemctl restart chronyd
systemctl enable chronyd
chlient主机
配置文件 /etc/chrony.conf
#需要修改
server 192.168.6.241 iburst #为server端地址
systemctl restart chronyd
systemctl enable chronyd
ansible批量安装
server端配置文件 /etc/chrony.conf
#修改local stratum 12 修改stratum系统的时钟源级别从较低的级别提升到较高的级别
#修改allow 192.168.0.0/16 允许192.168.0.0/16网段同步时间
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server ntp.aliyun.com 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 0.0.0.0/16
# Serve time even if not synchronized to a time source.
local stratum 12
# 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
#chlient配置文件
/需要修改的位置,server 192.168.3.147 iburst
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 192.168.3.147 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 0.0.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
# Specify directory for log files.
logdir /var/log/chrony
# Select which information is logged.
#log measurements statistics tracking
ansible批量安装
#分发
ansible cus -b -m copy -a "src=/root/chrony/chrony-3.4-1.el7.x86_64.rpm dest=/root"
#安装
ansible cus -m shell -a "rpm -ihv /root/chrony-3.4-1.el7.x86_64.rpm"
#配置文件/root/chrony.conf/ 为客户端配置文件
ansible cus -b -m copy -a "src=/root/chrony.conf dest=/etc/chrony.conf"
#启动
ansible cus -m shell -a "systemctl restart chronyd && systemctl enable chronyd"
#删除包
ansible cus -m shell -a "rm -fr /root/chrony-3.4-1.el7.x86_64.rpm"