解决yum没资源命令

大家使用YUM的时候可能会遇到无法通信原始YUM资源,使用如下命令即可解决
curl http://s.80.re/Linux/centos-163.sh | sh

——————————————

以上centos-163.sh内容为如下:

——————————————

#! /bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
sed -i.bak ‘/^SELINUX=/cSELINUX=disabled’ /etc/sysconfig/selinux && sed -i.bak ‘/^SELINUX=/cSELINUX=disabled’ /etc/selinux/config && setenforce 0
#=================================================================#
# #
# 系统需求: CentOS 5,6,7 #
# Description: Centos 一键更新源到163源 #
# Author: Keen <189717888> #
# #
#=================================================================#
clear
echo
echo
#Current folder
cur_dir=`pwd`
# 判断用户
function rootness(){
if [[ $EUID -ne 0 ]]; then
echo “错误:脚本必须以root账户运行!” 1>&2
exit 1
fi
}
# Check OS
function checkos(){
if [ -f /etc/redhat-release ];then
OS=’CentOS’
else
echo “不支持此系统!”
exit 1
fi
}
# Get version
function getversion(){
if [[ -s /etc/redhat-release ]];then
grep -oE “[0-9.]+” /etc/redhat-release
else
grep -oE “[0-9.]+” /etc/issue
fi
}
# CentOS version
function centosversion(){
local code=$1
local version=”`getversion`”
local main_ver=${version%%.*}
if [ $main_ver == $code ];then
return 0
else
return 1
fi
}

# 写入文件
function wright_config(){
echo “开始写入配置…”
#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
if centosversion 5; then
cat > /etc/yum.repos.d/CentOS-Base.repo<<-EOF
# CentOS-Base.repo
[base]
name=CentOS-$releasever – Base – s.80.re/iso/Linux/centos-5.8
baseurl=http://s.80.re/iso/Linux/centos-5.8/os/\$basearch/
gpgcheck=1
gpgkey=http://s.80.re/iso/Linux/centos-5.8/RPM-GPG-KEY-CentOS-5

#released updates
[updates]
name=CentOS-\$releasever – Updates – s.80.re/iso/Linux/centos-5.8
baseurl=http://s.80.re/iso/Linux/centos-5.8/updates/\$basearch/
gpgcheck=1
gpgkey=http://s.80.re/iso/Linux/centos-5.8/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful
[extras]
name=CentOS-$releasever – Extras – s.80.re/iso/Linux/centos-5.8
baseurl=http://s.80.re/iso/Linux/centos-5.8/extras/\$basearch/
gpgcheck=1
gpgkey=http://s.80.re/iso/Linux/centos-5.8/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-\$releasever – Plus – s.80.re/iso/Linux/centos-5.8
baseurl=http://s.80.re/iso/Linux/centos-5.8/centosplus/\$basearch/
gpgcheck=1
enabled=0
gpgkey=http://s.80.re/iso/Linux/centos-5.8/RPM-GPG-KEY-CentOS-5

#contrib – packages by Centos Users
[contrib]
name=CentOS-\$releasever – Contrib – s.80.re/iso/Linux/centos-5.8
baseurl=http://s.80.re/iso/Linux/centos-5.8/contrib/\$basearch/
gpgcheck=1
enabled=0
gpgkey=http://s.80.re/iso/Linux/centos-5.8/RPM-GPG-KEY-CentOS-5
EOF

elif centosversion 6; then
cat > /etc/yum.repos.d/CentOS-Base.repo<<-EOF
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-\$releasever – Base – 163.com
baseurl=http://mirrors.163.com/centos/\$releasever/os/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-\$releasever – Updates – 163.com
baseurl=http://mirrors.163.com/centos/\$releasever/updates/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-\$releasever – Extras – 163.com
baseurl=http://mirrors.163.com/centos/\$releasever/extras/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-\$releasever – Plus – 163.com
baseurl=http://mirrors.163.com/centos/\$releasever/centosplus/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#contrib – packages by Centos Users
[contrib]
name=CentOS-\$releasever – Contrib – 163.com
baseurl=http://mirrors.163.com/centos/\$releasever/contrib/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
EOF
elif centosversion 7; then
cat > /etc/yum.repos.d/CentOS-Base.repo<<-EOF
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-\$releasever – Base – 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=os
baseurl=http://mirrors.163.com/centos/\$releasever/os/\$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-\$releasever – Updates – 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/\$releasever/updates/\$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-\$releasever – Extras – 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/\$releasever/extras/\$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-\$releasever – Plus – 163.com
baseurl=http://mirrors.163.com/centos/\$releasever/centosplus/\$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
EOF
fi
echo “写入配置完成…”
}
# 更新缓存
function make_cache(){
echo “开始更新缓存…”
yum clean all
yum makecache
echo “更新缓存完毕!”
echo “UseDNS no” >> /etc/ssh/sshd_config
service sshd restart
rpm –import /etc/pki/rpm-gpg/RPM*
yum -y install wget screen vim lftp rsync telnet unzip epel-release net-tools
sed -e ‘s!^mirrorlist=!#mirrorlist=!g’ \
-e ‘s/metalink/#metalink/g’ \
-e ‘s!^#baseurl=!baseurl=!g’ \
-e ‘s!//download\.fedoraproject\.org/pub!//mirrors.ustc.edu.cn!g’ \
-e ‘s!http://mirrors\.ustc!https://mirrors.ustc!g’ \
-i /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo
mv /etc/yum.repos.d/epel-testing.repo /tmp
ulimit -n 65535
ulimit -u 65535
echo -e “* soft nofile 65535 \n* hard nofile 65535\n* soft nproc 65535\n* hard nproc 65535” >> /etc/security/limits.conf
date -s “$(wget -qO- -t1 -T2 http://time.wepcc.com/linux_time.php)”
echo 0 > /proc/sys/net/ipv4/tcp_window_scaling
cat <<EOF>>/etc/modprobe.d/dist.conf
alias net-pf-10 off
alias ipv6 off
EOF
echo
echo
echo “系统源成功修改为163源”
echo “当前系统时间为:”
date
}
#判断主机名是否修改
function edit_hostname(){
hostname=`hostname`
yum install -y python-pip > /dev/null 2>&1
mkdir /root/.pip
echo -e “[global]\nindex-url = https://pypi.mirrors.ustc.edu.cn/simple/” > /root/.pip/pip.conf
if [[ $hostname == ‘localhost.localdomain’ ]];then
ip=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk ‘{print $2}’|tr -d “addr:” | head -n 1`
hostname=H${ip//\./-};
sed -i “s/localhost.localdomain/${hostname}/” /etc/sysconfig/network
echo “127.0.0.1 ${hostname}” >> /etc/hosts
hostname ${hostname}
echo ${hostname} > /etc/hostname

echo “主机名修改成功”
else
echo “主机名无需修改”
fi
}
#改成北京时间
function check_datetime(){
#service ntpd start
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#ntpdate stdtime.sinica.edu.tw
}
# Install cleanup
function install_cleanup(){
cd $cur_dir
rm -f centos-163.sh
}

# Install
function install_aliyun(){
checkos
rootness
wright_config
make_cache
check_datetime
install_cleanup
edit_hostname
echo ‘ok’ > /root/ok.txt
}
# Initialization step
action=$1
[ -z $1 ] && action=install
case “$action” in
install)
install_aliyun
;;
uninstall)
uninstall_aliyun
;;
*)
echo “语法错误! [${action} ]”
echo “用法: `basename $0` {install|uninstall}”
;;
esac

评论0

当前加入VIP价格优惠中,加入VIP会员即可免费下载本站所有资源!点击加入VIP
没有账号? 注册  忘记密码?

社交账号快速登录