centos各版本更换阿里源的脚本
发布时间:2024-06-13 09:42
阅读量:1046
携手合作伙伴,实现业务上的双向合作共赢
我们为您提供全方位的支持与服务,确保您在使用我们的云服务时无忧无虑。
10+年商誉沉淀,深耕中国香港及海外高端资源
本文介绍一个centos各版本更换阿里源的脚本,以作参考
#!/bin/bash
# Detect CentOS version
if [ -f /etc/os-release ]; then
. /etc/os-release
OS_NAME=$ID
OS_VERSION_ID=$VERSION_ID
elif [ -f /etc/centos-release ]; then
OS_NAME="centos"
OS_VERSION_ID=$(rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release))
else
echo "不支持的系统类型."
exit 1
fi
# Function to backup and replace YUM repo files
replace_yum_repo() {
local url=$1
local dest_dir="/etc/yum.repos.d"
# Backup existing repo files
mkdir -p "${dest_dir}/backup"
mv ${dest_dir}/*.repo ${dest_dir}/backup/
# Download new repo file
curl -o ${dest_dir}/CentOS-Base.repo ${url}
}
# Replace YUM repo based on CentOS version
case $OS_VERSION_ID in
6)
echo "Detected CentOS 6"
replace_yum_repo "http://www.landui.com/repo/Centos-6.repo"
;;
7)
echo "Detected CentOS 7"
replace_yum_repo "http://www.landui.com/repo/Centos-7.repo"
;;
8)
echo "Detected CentOS 8"
replace_yum_repo "http://www.landui.com/repo/Centos-8.repo"
;;
*)
echo "不支持的系统版本: $OS_VERSION_ID"
exit 1
;;
esac
# Clean YUM cache
yum clean all
yum makecache
echo "yum已成功更换为阿里源!"
# End of script
服务热线:
18251482443电子邮箱:
202256327@qq.com商务QQ:
202256327公司地址:
江苏省连云港市东海县红星美凯龙S5-A133
客服微信
客服微信