chrony时间同步 服务端 客户端 安装配置

#!/bin/sh
#运行环境 centos7
#chrony时间同步 服务端 客户端 安装配置

#安装
yum install chrony -y
cp /etc/chrony.conf{,.bak} #备份默认配置

#chrony服务配置
echo "
# #外部NTP服务#
server ntp6.aliyun.com iburst
server cn.ntp.org.cn iburst
server ntp.shu.edu.cn iburst
driftfile /var/lib/chrony/drift
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
logdir /var/log/chrony
">/etc/chrony.conf

#chrony作为内网NTP服务配置
echo "
# #外部NTP服务
server ntp6.aliyun.com iburst
server cn.ntp.org.cn iburst
server ntp.shu.edu.cn iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
# #内网
allow 10.2.1.0/24
allow 172.16.11.0/24
bindcmdaddress 127.0.0.1
bindcmdaddress ::1
keyfile /etc/chrony.keys
commandkey 1
generatecommandkey
noclientlog
logchange 0.5
logdir /var/log/chrony
">/etc/chrony.conf

#chrony使用内网NTP服务配置
echo "
# #内部NTP服务
server 10.2.1.10 iburst
server ntp6.aliyun.com iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
logdir /var/log/chrony
">/etc/chrony.conf

#启动
systemctl start chronyd
systemctl enable chronyd #开机启动
systemctl restart chronyd
chronyc sources #查看同步源

##查看

chronyc sources #服务端
# 210 Number of sources = 3
# MS Name/IP address         Stratum Poll Reach LastRx Last sample               
# ===============================================================================
# ^* time6.aliyun.com              2   6   377    71  -2307us[-3126us] +/-   20ms
# ^+ xk-6-95-a8.bta.net.cn         2   6   377     7   +767us[ +767us] +/-   62ms
# ^- ntp.shu.edu.cn                2   6   377     7    -11ms[  -11ms] +/-  419ms

# # chronyc sources #客户端
# 210 Number of sources = 1
# MS Name/IP address         Stratum Poll Reach LastRx Last sample               
# ===============================================================================
# ^* kweb.w.dev                    3   6   377    44    -99us[ +160us] +/-   21ms

 

posted @ 2019-03-18 09:51  侃豺小哥  阅读(455)  评论(0编辑  收藏  举报