问题:为什么要制作RPM包?
答:为了避免利用源码包进行编译安装时的繁琐步骤和节省时间,同时也为了方便的卸载已安装的软件
此处我们以lsyncd为例
第一步:获取源码包
lsyncd-2.1.5.tar.gz
第二步:生成/root/rpmbulid 目录
[root@localhost ~]# rpmbuild lsyncd-2.1.5.tar.gz
error: failed to stat /root/lsyncd-2.1.5.tar.gz: No such file or directory
[root@localhost ~]# ls rpmbuild/
BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
各目录作用简单介绍如下:
BUILD -> 编译位置(忽略)
BUILDROOT -> 编译位置(忽略)
RPMS -> 生成的二进制rpm 存放位置
SOURCES -> 存放源码, 补丁文件
SPECS -> 存放编译方案*.spec 规则文件
SRPMS -> 生成rpm 源码包(src.rpm)存放位置
第三步:生成spec文件
将源码包拷贝到SOURCES目录下
[root@localhost ~]# cp lianxi/lsyncd-2.1.5.tar.gz rpmbuild/SOURCES/
[root@localhost ~]# tree
.
|-- lianxi
| `-- lsyncd-2.1.5.tar.gz
`-- rpmbuild
|-- BUILD
|-- BUILDROOT
|-- RPMS
|-- SOURCES
| `-- lsyncd-2.1.5.tar.gz
|-- SPECS
`-- SRPMS
[root@localhost SPECS]# vim lsyncd-2.1.5.spec
若想了解spec文件 请点击下面的链接
http://zhumeng8337797.blog.163.com/blog/static/100768914201181955456565/?suggestedreading&wumii
第四步。填写spec文件
[root@localhost SPECS]# vim lsyncd-2.1.5.spec
[root@localhost lianxi]# tar xf lsyncd-2.1.5.tar.gz
[root@localhost lianxi]# cd lsyncd-2.1.5
[root@localhost lsyncd-2.1.5]# ./configure //看看配置时需要那些依赖包
configure: error: Need a Lua toolchain with matching versions ('lua' library and 'lua' and 'luac' programs)
缺少一个lua的包
[root@localhost lsyncd-2.1.5]# rpm -ivh /root/lua-devel-5.1.4-4.1.el6.x86_64.rpm
warning: /root/lua-devel-5.1.4-4.1.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:lua-devel ########################################### [100%]
[root@localhost lsyncd-2.1.5]# make
[root@localhost lsyncd-2.1.5]# make install
make[1]: Entering directory `/root/lianxi/lsyncd-2.1.5'
/bin/mkdir -p '/usr/local/bin'
/usr/bin/install -c lsyncd '/usr/local/bin'
/bin/mkdir -p '/usr/local/share/doc/lsyncd/'
/usr/bin/install -c -m 644 examples/lbash.lua examples/lecho.lua examples/lgforce.lua examples/lp_w_picpathmagic.lua examples/lpostcmd.lua examples/lrsync.lua examples/lrsyncssh.lua '/usr/local/share/doc/lsyncd/'
/bin/mkdir -p '/usr/local/share/man/man1'
/usr/bin/install -c -m 644 doc/lsyncd.1 '/usr/local/share/man/man1'
make[1]: Leaving directory `/root/lianxi/lsyncd-2.1.5'
这一段输出中红字部分就是lsyncd-2.1.5.spec 文件中“%install”后面需要填写的内容,表
示安装哪些文件到哪些路径下,但要修改格式。
1. 将这一段内容中所有的/usr/local 修改为变量$RPM_BUILD_ROOT,因为制作rpm 包时并
不需要将文件安装到实际的路径,所以暂时安装在$RPM_BUILD_ROOT 中,其实就是
/root/rpmbuild/BUILDROOT/lsyncd-2.1.5-1.el6.i386 这个临时目录。
2. 将这一段内容中所有的单引号去掉或者换成双引号,因为要允许变量。
RPM build errors:
Installed (but unpackaged) file(s) found:
/bin/lsyncd
/share/doc/lsyncd/lbash.lua
/share/doc/lsyncd/lecho.lua
/share/doc/lsyncd/lgforce.lua
/share/doc/lsyncd/lp_w_picpathmagic.lua
/share/doc/lsyncd/lpostcmd.lua
/share/doc/lsyncd/lrsync.lua
/share/doc/lsyncd/lrsyncssh.lua
/share/man/man1/lsyncd.1
/usr/bin/lsyncd
/usr/share/doc/lsyncd/lbash.lua
/usr/share/doc/lsyncd/lecho.lua
/usr/share/doc/lsyncd/lgforce.lua
/usr/share/doc/lsyncd/lp_w_picpathmagic.lua
/usr/share/doc/lsyncd/lpostcmd.lua
/usr/share/doc/lsyncd/lrsync.lua
/usr/share/doc/lsyncd/lrsyncssh.lua
/usr/share/man/man1/lsyncd.1.gz
[root@localhost rpmbuild]# rpmbuild -ba lsyncd-2.1.5.spec
[root@localhost rpmbuild]# tree
|-- BUILDROOT
|-- RPMS
| `-- x86_64
| `-- lsyncd-2.1.5-1.el6.x86_64.rpm
|-- SOURCES
| `-- lsyncd-2.1.5.tar.gz
|-- SPECS
| `-- lsyncd-2.1.5.spec
`-- SRPMS
`-- lsyncd-2.1.5-1.el6.src.rpm
就这样 lsyncd-2.1.5-1.el6.x86_64.rpm lsyncd-2.1.5-1.el6.src.rpm 制作好了
[root@localhost rpmbuild]# rpm -ivh RPMS/x86_64/lsyncd-2.1.5-1.el6.x86_64.rpm
Preparing... ########################################### [100%]
1:lsyncd ########################################### [100%]
[root@localhost rpmbuild]# ls
ls lsattr lsblk lscpu lsinitrd lsmod lsyncd
指导老师:双星教育 冯老师
本人联系方式 :[email protected]