CentOS yum配置
一、yum 安装
CentOS 默认已经安装了yum,不需要另外安装,这里为了实验目的,先将yum 卸载再重新安装。
1、查看系统默认安装的yum
# rpm -qa|grep yum
2、卸载yum
# rpm -e yum-fastestmirror-1.1.16-14.el5.centos.1 yum-metadata-parser-1.1.2-3.el5.centos yum-3.2.22-33.el5.centos
3、重新安装yum
这里可以通过wget 从网上下载相关包安装,也可以挂载系统安装光盘进行安装,这里选择挂载系统安装光盘进行安装。
# mount /dev/cdrom /mnt/cdrom/
# rpm -ivh yum-3.2.22-33.el5.centos.noarch.rpm yum-fastestmirror-1.1.16-14.el5.centos.1.noarch.rpm yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm
# yum -v
yum 的基础安装包包括:
- yum //RPM installer/updater
- yum-fastestmirror //Yum plugin which chooses fastest repository from a mirrorlist
- yum-metadata-parser //A fast metadata parser for yum
其他安装包根据自己需要安装。
二、yum 配置
yum 的配置文件分为两部分:main 和repository
- main 部分定义了全局配置选项,整个yum 配置文件应该只有一个main。常位于/etc/yum.conf 中。
- repository 部分定义了每个源/服务器的具体配置,可以有一到多个。常位于/etc/yum.repo.d 目录下的各文件中。
yum.conf 文件一般位于/etc目录下,一般其中只包含main部分的配置选项。
# cat /etc/yum.conf
配置国内yum源
系统默认的yum 源速度往往不尽人意,为了达到快速安装的目的,在这里修改yum源为国内源。
上海交通大学yum源: http://ftp.sjtu.edu.cn/centos
可以点击这个网址,然后找到你要安装的包:
这里寻找你要的包,
1,选centos
2,选择系统版本7.3.1611/
3,选择包类型(系统) os/
4,系统位数 x86_64/
5,包 Packages/
6,ctrl+f 搜索yum
7、yum的安装需要:
yum-plugin-fastestmirror
yum-updateonboot
yum-utils
yum-metadata-parser
yum-3.4.3-150.el7
如需要安装yum包,可以用命令: (centos 7 所有版本的安装包都在centos/7/os 目录下面,而不是在 centos/7.XXX/下面)
[root@localhost]#wget http://ftp.sjtu.edu.cn/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-40.el7.noarch.rpm
[root@localhost]#wget http://ftp.sjtu.edu.cn/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-40.el7.noarch.rpm
[root@localhost]#wget http://ftp.sjtu.edu.cn/centos/7/os/x86_64/Packages/yum-utils-1.1.31-40.el7.noarch.rpm
[root@localhost]#wget http://ftp.sjtu.edu.cn/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
[root@localhost]#wget http://ftp.sjtu.edu.cn/centos/7/os/x86_64/Packages/yum-3.4.3-150.el7.centos.noarch.rpm
配置yum源
a. 修改/etc/yum.repos.d/CentOS-Base.repo为
#released updates [updates] name=CentOS-$releasever - Updates #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/contrib/$basearch/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
关于变量
- $releasever:代表发行版的版本,从[main]部分的distroverpkg获取,如果没有,则根据redhat-release包进行判断。
- $arch:cpu体系,如i686,athlon等
- $basearch:cpu的基本体系组,如i686和athlon同属i386,alpha和alphaev6同属alpha。
清理之前源,保证只有一个配置文件
[root@localhost]# yum clean all
[root@localhost]# ls /etc/yum.repos.d/
CentOS-Base.repo
安装你需要的软件测试是否正常使用
其他国内yum源列表如下:
1. 企业贡献:
搜狐开源镜像站:http://mirrors.sohu.com/
网易开源镜像站:http://mirrors.163.com/
2. 大学教学:
北京理工大学:
http://mirror.bit.edu.cn (IPv4 only)
http://mirror.bit6.edu.cn (IPv6 only)
北京交通大学:
http://mirror.bjtu.edu.cn (IPv4 only)
http://mirror6.bjtu.edu.cn (IPv6 only)
http://debian.bjtu.edu.cn (IPv4+IPv6)
兰州大学:http://mirror.lzu.edu.cn/
厦门大学:http://mirrors.xmu.edu.cn/
清华大学:
http://mirrors.tuna.tsinghua.edu.cn/ (IPv4+IPv6)
http://mirrors.6.tuna.tsinghua.edu.cn/ (IPv6 only)
http://mirrors.4.tuna.tsinghua.edu.cn/ (IPv4 only)
天津大学:http://mirror.tju.edu.cn/
中国科学技术大学:
http://mirrors.ustc.edu.cn/ (IPv4+IPv6)
http://mirrors4.ustc.edu.cn/
http://mirrors6.ustc.edu.cn/
东北大学:
http://mirror.neu.edu.cn/ (IPv4 only)
http://mirror.neu6.edu.cn/ (IPv6 only)
电子科技大学:http://ubuntu.uestc.edu.cn/
备注:
我这里在Centos7.3.1611上配置yum源,测试可以使用的配置:
# 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-centos/7 - Base #mirrorlist=http://mirrorlist.centos.org/?release=centos/7&arch=$basearch&repo=os baseurl=http://ftp.sjtu.edu.cn/centos/7/os/$basearch/ gpgcheck=1 gpgkey=http://ftp.sjtu.edu.cn/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-centos/7 - Updates #mirrorlist=http://mirrorlist.centos.org/?release=centos/7&arch=$basearch&repo=updates baseurl=http://ftp.sjtu.edu.cn/centos/7/updates/$basearch/ gpgcheck=1 gpgkey=http://ftp.sjtu.edu.cn/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-centos/7 - Extras #mirrorlist=http://mirrorlist.centos.org/?release=centos/7&arch=$basearch&repo=extras baseurl=http://ftp.sjtu.edu.cn/centos/7/extras/$basearch/ gpgcheck=1 gpgkey=http://ftp.sjtu.edu.cn/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-centos/7 - Plus #mirrorlist=http://mirrorlist.centos.org/?release=centos/7&arch=$basearch&repo=centosplus baseurl=http://ftp.sjtu.edu.cn/centos/7/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://ftp.sjtu.edu.cn/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7 #contrib - packages by Centos Users [contrib] name=CentOS-centos/7 - Contrib #mirrorlist=http://mirrorlist.centos.org/?release=centos/7&arch=$basearch&repo=contrib baseurl=http://ftp.sjtu.edu.cn/centos/7/contrib/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://ftp.sjtu.edu.cn/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7