- 工信部备案号 滇ICP备05000110号-1
- 滇公安备案 滇53010302000111
- 增值电信业务经营许可证 B1.B2-20181647、滇B1.B2-20190004
- 云南互联网协会理事单位
- 安全联盟认证网站身份V标记
- 域名注册服务机构许可:滇D3-20230001
- 代理域名注册服务机构:新网数码
centos各版本更换阿里源的脚本
蓝队云小课堂:
本文介绍一个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
更多小知识,可联系蓝队云一起探讨。
售前咨询
售后咨询
备案咨询
二维码
TOP