0
点赞
收藏
分享

微信扫一扫

chrony时间同步

墨春 2023-05-22 阅读 67
chrony运维

server:

#!/bin/bash





cd $(dirname $0)
date=$(date +%Y%m%d%H%M%S)
ssh_ip_list=""
ssh_password=""





mkdir ${date}_chrony_server
yum install sshpass -y





cat > ./${date}_chrony_server/chrony.conf << EOF
server ntp.aliyun.com iburst
driftfile /var/lib/chrony/drift
makestep 1 -1
rtcsync
bindcmdaddress 127.0.0.1
allow x.x.x.x/24
local stratum 10
logdir /var/log/chrony
EOF





for ssh_ip in ${ssh_ip_list}
do

    sshpass -p ${ssh_password} ssh root@${ssh_ip} 'yum install chrony -y'
    sshpass -p ${ssh_password} scp ./${date}_chrony_server/chrony.conf root@${ssh_ip}:/etc/chrony.conf
    sshpass -p ${ssh_password} ssh root@${ssh_ip} 'systemctl restart chronyd.service'
    sshpass -p ${ssh_password} ssh root@${ssh_ip} 'systemctl enable chronyd.service'
done





rm -rf ${date}_chrony_server



client:

#!/bin/bash





cd $(dirname $0)
date=$(date +%Y%m%d%H%M%S)
chrony_server_ip=""
ssh_ip_list=""
ssh_password=""





mkdir ${date}_chrony_client
yum install sshpass -y





cat > ./${date}_chrony_client/chrony.conf << EOF
server $chrony_server_ip iburst
driftfile /var/lib/chrony/drift
makestep 1 -1
rtcsync
bindcmdaddress 127.0.0.1
logdir /var/log/chrony
EOF





for ssh_ip in ${ssh_ip_list}
do

    sshpass -p ${ssh_password} ssh root@${ssh_ip} 'yum install chrony -y'
    sshpass -p ${ssh_password} scp ./${date}_chrony_client/chrony.conf root@${ssh_ip}:/etc/chrony.conf
    sshpass -p ${ssh_password} ssh root@${ssh_ip} 'systemctl restart chronyd.service'
    sshpass -p ${ssh_password} ssh root@${ssh_ip} 'systemctl enable chronyd.service'
done





rm -rf ${date}_chrony_client


举报

相关推荐

0 条评论