系统版本:
[root@centos67d1 ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)
[root@centos67d1 ~]# uname -r
2.6.32-573.el6.x86_64
[root@centos71d1 ~]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
[root@centos71d1 ~]# uname -r
3.10.0-229.el7.x86_64
应用yum源的3种方式:
更换使用阿里云yum源
[root@centos71d1 ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
#备份原repo文件
[root@centos71d1 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo \
http://mirrors.aliyun.com/repo/Centos-7.repo
#下载阿里云的repo文件
[root@centos71d1 ~]# yum clean all
[root@centos71d1 ~]# yum makecache
#清除本地缓存,并重建缓存
[root@centos71d1 ~]# yum repolist all
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com enabled: 9,911
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com enabled: 369
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com enabled: 1,041
....
使用CentOS安装光盘作为本地yum源
[root@centos71d1 ~]# mkdir /media/cdrom
[root@centos71d1 ~]# mount -r /dev/cdrom /media/cdrom
#挂载CentOS安装光盘
[root@centos71d1 ~]# cp -a /etc/yum.repos.d /tmp/yum.repo.d.bak
#备份/etc/yum.repos.d目录
[root@centos71d1 ~]# rm -f /etc/yum.repos.d/*
[root@centos71d1 ~]# vim /etc/yum.repos.d/local.repo
[base]
name=CentOS 7 Release 7.1.1503
baseurl=file:///media/cdrom
enable=1
gpgcheck=0
#创建repo文件,添加以上内容
[root@centos71d1 ~]# yum clean all
[root@centos71d1 ~]# yum makecache
#重新生成缓存
[root@centos71d1 ~]# yum repolist
[root@centos71d1 ~]# yum list all
#显示所有程序包
[root@centos71d1 ~]# yum grouplist
#显示包组信息
创建本地yum repository
[root@centos67d1 ~]# mount -r /dev/cdrom /media/cdrom
[root@centos67d1 ~]# mkdir -p /yum/repo
[root@centos67d1 ~]# cp /media/cdrom/Packages/r* /yum/repo
#拷贝一些rpm包来做实验
[root@centos67d1 ~]# yum install -y createrepo
#使用createrepo命令创建yum源,先确保系统中已安装createrepo
[root@centos67d1 ~]# createrepo /yum/repo
[root@centos67d1 ~]# ll /yum/repo/repodata
#可以看到repodata目录被自动创建,目录下有几个自动生成的文件
[root@centos67d1 ~]# vim /etc/yum.repos.d/centos-local.repo
[YumRepoTest]
name=Yum Repo Test
baseurl=file:///yum/repo
gpgcheck=0
#在/etc/yum.repos.d目录下添加并配置repo文件
[root@centos67d1 ~]# yum repolist
YumRepoTest | 2.9 kB 00:00 ...
YumRepoTest/primary_db | 59 kB 00:00 ...
repo id repo name status
YumRepoTest Yum Repo Test 75