修改Redhat 源,阿里巴巴源镜像

  进入源路径,备份下

cd /etc/yum.repos.d/
mv rhel-debuginfo.repo rhel-debuginfo.repo_bak

  阿里巴巴源镜像地址 http://mirrors.aliyun.com/

   下载相应系统的help中的系统版本。 

   因我使用的redhat5,所以命令如下:

wget -O http://mirrors.aliyun.com/repo/Centos-5.repo 

 打开其文件,可以看到 $releasever 和  $basearch

   因我使用的是Centos5 x86_64  所以替换如下:

sed  's/$releasevr/5/g' /etc/yum.repos.d/CentOS-Base.repo
sed  's/$basearch/x86_64/g' /etc/yum.repos.d/CentOS-Base.repo

 32位的系统替换成

sed  's/$releasever/5/g' /etc/yum.repos.d/CentOS-Base.repo
sed  's/$basearch/i386/g' /etc/yum.repos.d/CentOS-Base.repo

 最后执行:

yum clean all && yum makecache

 这样就ok了!

   做个一键脚本:

  

#!/bin/bash

old_file="/etc/yum.repos.d/rhel-debuginfo.repo"
new_file="/etc/yum.repos.d/Centos-5.repo"

cd /etc/yum.repos.d/

if [ -f "$old_file" ]; then 
        mv /etc/yum.repos.d/rhel-debuginfo.repo /etc/yum.repos.d/rhel-debuginfo.repo_bak
fi

if [ -f "$new_file" ]; then 
        rm -rf /etc/yum.repos.d/Centos-5.repo
fi

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

sed -i "s/\$releasever/5/g"      /etc/yum.repos.d/CentOS-Base.repo
sed -i "s/\$basearch/x86_64/g"   /etc/yum.repos.d/CentOS-Base.repo

yum clean all  && yum makecache
echo "================yum update ok========="

  

posted @ 2015-10-22 00:49  EvilBaby  阅读(859)  评论(0)    收藏  举报