Modify the chrony shell script file on April 12, 2025.

This commit is contained in:
raymond9
2025-04-12 15:28:52 +08:00
parent 4c8e3ec492
commit aaad825ac7
2 changed files with 65 additions and 34 deletions

View File

@@ -3,12 +3,16 @@
#*************************************************************************************************************
#Author: Raymond
#QQ: 88563128
#Date: 2024-01-19
#Date: 2025-04-10
#FileName: install_chrony_client_v2.sh
#URL: raymond.blog.csdn.net
#Description: install_chrony_client for CentOS 7 & CentOS Stream 8/9 & Ubuntu 18.04/20.04/22.04 & Rocky 8/9
#Copyright (C): 2021 All rights reserved
#*************************************************************************************************************
#MIRROR: https://wx.zsxq.com/group/15555885545422
#Description: The chrony client install script supports
# “Rocky Linux 8 and 9, Almalinux 8 and 9, CentOS 7,
# CentOS Stream 8, 9 and 10, Ubuntu 18.04, 20.04, 22.04 and 24.04,
# Debian 11 and 12, openEuler 22.03 and 24.03, AnolisOS 8 and 23,
# OpencloudOS 8 and 9, openSUSE 15, Kylin Server v10,
# Uos Server v20“ operating systems.
#Copyright (C): 2025 All rights reserved
COLOR="echo -e \\033[01;31m"
END='\033[0m'
SERVER=172.31.0.9
@@ -18,19 +22,29 @@ os(){
}
install_chrony(){
if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ] &> /dev/null;then
rpm -q chrony &> /dev/null || { ${COLOR}"安装chrony包请稍等..."${END};yum -y install chrony &> /dev/null; }
sed -i -e '/^pool.*/d' -e '/^server.*/d' -e '/^# Please consider .*/a\server '${SERVER}' iburst' /etc/chrony.conf
systemctl restart chronyd && systemctl enable --now chronyd &> /dev/null
systemctl is-active chronyd &> /dev/null || { ${COLOR}"chrony 启动失败,退出!"${END} ; exit; }
${COLOR}"chrony安装完成"${END}
if [ ${OS_ID} == "Rocky" -o ${OS_ID} == "AlmaLinux" -o ${OS_ID} == "CentOS" -o ${OS_ID} == "openEuler" -o ${OS_ID} == "Anolis" -o ${OS_ID} == "OpenCloudOS" -o ${OS_ID} == "openSUSE" -o ${OS_ID} == "Kylin" -o ${OS_ID} == "UOS" ];then
if [ ${OS_ID} == "openSUSE" ];then
INSTALL_TOOL='zypper'
else
INSTALL_TOOL='yum'
fi
rpm -q chrony &> /dev/null || { ${COLOR}"安装chrony包请稍等..."${END};${INSTALL_TOOL} install -y chrony &> /dev/null; }
if [ ${OS_ID} == "OpenCloudOS" ];then
sed -i -e '/^pool.*/d' -e '/^server.*/d' -e '/^# Use public.*/a\server '${SERVER}' iburst' /etc/chrony.conf
else
sed -i -e '/^pool.*/d' -e '/^server.*/d' -e '/^# Please consider .*/a\server '${SERVER}' iburst' /etc/chrony.conf
fi
else
dpkg -s chrony &>/dev/null || { ${COLOR}"安装chrony包请稍等..."${END};apt -y install chrony &> /dev/null; }
sed -i -e '/^pool.*/d' -e '/^# See http:.*/a\server '${SERVER}' iburst' /etc/chrony/chrony.conf
systemctl restart chronyd && systemctl enable --now chronyd &> /dev/null
systemctl is-active chronyd &> /dev/null || { ${COLOR}"chrony 启动失败,退出!"${END} ; exit; }
${COLOR}"chrony安装完成"${END}
dpkg -s chrony &>/dev/null || { ${COLOR}"安装chrony包请稍等..."${END};apt install -y chrony &> /dev/null; }
if [ ${OS_ID} == "Ubuntu" ];then
sed -i -e '/^pool.*/d' -e '/^# See http:.*/a\server '${SERVER}' iburst' /etc/chrony/chrony.conf
else
sed -i -e '/^pool.*/d' -e '/^# Use Debian.*/a\server '${SERVER}' iburst' /etc/chrony/chrony.conf
fi
fi
systemctl restart chronyd && systemctl enable --now chronyd &> /dev/null
systemctl is-active chronyd &> /dev/null || { ${COLOR}"chrony 启动失败,退出!"${END} ; exit; }
${COLOR}"chrony安装完成"${END}
}
main(){

View File

@@ -1,38 +1,55 @@
#!/bin/bash
#
#*************************************************************************************************************
#**********************************************************************************
#Author: Raymond
#QQ: 88563128
#Date: 2024-01-19
#Date: 2025-04-10
#FileName: install_chrony_server_v2.sh
#URL: raymond.blog.csdn.net
#Description: install_chrony_server for CentOS 7 & CentOS Stream 8/9 & Ubuntu 18.04/20.04/22.04 & Rocky 8/9
#Copyright (C): 2024 All rights reserved
#*************************************************************************************************************
#MIRROR: https://wx.zsxq.com/group/15555885545422
#Description: The chrony server install script supports
# “Rocky Linux 8 and 9, Almalinux 8 and 9, CentOS 7,
# CentOS Stream 8, 9 and 10, Ubuntu 18.04, 20.04, 22.04 and 24.04,
# Debian 11 and 12, openEuler 22.03 and 24.03, AnolisOS 8 and 23,
# OpencloudOS 8 and 9, openSUSE 15, Kylin Server v10,
# Uos Server v20“ operating systems.
#Copyright (C): 2025 All rights reserved
#**********************************************************************************
COLOR="echo -e \\033[01;31m"
END='\033[0m'
NTP_SERVER1=ntp.aliyun.com
NTP_SERVER2=ntp.tencent.com
NTP_SERVER3=ntp.tuna.tsinghua.edu.cn
os(){
OS_ID=`sed -rn '/^NAME=/s@.*="([[:alpha:]]+).*"$@\1@p' /etc/os-release`
}
install_chrony(){
if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ] &> /dev/null;then
rpm -q chrony &> /dev/null || { ${COLOR}"安装chrony包请稍等..."${END};yum -y install chrony &> /dev/null; }
sed -i -e '/^pool.*/d' -e '/^server.*/d' -e '/^# Please consider .*/a\server ntp.aliyun.com iburst\nserver time1.cloud.tencent.com iburst\nserver ntp.tuna.tsinghua.edu.cn iburst' -e 's@^#allow.*@allow 0.0.0.0/0@' -e 's@^#local.*@local stratum 10@' /etc/chrony.conf
systemctl restart chronyd && systemctl enable --now chronyd &> /dev/null
systemctl is-active chronyd &> /dev/null || { ${COLOR}"chrony 启动失败,退出!"${END} ; exit; }
${COLOR}"chrony安装完成"${END}
if [ ${OS_ID} == "Rocky" -o ${OS_ID} == "AlmaLinux" -o ${OS_ID} == "CentOS" -o ${OS_ID} == "openEuler" -o ${OS_ID} == "Anolis" -o ${OS_ID} == "OpenCloudOS" -o ${OS_ID} == "openSUSE" -o ${OS_ID} == "Kylin" -o ${OS_ID} == "UOS" ];then
if [ ${OS_ID} == "openSUSE" ];then
INSTALL_TOOL='zypper'
else
INSTALL_TOOL='yum'
fi
rpm -q chrony &> /dev/null || { ${COLOR}"安装chrony包请稍等..."${END};${INSTALL_TOOL} install -y chrony &> /dev/null; }
if [ ${OS_ID} == "OpenCloudOS" ];then
sed -i -e '/^pool.*/d' -e '/^server.*/d' -e '/^# Use public.*/a\server '${NTP_SERVER1}' iburst\nserver '${NTP_SERVER2}' iburst\nserver '${NTP_SERVER3}' iburst' -e 's@^#allow.*@allow 0.0.0.0/0@' -e 's@^#local.*@local stratum 10@' /etc/chrony.conf
else
sed -i -e '/^pool.*/d' -e '/^server.*/d' -e '/^# Please consider .*/a\server '${NTP_SERVER1}' iburst\nserver '${NTP_SERVER2}' iburst\nserver '${NTP_SERVER3}' iburst' -e 's@^#allow.*@allow 0.0.0.0/0@' -e 's@^#local.*@local stratum 10@' /etc/chrony.conf
fi
else
dpkg -s chrony &>/dev/null || { ${COLOR}"安装chrony包请稍等..."${END};apt -y install chrony &> /dev/null; }
apt -y install chrony &> /dev/null
sed -i -e '/^pool.*/d' -e '/^# See http:.*/a\server ntp.aliyun.com iburst\nserver time1.cloud.tencent.com iburst\nserver ntp.tuna.tsinghua.edu.cn iburst' /etc/chrony/chrony.conf
dpkg -s chrony &>/dev/null || { ${COLOR}"安装chrony包请稍等..."${END};apt install -y chrony &> /dev/null; }
if [ ${OS_ID} == "Ubuntu" ];then
sed -i -e '/^pool.*/d' -e '/^# See http:.*/a\server '${NTP_SERVER1}' iburst\nserver '${NTP_SERVER2}' iburst\nserver '${NTP_SERVER3}' iburst' /etc/chrony/chrony.conf
else
sed -i -e '/^pool.*/d' -e '/^# Use Debian.*/a\server '${NTP_SERVER1}' iburst\nserver '${NTP_SERVER2}' iburst\nserver '${NTP_SERVER3}' iburst' /etc/chrony/chrony.conf
fi
echo "allow 0.0.0.0/0" >> /etc/chrony/chrony.conf
echo "local stratum 10" >> /etc/chrony/chrony.conf
systemctl restart chronyd && systemctl enable --now chronyd &> /dev/null
systemctl is-active chronyd &> /dev/null || { ${COLOR}"chrony 启动失败,退出!"${END} ; exit; }
${COLOR}"chrony安装完成"${END}
fi
systemctl restart chronyd && systemctl enable --now chronyd &> /dev/null
systemctl is-active chronyd &> /dev/null || { ${COLOR}"chrony 启动失败,退出!"${END} ; exit; }
${COLOR}"chrony安装完成"${END}
}
main(){