CentOS安裝后默認官方源,速度可能不是很快,這個時候就需要更改為國內的源了,
這里以 阿里源 為例,進行腳本展示

#!/bin/bash # by liuxg # 2019.05.15 # aliyun_repo.sh # 獲得當前 CentOS 系統發行版本號 # 第一個 awk 后邊必須換行, 目前未查到原因 releasetmp=`cat /etc/redhat-release | awk '{match($0,"release ") print substr($0,RSTART+RLENGTH)}' | awk -F '.' '{print $1}'` echo $releasetmp sleep 5 yum install wget -y # 備份原文件 應該添加檢測是否原來有備份文件, 有的話應該備份為別名文件 此處省略 cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-$releasetmp.repo if [[ $? -eq 0 ]];then echo -e "\033[32m# yum 源已成功更新為 aliyun_repo #\033[0m"; sleep 3; else echo -e "\033[31m# yum 源未成功更新為 aliyun_repo #\n3s 后退出...\033[0m"; exit; fi # 添加EPEL源 wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-$releasetmp.repo # 重建緩存 yum clean all yum makecache # 自動更新包列表,可選擇注釋該行 yum update -y;