之前使用的yum仓库,是直接将baseurl设置为官方镜像,或者是安装光盘。本节内容将介绍如何将互联网上下载到本地的rpm包制作成本地的yum源。定制yum源的命令是 createrepo:
[[email protected] ~]# createrepo
-bash: createrepo: command not found # 该命令尚未安装,可以使用yum安装
[[email protected] ~]# yum -y install createrepo
Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package createrepo.noarch 0:0.9.9-18.el6 will be installed --> Processing Dependency: python-deltarpm for package: createrepo-0.9.9-18.el6.noarch --> Running transaction check ---> Package python-deltarpm.x86_64 0:3.5-0.5.20090913git.el6 will be installed --> Processing Dependency: deltarpm = 3.5-0.5.20090913git.el6 for package: python-deltarpm-3.5-0.5.20090913git.el6.x86_64 --> Running transaction check ---> Package deltarpm.x86_64 0:3.5-0.5.20090913git.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================= Package Arch Version Repository Size ============================================================================== Installing: createrepo noarch 0.9.9-18.el6 cdrom-centos6 94 k Installing for dependencies: deltarpm x86_64 3.5-0.5.20090913git.el6 cdrom-centos6 71 k python-deltarpm x86_64 3.5-0.5.20090913git.el6 cdrom-centos6 27 k Transaction Summary ================================================================================= Install 3 Package(s) Total download size: 192 k Installed size: 518 k Downloading Packages: --------------------------------------------------------------------------------- Total 1.9 MB/s | 192 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : deltarpm-3.5-0.5.20090913git.el6.x86_64 1/3 Installing : python-deltarpm-3.5-0.5.20090913git.el6.x86_64 2/3 Installing : createrepo-0.9.9-18.el6.noarch 3/3 Verifying : createrepo-0.9.9-18.el6.noarch 1/3 Verifying : python-deltarpm-3.5-0.5.20090913git.el6.x86_64 2/3 Verifying : deltarpm-3.5-0.5.20090913git.el6.x86_64 3/3 Installed: createrepo.noarch 0:0.9.9-18.el6 Dependency Installed: deltarpm.x86_64 0:3.5-0.5.20090913git.el6 python-deltarpm.x86_64 0:3.5-0.5.20090913git.el6 Complete!
一、 制作本地的yum源
现在到官方站点上下载几个rpm包到本地(可以使用ftp工具FileZilla将本机上下载的文件传输到虚拟机中):
[[email protected] ~]# ls
anaconda-ks.cfg if_exist.sh Templates axis-1.2.1-7.5.el6_5.noarch.rpm install.log Videos axis-javadoc-1.2.1-7.5.el6_5.noarch.rpm install.log.syslog xen-4.4.1-5.el6.x86_64.rpm axis-manual-1.2.1-7.5.el6_5.noarch.rpm mkscript zsh-4.3.10-7.el6.x86_64.rpm Desktop Music zsh-html-4.3.10-7.el6.x86_64.rpm Documents Pictures Downloads Public # 下载了很多rpm包
[[email protected] ~]# mkdir /yum
[[email protected]ocalhost ~]# mkdir /yum/package
[[email protected] ~]# mv *.rpm /yum/package/
[[email protected] ~]# ls /yum/package/
axis-1.2.1-7.5.el6_5.noarch.rpm xen-4.4.1-5.el6.x86_64.rpm axis-javadoc-1.2.1-7.5.el6_5.noarch.rpm zsh-4.3.10-7.el6.x86_64.rpm axis-manual-1.2.1-7.5.el6_5.noarch.rpm zsh-html-4.3.10-7.el6.x86_64.rpm
[[email protected] ~]# createrepo /yum/package/
# 使用createrepo命令加上rpm包的路径即可 Spawning worker 0 with 6 pkgs Workers Finished Gathering worker results Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete
[[email protected] ~]# ls /yum/package/
axis-1.2.1-7.5.el6_5.noarch.rpm zsh-html-4.3.10-7.el6.x86_64.rpm axis-javadoc-1.2.1-7.5.el6_5.noarch.rpm xen-4.4.1-5.el6.x86_64.rpm axis-manual-1.2.1-7.5.el6_5.noarch.rpm zsh-4.3.10-7.el6.x86_64.rpm repodata #会发现多了一个目录repodata
[[email protected] ~]# cd /yum//package/repodata/
[[email protected] repodata]# ls
# repodata中有很多新生成的文件 4aa67d3d6de3fb964dd96bc15e3849a95c0c26add8bdf871b584c42fafc6564d-other.sqlite.bz2 # 这是个小型的嵌入式数据库引擎 9501c262742c6024ec0bf8e0e0a876c1ab8c51c3c9f9e8b54205c03121c2274f-primary.xml.gz af1104a240755c3d4cf5d8ead181afed54f3395d71f6eec76210bae9aeac6b5f-primary.sqlite.bz2 # 主配置文件,包含当前仓库内的所有rpm包,以及各rpm包之间的依赖关系 d8d9144e02ffe32302d157984b9fb84246e30e78a3ab440c32b74e73489de44e-filelists.sqlite.bz2 f501ede79b66c9f96117d7070cffae3c8aa621723f13f53999cd2a91b621cf1e-filelists.xml.gz # 当前目录中所有rpm包的文件列表 repomd.xml # 核心文件,用来保留下面六个文件的时间戳信息,当升级rpm包时,yum会将本地rpm包的缓存时间戳和该文件中的时间戳进行比较,如果一致,说明远程服务器的rpm包没有更新 (本地的缓存时间戳保存在/var/cache/yum) 832dc759e3507b97d6b92ce2d82aee1242d2b15839b0788ab7ec342fe059079f-other.xml.gz # 其他信息,如rpm包的改变日志等(每次rpm包升级的变化),rpm -q --changelog会依赖这个文件
[[email protected] repodata]# rpm -q --changelog bash
* Tue Jul 09 2013 Roman Rakus <[email protected]> - 4.1.2-15 - Fixed a bug that caused trap handlers to be executed recursively, corrupting internal data structures. Resolves: #982610 * Wed Aug 29 2012 Roman Rakus <[email protected]> - 4.1.2-14 - Tweak a logout patch so it will not create backup file Resolves: #677439
[[email protected] repodata]# ls /var/cache/yum
timedhosts.txt x86_64
二、使用本地的yum源
[[email protected] repodata]# vim /etc/yum.repos.d/localrepo.repo
[local-package] name=Local x86_64 baseurl=file:///yum/package gpgcheck=0 enabled=1
[[email protected] ~]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile local-package | 2.9 kB 00:00 ... local-package/primary_db | 7.0 kB 00:00 ... base | 4.0 kB 00:00 ... repo id repo name status cdrom-centos6 CentOS 6.4 x86_64 6,367 local-package Local x86_64 6 # 可以看到本地yum源已经创建成功了 base CentOS 6.4 x86_64 6,367 repolist: 12,740 [[email protected] ~]# yum install axis Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package axis.noarch 0:1.2.1-7.5.el6_5 will be installed --> Processing Dependency: wsdl4j for package: axis-1.2.1-7.5.el6_5.noarch --> Processing Dependency: log4j for package: axis-1.2.1-7.5.el6_5.noarch --> Processing Dependency: jaxp_parser_impl for package: axis-1.2.1-7.5.el6_5.noarch local-package/filelists_db | 21 kB 00:00 ... --> Processing Dependency: javamail for package: axis-1.2.1-7.5.el6_5.noarch --> Processing Dependency: jakarta-commons-logging for package: axis-1.2.1-7.5.el6_5.noarch --> Processing Dependency: jakarta-commons-httpclient for package: axis-1.2.1-7.5.el6_5.noarch --> Processing Dependency: jakarta-commons-discovery for package: axis-1.2.1-7.5.el6_5.noarch --> Processing Dependency: jaf for package: axis-1.2.1-7.5.el6_5.noarch --> Running transaction check ---> Package classpathx-jaf.x86_64 0:1.0-15.4.el6 will be installed ---> Package classpathx-mail.noarch 0:1.1.1-9.4.el6 will be installed ---> Package jakarta-commons-discovery.noarch 1:0.4-5.4.el6 will be installed ---> Package jakarta-commons-httpclient.x86_64 1:3.1-0.7.el6_3 will be installed ---> Package jakarta-commons-logging.noarch 0:1.0.4-10.el6 will be installed ---> Package java-1.5.0-gcj.x86_64 0:1.5.0.0-29.1.el6 will be installed --> Processing Dependency: sinjdoc for package: java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64 ---> Package log4j.x86_64 0:1.2.14-6.4.el6 will be installed --> Processing Dependency: xml-commons-apis for package: log4j-1.2.14-6.4.el6.x86_64 ---> Package wsdl4j.noarch 0:1.5.2-7.8.el6 will be installed --> Running transaction check ---> Package sinjdoc.x86_64 0:0.5-9.1.el6 will be installed --> Processing Dependency: java_cup >= 0.10 for package: sinjdoc-0.5-9.1.el6.x86_64 ---> Package xml-commons-apis.x86_64 0:1.3.04-3.6.el6 will be installed --> Running transaction check ---> Package java_cup.x86_64 1:0.10k-5.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================= Package Arch Version Repository Size ================================================================================= Installing: axis noarch 1.2.1-7.5.el6_5 local-package 1.5 M # 可以看到该rpm包来源于本地的repository,而相关的依赖关系来源于光盘yum源 Installing for dependencies: classpathx-jaf x86_64 1.0-15.4.el6 cdrom-centos6 100 k classpathx-mail noarch 1.1.1-9.4.el6 cdrom-centos6 479 k jakarta-commons-discovery noarch 1:0.4-5.4.el6 cdrom-centos6 73 k jakarta-commons-httpclient x86_64 1:3.1-0.7.el6_3 cdrom-centos6 587 k jakarta-commons-logging noarch 1.0.4-10.el6 cdrom-centos6 52 k java-1.5.0-gcj x86_64 1.5.0.0-29.1.el6 cdrom-centos6 139 k java_cup x86_64 1:0.10k-5.el6 cdrom-centos6 197 k log4j x86_64 1.2.14-6.4.el6 cdrom-centos6 679 k sinjdoc x86_64 0.5-9.1.el6 cdrom-centos6 705 k wsdl4j noarch 1.5.2-7.8.el6 cdrom-centos6 157 k xml-commons-apis x86_64 1.3.04-3.6.el6 cdrom-centos6 439 k Transaction Summary ================================================================================ Install 12 Package(s) Total download size: 5.0 M Installed size: 11 M Is this ok [y/N]: