目录
适用于刚创建的centos8新环境,需要配置yum阿里仓库 ,脚本内容复制黏贴即可用
老环境需要配置yum阿里仓库, 请慎用
- #!/bin/bash
-
- #检测函数,检测命令是否成功执行
- function check()
- if [ $? == 0 ]; then
- echo -e "\033[32m success \033[0m"
- else
- echo -e "\033[31m fail \033[0m"
- exit 0
- fi
- echo "正在部署本地阿里云yum仓库"
- #进入/etc/yum.repos.d目录并创建文件CentOS-AppStream.repo CentOS-BaseOS.repo CentOS-Extras.repo
- cd /etc/yum.repos.d && rm -rf * && touch CentOS-AppStream.repo CentOS-BaseOS.repo CentOS-Extras.repo
-
- #将字符串写入CentOS-AppStream.repo文件中
- (
- cat << EOF
- [aliyun-AppStream]
- name=CentOS-\$releasever- AppStream
- baseurl=https://mirrors.aliyun.com/centos/\$releasever/AppStream/\$basearch/os/
- gpgcheck=1
- enabled=1
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- EOF
- ) > /etc/yum.repos.d/CentOS-AppStream.repo
- #将字符串写入CentOS-BaseOS.repo文件中
- (
- cat << EOF
- [aliyun-BaseOS]
- name=CentOS-\$releasever\- Base
- baseurl=https://mirrors.aliyun.com/centos/\$releasever/BaseOS/\$basearch/os/
- gpgcheck=1
- enabled=1
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- EOF
- ) > /etc/yum.repos.d/CentOS-BaseOS.repo
- #将字符串写入CentOS-Extras.repo文件中
- (
- cat << EOF
- [aliyun-extras]
- name=CentOS-\$releasever- Extras
- baseurl=https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/os/
- gpgcheck=1
- enabled=1
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
- EOF
- ) > /etc/yum.repos.d/CentOS-Extras.repo
- #下载epel-release 、清理缓存、建立缓存
- dnf -y install epel-release &> /dev/null && dnf clean all &> /dev/null && dnf makecache &> /dev/null && dnf repolist &> /dev/null
-
- echo -e "\033[32m 本地阿里云仓库部署成功 \033[0m"
备注:check函数是测试的时候需要的,所以我也留了
新环境未使用脚本前,下载http报错
运行脚本
再次下载httpd验证是否配置成功
成功!!!
手动配置阿里yum仓库连接 :cenots8配置阿里yum仓库_东鹏特饮的博客-CSDN博客