yum无法正常使用的解决办法

简介:

方法一:

解决了什么问题:一键式更新yum源,省去了复杂的命令和步骤

注:所有执行的脚本都需要root身份来执行,执行方法:以root身执行命令:bash xxx.sh

功能:更新系统的yum源为163的yum源

适用系统版本:线上centos5/6系列,redhat5系列,兼容32位和64位


vim update_yum_source.sh


#!/bin/bash
#########################################
#Function:    update yum source
#Usage:       bash update_yum_source.sh
#Author:      Customer service department
#Company:     Alibaba Cloud Computing
#Version:     2.1
#########################################
check_os_release()
{
  while true
  do
  os_release=$(grep "Red Hat Enterprise Linux Server release" /etc/issue 2>/dev/null)
  os_release_2=$(grep "Red Hat Enterprise Linux Server release" /etc/redhat-release 2>/dev/null)
  if [ "$os_release" ] && [ "$os_release_2" ]
  then
    echo "$os_release"
    break
  fi
  os_release=$(grep "CentOS release" /etc/issue 2>/dev/null)
  os_release_2=$(grep "CentOS release" /etc/*release 2>/dev/null)
  if [ "$os_release" ] && [ "$os_release_2" ]
  then
    echo "$os_release"
    break
  fi
  break
  done
}


modify_rhel5_yum()
{
  rpm --import http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-5
  cd /etc/yum.repos.d/
  wget http://mirrors.163.com/.help/CentOS-Base-163.repo -O CentOS-Base-163.repo
  sed -i '/mirrorlist/d' CentOS-Base-163.repo
  sed -i 's/\$releasever/5/' CentOS-Base-163.repo
  yum clean metadata
  yum makecache
  cd ~
}


modify_rhel6_yum()
{
  rpm --import http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6
  cd /etc/yum.repos.d/
  wget http://mirrors.163.com/.help/CentOS-Base-163.repo -O CentOS-Base-163.repo
  sed -i '/mirrorlist/d' CentOS-Base-163.repo
  sed -i '/\[addons\]/,/^$/d' CentOS-Base-163.repo
  sed -i 's/\$releasever/6/' CentOS-Base-163.repo
  sed -i 's/RPM-GPG-KEY-CentOS-5/RPM-GPG-KEY-CentOS-6/' CentOS-Base-163.repo
  yum clean metadata
  yum makecache
  cd ~
}


##########start######################
#check lock file ,one time only let the script run one time 
LOCKfile=/tmp/.$(basename $0)
if [ -f "$LOCKfile" ]
then
  echo -e "\033[1;40;31mThe script is already exist,please next time to run this script.\n\033[0m"
  exit
else
  echo -e "\033[40;32mStep 1.No lock file,begin to create lock file and continue.\n\033[40;37m"
  touch $LOCKfile
fi


#check user
if [ $(id -u) != "0" ]
then
  echo -e "\033[1;40;31mError: You must be root to run this script, please use root to install this script.\n\033[0m"
  rm -rf $LOCKfile
  exit 1
fi


os_type=$(check_os_release)
if [ "X$os_type" == "X" ]
then
  echo -e "\033[1;40;31mOS type is not RedHat or CentOS,So this script is not executede.\n\033[0m"
  rm -rf $LOCKfile
  exit 0
else
  echo -e "\033[40;32mThis OS is $os_type.\033[40;37m"
  echo "$os_type" |grep 5 >/dev/null
  if [ $? -eq 0 ]
  then
    modify_rhel5_yum
    rm -rf $LOCKfile
    exit 0
  fi
  echo "$os_type"|grep 6 >/dev/null
  if [ $? -eq 0 ]
  then
    modify_rhel6_yum
    rm -rf $LOCKfile
    exit 0
  fi
fi
rm -rf $LOCKfile


执行方法:以root身执行命令,bash update_yum_source.sh




附 加:

Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again

在网上查了查,解决办法都是编辑/etc/yum.repos.d/epel.repo,把基础的恢复,镜像的地址注释掉

#baseurl
mirrorlist

改成

baseurl
#mirrorlist

##本文内容摘自:

http://blog.chinaunix.net/uid-26642180-id-3486741.html



方法二:


1. cd /etc/yum.repos.d

2. mv CentOS-Base.repo CentOS-Base.repo.backup

3. wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

4. mv CentOS6-Base-163.repo CentOS-Base.repo

5.yum clean all

本文转自奔跑在路上博客51CTO博客,原文链接http://blog.51cto.com/qiangsh/1565082如需转载请自行联系原作者


qianghong000

相关文章
|
11月前
使用本地YUM源安装服务报错以及解决办法
使用本地YUM源安装服务报错以及解决办法
|
缓存 Linux 虚拟化
linux下yum安装时出现Loaded plugins: fastestmirror解决办法
linux下yum安装时出现Loaded plugins: fastestmirror解决办法
732 0
|
Linux Python
Aliyun Linux 2 ,误删自带python2,yum的解决办法
在未安装编译相关工具的情况下误删python2、yum的解决办法。
944 0
Aliyun Linux 2 ,误删自带python2,yum的解决办法
|
应用服务中间件 Linux nginx
CentOS7 yum使用阿里源安装tomcat无欢迎页问题解决办法
解决过程 在阿里云服务器CentOS7上通过命令安装上了tomcat: yum -y install tomcat 接着执行命令,启动tomcat服务: systemctl start tomcat.service 但是当我在浏览器中输入ip:port后却没有反应,然后报404错误。
2030 0