Redhat多版本通用的yum配置

这是我整理的Redhat多版本通用的yum配置, 复制以下全文并粘贴到Shell中执行即可, 相当方便大笑


#1.删除RHEL插件

rpm -q yum-rhn-plugin >/dev/null && rpm -e --nodeps yum-rhn-plugin


#2.编辑新配置文件
cat > /etc/yum.conf.new << EOF
[main]
cachedir=/var/cache/yum/\$basearch/\$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
#metadata_expire=1800


[base]
name=CentOS - Base
mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-\$releasever


[updates]
name=CentOS - Updates
mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-\$releasever


[extras]
name=CentOS - Extras
mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-\$releasever


[centosplus]
name=CentOS - Plus
mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=centosplus
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-\$releasever
enabled=0


[contrib]
name=CentOS - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=contrib
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-\$releasever
enabled=0


EOF


#3.替换配置文件
/bin/mv /etc/yum.conf /etc/yum.conf.$(date +%s)
/bin/mv /etc/yum.conf.new /etc/yum.conf
test -e /etc/yum.repos.d && /bin/mv /etc/yum.repos.d /etc/yum.repos.d.$(date +%s)


#4.写入大版本号
test ! -e /etc/yum/vars && mkdir -p /etc/yum/vars

lsb_release -r | awk -F "[ \t.]*" '{print $2}' > /etc/yum/vars/releasever

#如果没有lsb_release命令, 那么手工写入版本号也可以. 比如Redhat6.4, 需要这么做: echo 6 > /etc/yum/vars/releasever

你可能感兴趣的:(redhat,yum)