1.由于centos自带的yum源在国内使用时有时候速度会很慢,导致yum在线安装速度缓慢。这时候就需要yum源为国内的一些镜像站点。
2.首先访问阿里云镜像站点:http://mirrors.aliyun.com
3.选择对应的linux发行版(此次使用CentOS Linux release 7.4.1708进行测试)
4.进入7.6.1810版本,此次准备创建4个repo
1)os/:即发行版光盘上附带的所有基础rpm包
2)updates/ :所有更新的rpm包
3)extras/ :附带的一些额外包
4)centosplus/ :额外增添的一些包
5.找到repodata所在目录并记录其路径:
6.repo的配置文件在/etc/yum.repos.d/*repo,制作名称为CentOS-Base.repo;并将之前的CentOS-Base.repo更改为CentOS-Base.repo.apk
1)开始编辑CentOS-Base.repo文件
[aliyun] 仓库ID
name=this is os repo 仓库介绍
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/ repo链接,$releasever为版本号,$basearch为基础架构
enabled=1 开启仓库
gpgcheck=1 检查其rpm包的合法性及完整性
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 秘钥地址
7.依据上面步骤添加剩余三个仓库,并且将网易镜像链接也添加进来做防范措施.。
[aliyun]
name=this is os repo
failovermethod=priority 出错防范措施,为顺序执行
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/
https://mirrors.163.com/centos/$releasever/os/$basearch
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#https://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
[updates]
name=this is updates repo
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
https://mirrors.163.com/centos/$releasever/updates/$basearch
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#https://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
[centosplus]
name=this is centosplus repo
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
https://mirrors.163.com/centos/$releasever/centosplus/$basearch
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#https://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
[extras]
name=this is extras repo
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
https://mirrors.163.com/centos/$releasever/extras/$basearch
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#https://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
~
"/etc/yum.repos.d/CentOS-Base.repo" 39L, 1319C 5,2-9 全部
8.编辑完CentOS-Base.repo文件后,使用yum makecache
创建缓存,使用yum repolist
查看可用仓库,使用yum list
可列出所有rpm包。
1)制作缓存
[root@yuki yum.repos.d]# yum makecache
已加载插件:fastestmirror, langpacks
aliyun | 3.6 kB 00:00:00
centosplus | 3.4 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/16): aliyun/7/x86_64/group_gz | 166 kB 00:00:25
(2/16): aliyun/7/x86_64/filelists_db | 7.1 MB 00:00:26
(3/16): aliyun/7/x86_64/primary_db | 6.0 MB 00:00:01
(4/16): aliyun/7/x86_64/other_db | 2.6 MB 00:00:00
(5/16): centosplus/7/x86_64/prestodelta | 24 kB 00:00:25
(6/16): centosplus/7/x86_64/primary_db | 2.0 MB 00:00:00
(7/16): centosplus/7/x86_64/other_db | 36 kB 00:00:00
(8/16): centosplus/7/x86_64/filelists_db | 926 kB 00:00:26
(9/16): extras/7/x86_64/prestodelta | 62 kB 00:00:25
(10/16): extras/7/x86_64/filelists_db | 243 kB 00:00:25
(11/16): extras/7/x86_64/primary_db | 201 kB 00:00:00
(12/16): extras/7/x86_64/other_db | 126 kB 00:00:00
(13/16): updates/7/x86_64/prestodelta | 623 kB 00:00:25
(14/16): updates/7/x86_64/filelists_db | 3.4 MB 00:00:26
(15/16): updates/7/x86_64/other_db | 563 kB 00:00:00
(16/16): updates/7/x86_64/primary_db | 4.2 MB 00:00:01
Determining fastest mirrors
* aliyun: mirrors.aliyun.com
* centosplus: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
元数据缓存已建立
2)查看可用仓库:
[root@yuki yum.repos.d]# yum repolist
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* aliyun: mirrors.aliyun.com
* centosplus: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
源标识 源名称 状态
aliyun/7/x86_64 this is os repo 10,019
centosplus/7/x86_64 this is centosplus repo 59
extras/7/x86_64 this is extras repo 413
updates/7/x86_64 this is updates repo 1,840
repolist: 12,331
3)列出可使用的rpm包,可搭配通配符使用
[root@yuki yum.repos.d]# yum list | grep "httpd"
httpd.x86_64 2.4.6-89.el7.centos @updates
httpd-tools.x86_64 2.4.6-89.el7.centos @updates
httpd-devel.x86_64 2.4.6-89.el7.centos updates
httpd-manual.noarch 2.4.6-89.el7.centos updates
keycloak-httpd-client-install.noarch 0.6-3.el7 aliyun
libmicrohttpd.i686 0.9.33-2.el7 aliyun
libmicrohttpd.x86_64 0.9.33-2.el7 aliyun
libmicrohttpd-devel.i686 0.9.33-2.el7 aliyun
libmicrohttpd-devel.x86_64 0.9.33-2.el7 aliyun
libmicrohttpd-doc.noarch 0.9.33-2.el7 aliyun
python2-keycloak-httpd-client-install.noarch
ps:配置repo仓库时,baseurl链接中$releasever变量若无法替换成相应的主版本号,需要查询rpm -qi centos-release,是否安装此程序包,若未安装则无法进行相应替换。$basearch是由arch命令查询。
1.挂载光盘至指定目录:
[root@kasumi ~]# mount -r -t iso9660 /dev/sr0 /media/
[root@kasumi ~]# ll /media/
total 1586
-rw-rw-r--. 3 root root 14 Sep 5 2017 CentOS_BuildTag
drwxr-xr-x. 3 root root 2048 Sep 5 2017 EFI
-rw-rw-r--. 3 root root 227 Aug 30 2017 EULA
-rw-rw-r--. 3 root root 18009 Dec 10 2015 GPL
drwxr-xr-x. 3 root root 2048 Sep 6 2017 images
drwxr-xr-x. 2 root root 2048 Sep 5 2017 isolinux
drwxr-xr-x. 2 root root 2048 Sep 5 2017 LiveOS
drwxrwxr-x. 2 root root 1585152 Sep 6 2017 Packages
drwxrwxr-x. 2 root root 4096 Sep 6 2017 repodata
-rw-rw-r--. 3 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 3 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root 2883 Sep 6 2017 TRANS.TBL
2.创建配置文件
1 [testrepo] repo的ID
2 name=Centos7 repotest repo名称
3 baseurl=file:///media/ repo路径
4 enabled=1 启用repo
5 gpgcheck=1 检查其合法性,完整性
6 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 秘钥指向路径
3.查看可使用repo
[root@kasumi ~]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id repo name status
testrepo 即为配置好的本地repo Centos7 repotest 9,591
repolist: 9,591
1.首先需要查看本地是否安装了createrepo程序包,用于制作repodata(制作repo元数据)
[root@kasumi repo]# rpm -q createrepo
未安装软件包 createrepo
[root@kasumi repo]# yum install createrepo 使用光盘制作的yum源安装createrepo
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 createrepo.noarch.0.0.9.9-28.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
============================================================================================================
Package 架构 版本 源 大小
============================================================================================================
正在安装:
createrepo noarch 0.9.9-28.el7 testrepo 94 k
事务概要
============================================================================================================
安装 1 软件包
总下载量:94 k
安装大小:302 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : createrepo-0.9.9-28.el7.noarch 1/1
验证中 : createrepo-0.9.9-28.el7.noarch 1/1
已安装:
createrepo.noarch 0:0.9.9-28.el7
完毕!
2.确定好repo的输出形式(此次测试本地输出)
1)本地输出:提供一个放置rpm包的本地路径
2)网络输出:提供一个文件服务器,配置好ftp服务或http服务
ps:需要确认防火墙服务关闭
3.在准备好的目录中放置相应的rpm包:
4.createrepo创建repodata:
[root@kasumi repo]# createrepo /yum/repo/
Spawning worker 0 with 106 pkgs
Spawning worker 1 with 105 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@kasumi repo]# ll /yum/repo/
ps:确认创建完成
[root@kasumi repo]# ll /yum/repo/ | grep "repodata"
drwxr-xr-x. 2 root root 4096 5月 8 00:11 repodata
5.在etc/yum.repos.d/CentOS-Base.repo写入配置文件
[xen]
11 name=xen repo
12 baseurl=file:///yum/repo/
13 enabled=1
14 gpgcheck=0
6.检测可用repo
[root@kasumi repo]# yum repolist
已加载插件:fastestmirror, langpacks
testrepo | 3.6 kB 00:00:00
xen | 2.9 kB 00:00:00
xen/primary_db | 131 kB 00:00:00
Loading mirror speeds from cached hostfile
源标识 源名称 状态
testrepo Centos7 repotest 9,591
xen xen repo 211