对cfengine进行定制,自制rpm包。
安装rpm制作工具
yum install rpm-build #安装rpm-build yum install rpmdevtools #安装rpmdevtools rpmdev-setuptree #创建rpmbuild目录 rpmdev-newspec -o cfengine-2.2.1.spec #创建spec模板
查看宏变量
执行rpmdev-setuptree会在用户家目录创建一个隐藏文件 .rpmmacros ,该文件重定义了一些宏变量,将默认的工作目录改在了用户家目录下的rpmbuild目录。
[root@HADOOP-215 bin]# cat /root/.rpmmacros %_topdir %(echo $HOME)/rpmbuild %_smp_mflags -j3 %__arch_install_post /usr/lib/rpm/check-rpaths /usr/lib/rpm/check-buildroot
默认的工作目录
[root@HADOOP-215 bin]# rpm --showrc |grep topdir -14: _builddir %{_topdir}/BUILD -14: _buildrootdir %{_topdir}/BUILDROOT -14: _rpmdir %{_topdir}/RPMS -14: _sourcedir %{_topdir}/SOURCES -14: _specdir %{_topdir}/SPECS -14: _srcrpmdir %{_topdir}/SRPMS -14: _topdir %(echo $HOME)/rpmbuild
默认的安装目录
[root@HADOOP-215 bin]# rpm --showrc |grep _prefix %{-C:${_mydir}}%{!-C:.}/configure --prefix=%{_prefix} --exec-prefix=%{_exec_prefix} --bindir=%{_bindir} --sbindir=%{_sbindir} --sysconfdir=%{_sysconfdir} --datadir=%{_datadir} --includedir=%{_includedir} --libdir=%{_libdir} --libexecdir=%{_libexecdir} --localstatedir=%{_localstatedir} --sharedstatedir=%{_sharedstatedir} --mandir=%{_mandir} --infodir=%{_infodir} %* ; -14: _bindir %{_exec_prefix}/bin -14: _datarootdir %{_prefix}/share -14: _exec_prefix %{_prefix} -14: _includedir %{_prefix}/include -14: _libdir %{_prefix}/lib64 -14: _libexecdir %{_exec_prefix}/libexec -14: _prefix /usr #默认安装路径 -14: _sbindir %{_exec_prefix}/sbin --program-prefix=%{?_program_prefix} \ --prefix=%{_prefix} \ --exec-prefix=%{_exec_prefix} \ prefix=%{?buildroot:%{buildroot}}%{_prefix} \ exec_prefix=%{?buildroot:%{buildroot}}%{_exec_prefix} \
spec文件
由于默认的_prefix宏变量值为 /usr,制作的rpm包安装时将会安装到/usr目录下各个目录如/usr/sbin/,/usr/share。如果想将软件安装至单一的目录,需要重定义该变量。一开始尝试过直接修改make install的DESTDIR
make install DESTDIR=%{buildroot}/usr/local/cfengine
但是由于_prefix的影响,软件会安装在/usr/local/cfengine/usr 目录下。
另外configure --prefix=/usr/local/cfengine和Prefix: /usr/local/cfengine也都尝试过,均不起作用。
通过rpm --showrc |grep _prefix看到_prefix变量后,直接修改.rpmmacros,重定义_prefix,可以生效。但是每制作一个包就得重改一次,需要找一种在spec文件中重定义宏变量的方法:
宏(Macros)是使用变量和功能来控制rpm和 rpmbuild 的自定义的行为,宏指令一般地定义在 spec 文件中。语法象 %define macro value .宏指定也可以事先在配置文件中调整。
就是下面的文件。
- 默认设置为 /usr/lib/rpm/macros or /etc/rpm/macros
- 用户设置 ~/.rpmmacros
在打包的过程中,spec files 和 rpmbuild 能使用RPM 的宏命令中的变量.
此外,在 rpmbuild 时要不顾当前设置,可以在后面加上 –define=’macro value’ 选项,要显示当前的宏指令可以使用 rpm –eval %{macro} ,也可以rpm –showrc 来 dump 全部当前的宏指令和设置。引自 http://blog.csdn.net/hncomputer/article/details/7049127
重定义_prefix如下
%define _prefix /usr/local/cfengine #重定义宏变量_prefix,rpm安装时将安装至此目录
完整spec如下
[root@HADOOP-215 SPECS]# cat cfengine-2.2.10.spec %define _prefix /usr/local/cfengine #重定义宏变量_prefix,rpm安装时将安装至此目录 Name: cfengine Version: 2.2.10 Release: 1%{?dist} Summary: cfengine by hean Group: Applications/management License: GPL URL: http://www.cfengine.org/ Source0: %{name}-%{version}.tar.gz Packager: hean <hean@staff.sina.com.cn> BuildRequires: gcc,make Requires: db4,openssl %description cfengine by hean. des %prep %setup -q %build %configure --with-berkeleydb=/usr/local/BerkeleyDB --prefix=/usr/local/cfengine make %{?_smp_mflags} %install make install DESTDIR=%{buildroot} mkdir -p %{buildroot}/var/cfengine/bin mkdir -p %{buildroot}/var/cfengine/inputs mkdir -p %{buildroot}/var/cfengine/outputs for id in `ls %{buildroot}/usr/local/cfengine/sbin/`;do ln -s /usr/local/cfengine/sbin/$id %{buildroot}/var/cfengine/bin/$id;done cp %{buildroot}/usr/local/cfengine/share/cfengine/update.conf.example %{buildroot}/var/cfengine/inputs/update.conf sed -i 's/ policyhost.*/policyhost = ( 10.7.5.10 )/g' %{buildroot}/var/cfengine/inputs/update.conf %clean %files %defattr(-,root,root,-) %doc /usr/local/cfengine/lib64/libcfengine.a /usr/local/cfengine/lib64/libcfengine.la /usr/local/cfengine/sbin/cfagent /usr/local/cfengine/sbin/cfdoc /usr/local/cfengine/sbin/cfenvd /usr/local/cfengine/sbin/cfenvgraph /usr/local/cfengine/sbin/cfetool /usr/local/cfengine/sbin/cfetoolgraph /usr/local/cfengine/sbin/cfexecd /usr/local/cfengine/sbin/cfkey /usr/local/cfengine/sbin/cfrun /usr/local/cfengine/sbin/cfservd /usr/local/cfengine/sbin/cfshow /usr/local/cfengine/share/cfengine/ChangeLog /usr/local/cfengine/share/cfengine/INSTALL /usr/local/cfengine/share/cfengine/NEWS /usr/local/cfengine/share/cfengine/README /usr/local/cfengine/share/cfengine/cf.chflags.example /usr/local/cfengine/share/cfengine/cf.freebsd.example /usr/local/cfengine/share/cfengine/cf.ftp.example /usr/local/cfengine/share/cfengine/cf.groups.example /usr/local/cfengine/share/cfengine/cf.linux.example /usr/local/cfengine/share/cfengine/cf.main.example /usr/local/cfengine/share/cfengine/cf.motd.example /usr/local/cfengine/share/cfengine/cf.preconf.example /usr/local/cfengine/share/cfengine/cf.services.example /usr/local/cfengine/share/cfengine/cf.site.example /usr/local/cfengine/share/cfengine/cf.solaris.example /usr/local/cfengine/share/cfengine/cf.sun4.example /usr/local/cfengine/share/cfengine/cf.users.example /usr/local/cfengine/share/cfengine/cfagent.conf-advanced.example /usr/local/cfengine/share/cfengine/cfagent.conf.example /usr/local/cfengine/share/cfengine/cfengine.el /usr/local/cfengine/share/cfengine/cfrc.example /usr/local/cfengine/share/cfengine/cfrun.hosts.example /usr/local/cfengine/share/cfengine/cfservd.conf.example /usr/local/cfengine/share/cfengine/update.conf.example /var/cfengine/bin/cfagent /var/cfengine/bin/cfdoc /var/cfengine/bin/cfenvd /var/cfengine/bin/cfenvgraph /var/cfengine/bin/cfetool /var/cfengine/bin/cfetoolgraph /var/cfengine/bin/cfexecd /var/cfengine/bin/cfkey /var/cfengine/bin/cfrun /var/cfengine/bin/cfservd /var/cfengine/bin/cfshow /var/cfengine/inputs/update.conf %changelog
查看包信息
查看制作好的rpm包信息
[root@HADOOP-215 SPECS]# rpm -qpi ../RPMS/x86_64/cfengine-2.2.10-1.el6.x86_64.rpm Name : cfengine Relocations: (not relocatable) Version : 2.2.10 Vendor: (none) Release : 1.el6 Build Date: 2015年04月09日 星期四 14时15分58秒 Install Date: (not installed) Build Host: HADOOP-215 Group : Applications/management Source RPM: cfengine-2.2.10-1.el6.src.rpm Size : 13358939 License: GPL Signature : (none) Packager : hean <hean@staff.sina.com.cn> URL : http://www.cfengine.org/ Summary : cfengine by hean Description : cfengine by hean. des
文件列表
[root@HADOOP-215 SPECS]# rpm -qpl ../RPMS/x86_64/cfengine-2.2.10-1.el6.x86_64.rpm /usr/local/cfengine/lib64/libcfengine.a /usr/local/cfengine/lib64/libcfengine.la /usr/local/cfengine/sbin/cfagent /usr/local/cfengine/sbin/cfdoc /usr/local/cfengine/sbin/cfenvd /usr/local/cfengine/sbin/cfenvgraph /usr/local/cfengine/sbin/cfetool /usr/local/cfengine/sbin/cfetoolgraph /usr/local/cfengine/sbin/cfexecd /usr/local/cfengine/sbin/cfkey /usr/local/cfengine/sbin/cfrun /usr/local/cfengine/sbin/cfservd /usr/local/cfengine/sbin/cfshow /usr/local/cfengine/share/cfengine/ChangeLog /usr/local/cfengine/share/cfengine/INSTALL /usr/local/cfengine/share/cfengine/NEWS /usr/local/cfengine/share/cfengine/README /usr/local/cfengine/share/cfengine/cf.chflags.example /usr/local/cfengine/share/cfengine/cf.freebsd.example /usr/local/cfengine/share/cfengine/cf.ftp.example /usr/local/cfengine/share/cfengine/cf.groups.example /usr/local/cfengine/share/cfengine/cf.linux.example /usr/local/cfengine/share/cfengine/cf.main.example /usr/local/cfengine/share/cfengine/cf.motd.example /usr/local/cfengine/share/cfengine/cf.preconf.example /usr/local/cfengine/share/cfengine/cf.services.example /usr/local/cfengine/share/cfengine/cf.site.example /usr/local/cfengine/share/cfengine/cf.solaris.example /usr/local/cfengine/share/cfengine/cf.sun4.example /usr/local/cfengine/share/cfengine/cf.users.example /usr/local/cfengine/share/cfengine/cfagent.conf-advanced.example /usr/local/cfengine/share/cfengine/cfagent.conf.example /usr/local/cfengine/share/cfengine/cfengine.el /usr/local/cfengine/share/cfengine/cfrc.example /usr/local/cfengine/share/cfengine/cfrun.hosts.example /usr/local/cfengine/share/cfengine/cfservd.conf.example /usr/local/cfengine/share/cfengine/update.conf.example /var/cfengine/bin/cfagent /var/cfengine/bin/cfdoc /var/cfengine/bin/cfenvd /var/cfengine/bin/cfenvgraph /var/cfengine/bin/cfetool /var/cfengine/bin/cfetoolgraph /var/cfengine/bin/cfexecd /var/cfengine/bin/cfkey /var/cfengine/bin/cfrun /var/cfengine/bin/cfservd /var/cfengine/bin/cfshow /var/cfengine/inputs/update.conf
参考资料
1. 使用rpm-build制作nginx的rpm包 http://nmshuishui.blog.51cto.com/1850554/1583117 2. 一堂课玩转rpm包的制作 http://blog.chinaunix.net/uid-23069658-id-3944462.html 3. spec文件详解 http://blog.csdn.net/hncomputer/article/details/7049127
不生成debuginfo包[root@HADOOP-215 ~]# echo '%debug_package %{nil}' >> ~/.rpmmacros[root@HADOOP-215 ~]# cat .rpmmacros %_topdir %(echo $HOME)/rpmbuild%_smp_mflags -j3%__arch_install_post /usr/lib/rpm/check-rpaths /usr/lib/rpm/check-buildroot