我们以centos6为范例演示

1、[root@Centos6 ~]# cd /etc/yum.repos.d/
[root@Centos6 yum.repos.d]# ls

CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo CentOS-Debuginfo.repo CentOS-Media.repo 先罗列出相关文件

2、[root@Centos6 yum.repos.d]# vim CentOS-Base.repo
# 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.
#
#
[epel]
name=aliyun-epel
baseurl=https://mirrors.aliyun.com/epel/6/x86_64/
gpgcheck=0
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-6 

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://mirrors.aliyun.com/centos/6/os/x86_64/
gpgcheck=0
gpgkey=https://mirrors.aliyun.com/centos/6/os/x86_64/RPM-GPG-KEY-CentOS-6  

#released updates 
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=https://mirrors.aliyun.com/centos/6/updates/x86_64/
gpgcheck=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=https://mirrors.aliyun.com/centos/6/extras/x86_64/
gpgcheck=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=https://mirrors.aliyun.com/centos/6/centosplus/x86_64/
gpgcheck=0
enabled=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
baseurl=https://mirrors.aliyun.com/centos/6/contrib/x86_64/
gpgcheck=0
enabled=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

在https://opsx.alibaba.com/mirro中查询相关配置文件的路径

3、[root@Centos6 yum.repos.d]# yum clean all

Loaded plugins: fastestmirror, refresh-packagekit, security Cleaning repos: base centosplus contrib epel extras updates Cleaning up Everything Cleaning up list of fastest mirrors 清除一下yum缓存

4、[root@Centos6 yum.repos.d]# yum repolist

Loaded plugins: fastestmirror, refresh-packagekit, security Determining fastest mirrors base | 3.7 kB 00:00
base/primary_db | 4.7 MB 00:00
centosplus | 3.4 kB 00:00
centosplus/primary_db | 1.7 MB 00:00
contrib | 2.9 kB 00:00
contrib/primary_db | 1.2 kB 00:00
epel | 4.7 kB 00:00
epel/primary_db | 6.0 MB 00:00
extras | 3.4 kB 00:00
extras/primary_db | 27 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 3.0 MB 00:00
repo id repo name status base CentOS-6 - Base 6,713 centosplus CentOS-6 - Plus 50 contrib CentOS-6 - Contrib 0 epel aliyun-epel 12,517 extras CentOS-6 - Extras 35 updates CentOS-6 - Updates 311 repolist: 19,626

5、此时表明yum源列表已生成,yum源已配好

我们就可以下载自己需要的东西了,示例如下:

[root@Centos6 yum.repos.d]# yum -y install lrzsz
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package lrzsz.x86_64 0:0.12.20-27.1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================
 Package     Arch         Version                   Repository  Size
=====================================================================
Installing:
 lrzsz       x86_64       0.12.20-27.1.el6          base        71 k

Transaction Summary
=====================================================================
Install       1 Package(s)

Total download size: 71 k
Installed size: 159 k
Downloading Packages:
lrzsz-0.12.20-27.1.el6.x86_64.rpm             |  71 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : lrzsz-0.12.20-27.1.el6.x86_64                     1/1 
  Verifying  : lrzsz-0.12.20-27.1.el6.x86_64                     1/1 

Installed:
  lrzsz.x86_64 0:0.12.20-27.1.el6                                    

Complete!