您的位置:首页 > 运维架构 > Linux

初涉定制linux系统之——rpm相关安装包的准备

2017-03-08 11:38 309 查看
在上一篇博客http://www.cnblogs.com/dengtr/p/5543820.html#3634582 中介绍了如何定制Centos系统镜像,但其中有个问题,就是服务所依赖的安装包不在原Centos系统镜像中,而是需要联网去epel等源那下载,对于一个不能联网的环境而言会很麻烦。

所有,我们需要可以在定制系统前,找出所有不在Centos镜像中的rpm包,封装到定制镜像中即可。本博客就给大家介绍如果获取我们需要的rpm包

1、首先,针对Centos6以下的版本,我们需要安装一个插件yum-plugin-downloadonly

1 [root@192 ~]# yum install yum-plugin-downloadonly

安装完后,如果你机器上的python是2.7以上版本的话,就需要修改下yum配置,因为Centos6以下的系统版本需要使用python2.6,所有需要修改/usr/bin/yum文件,将头部的“#!/usr/bin/python” 修改为“#!/usr/bin/python2.6”。(注:需要你本机上有/usr/bin/python2.6这个版本)

1 [root@192 ~]# vim /usr/bin/yum
2 #!/usr/bin/python2.6
3 import sys
4 try:
5     import yum
6 except ImportError:
7     print >> sys.stderr, """\
8 There was a problem importing one of the Python modules
9 required to run yum. The error leading to this problem was:
10
11    %s


2、这时候你就可以使用--downloadonly命令来yum下载自己需要的rpm了,该命令的作用就是下载rpm包及所有的依赖关系包,但是都不会被安装。

1 [root@192 ~]#  yum install --downloadonly epel*
2 Loaded plugins: fastestmirror
3 Setting up Install Process
4 Loading mirror speeds from cached hostfile
5  * base: mirrors.aliyun.com
6  * extras: mirrors.aliyun.com
7  * updates: mirrors.aliyun.com
8 Resolving Dependencies
9 --> Running transaction check
10 ---> Package epel-release.noarch 0:6-8 will be installed
11 --> Finished Dependency Resolution
12
13 Dependencies Resolved
14
15 =============================================================================================================================================================================================
16  Package                                           Arch                                        Version                                     Repository                                   Size
17 =============================================================================================================================================================================================
18 Installing:
19  epel-release                                      noarch                                      6-8                                         extras                                       14 k
20
21 Transaction Summary
22 =============================================================================================================================================================================================
23 Install       1 Package(s)
24
25 Total download size: 14 k
26 Installed size: 22 k
27 Is this ok [y/N]: y
28 Downloading Packages:
29 epel-release-6-8.noarch.rpm                                                                                                                                           |  14 kB     00:00
30 exiting because --downloadonly specified


可以看到yum只下载了epel包,但是并没有进行安装,一般下载的rpm存放在/var/cache/yum/x86_64/6/[repository]/packages/目录下,标红的[repository]表示下载包的来源仓库的名称(例如:base、extras、epel)。如刚才下载的epel-release包就存放在系统下面的目录下

1 /var/cache/yum/x86_64/6/extras/packages/epel-release-6-8.noarch.rpm

3、之后你就可以视自己的需求将下载的rpm封装到定制镜像里,以后再也不担心部署环境没外网了,当然要是客户死活不用你的定制镜像,你可以参考下一篇移动镜像源的制作方法。恩,如果博主有时间写的话。。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: