我这里使用的centos7操作系统。 下载地址是:https://www.centos.org/download/
yum仓库的创建可以参考: http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_037_yumrepo.html
yum源配置大致流程如下:
1 添加光盘
将安装光盘(我用的是CentOS-7-x86_64-Everything-1511.iso), 添加到vmware的光盘项中去。如下图
注意 :选择了安装包后,确保上面的那个设备状态的2个复选框是勾选中的。
2 挂载光盘
执行下面命令
[root@localhost ~]# mkdir /mnt/cdrom #创建一个目录 [root@localhost ~]# mount -r /dev/cdrom /mnt/cdrom #挂载光盘到指定的目录 [root@localhost ~]# tail -n 1 /etc/mtab >>/etc/fstab #挂载信息写入到配置文件中去,开机自动挂载
3 添加repo文件
[root@localhost /] cd /etc/yum.repos.d/ #进入yum配置目录 [root@localhost yum.repos.d]# ls #查看目录下已有的配置项 CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo [root@localhost yum.repos.d]# mkdir backup #创建一个备份目录 [root@localhost yum.repos.d]# mv *.* backup #当前目录的文件移动到备份目录中去 [root@localhost yum.repos.d]# ls #查看当前目录 backup [root@localhost yum.repos.d]# cp backup/CentOS-Base.repo localcdrom.repo #赋值一个repo文件到yum的配置目录中 [root@localhost yum.repos.d]# ls backup localcdrom.repo [root@localhost yum.repos.d]# vi localcdrom.repo #编辑这个repo文件 [root@localhost yum.repos.d]# cat localcdrom.repo #检查repo的配置 [localcdrom] name=localcdrom baseurl=file:///mnt/cdrom/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
这里说一下repo文件的选项意义:
- [localcdrom] : 这个是repo的识别号。必须是唯一的。不能有重复的
- name:repo的名字: 中间可以有空格
- baseurl: 这个是yum源的地址, ftp:// 是ftp协议, http://是http协议的, ftp://是ftp协议的, 这里配置的file:///mnt/cdrom/就是/mnt/cdrom这个目录就是本地yum的配置地址。确保这个目录有repodata目录。
- gpgcheck=1 :进行包检测
- gpgkey: 包检测秘钥路径。支持http,ftp,file三种协议的
- cost: 代价(默认是2000) 越小优先级越高。
4 清空yum和重新生成缓存
[root@localhost yum.repos.d]# yum clean all #清空yum 缓存 Loaded plugins: fastestmirror, langpacks Cleaning repos: localcdrom Cleaning up everything Cleaning up list of fastest mirrors [root@localhost yum.repos.d]# yum makecache #生成yum缓存 Loaded plugins: fastestmirror, langpacks localcdrom | 3.6 kB 00:00:00 (1/4): localcdrom/group_gz | 155 kB 00:00:00 (2/4): localcdrom/filelists_db | 6.2 MB 00:00:00 (3/4): localcdrom/primary_db | 5.3 MB 00:00:00 (4/4): localcdrom/other_db | 2.3 MB 00:00:00 Determining fastest mirrors Metadata Cache Created
5 配置好了。 那就测试一下吧。
[root@localhost yum.repos.d]# yum install lftp #这里测试一个ftp工具 Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package lftp.x86_64 0:4.4.8-7.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================= Package Arch Version Repository Size ============================================================================================================================= Installing: lftp x86_64 4.4.8-7.el7 localcdrom 750 k Transaction Summary ============================================================================================================================= Install 1 Package Total download size: 750 k Installed size: 2.4 M Is this ok [y/d/N]: y #输入y确认 Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : lftp-4.4.8-7.el7.x86_64 1/1 Verifying : lftp-4.4.8-7.el7.x86_64 1/1 Installed: lftp.x86_64 0:4.4.8-7.el7 Complete!
6 提供一些国内一些比较出名的一些yum源地址吧
阿里:http://mirrors.aliyun.com/
网易:http://mirrors.163.com/
搜狐:http://mirrors.sohu.com/
注意: aliyun上面是直接提供了repo文件下载的。我们可以直接下载ali官方提供的repo文件。 不用我们自己编写的,这里我截了两张aliyun的图。
7 提供我本地的一个配置吧
/etc/yum.repos.d/cdrom.repo
[cdrom] name=cdrom baseurl=file:///mnt/cdrom gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
8 重要环境变量
- $releasever : 红帽的发布版本,如果是centos6的系统,这个变量就是6。
- $basearch:系统架构,等价于uname -m,这个值x86_64,i686等这些数值。
- $uuid:机器的唯一数值,这个参数一般不用的。
- $YUM0 - $YUM9:这个是自定义的环境变量。
注意: 从3.2.28开始,/etc/yum/vars目录下的的任何文件都将变成一个以文件名命名的变量,变量值为文件的内容,如果设置了,会覆盖上面的设置的。如/etc/yum/vars/system的内容为abc,那么system变量的值就是abc。
9 官方的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. # # [base] name=CentOS-$releasever - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
这个repo样例,主要有base,updates,extras,centosplus,contrib几个片段, 每个片段都很基本,baseurl写了2个,使用了$releasever,$basearch这些内置变量。
10 epel源安装
EPEL的全称叫Extra Packages for Enterprise Linux 。EPEL是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。装上了 EPEL之后,就相当于添加了一个第三方源。