linux rpmbuild

RPM为Redhat Package Manager缩写,是一个为Redhat系列Linux生产软件包的小工厂。其产品是RPM包,包含一些归档文件和meta信息;这些meta信息用来记录如何安装和删除这些文件,一些帮助脚本,文件属性和描述行信息(如包依赖哪些包和被哪些包依赖)。整个RPM包的制作过程严格按照SPEC文件规范的执行,然后通过rpmbuild命令来解析SPEC文件生成对应的RPM包。

至于为什么要制作rpm包,大家都明白,方便部署,比起源码来,这个部署速度更快

下面让以nginx为例,做rpm包制作:

1、安装需要的工具:

yum install rpm-buildyum install rpmdevtools

2、生成spec文件:

rpmdev-newspec -o nginx-1.6.1.spec

修改为:# cat nginx-1.6.2.spec

Name:           nginxVersion:        1.6.2Release:        1%{?dist}Summary:        small and high performance HTTP and reverse proxy serverGroup:          System Environment/stableLicense:        el6URL:            http://nginx.orgSource0:        http://nginx.org/download/nginx-1.6.2.tar.gzSource1:        nginx-serverSource2:        nginx.confSource3:        vhost.confBuildRoot:      %{_topdir}/BUILDROOTBuildRequires:  pcre-devel,zlib-devel,openssl,perl,perl(ExtUtils::Embed)Requires:       gcc,gcc-c++,make,pcre,openssl,perl-ExtUtils-Embed%descriptionNginx [engine x] is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3proxy server written by Igor Sysoev.%prep%setup -q%build./configure     --user=nobody     --group=nobody     --prefix=/data/nginx     --with-http_ssl_module     --with-http_realip_module     --with-http_addition_module     --with-http_sub_module     --with-http_dav_module     --with-http_flv_module     --with-http_gzip_static_module     --with-http_stub_status_module     --with-http_perl_module     --with-mail     --with-mail_ssl_module#make %{?_smp_mflags}make%installmake install     此处有错,下面会提示#rm -rf $RPM_BUILD_ROOT#make install DESTDIR=$RPM_BUILD_ROOT%{__install} -p -D %{SOURCE1} -m 0711 %{buildroot}/etc/init.d/nginx%{__install} -p -D %{SOURCE2} -m 0644 %{buildroot}/data/nginx/conf/nginx.conf%{__install} -p -D %{SOURCE3} -m 0644 %{buildroot}/data/nginx/conf/vhosts/vhost.conf%cleanrm -rf $RPM_BUILD_ROOT%postchkconfig --add nginxchkconfig --level 345 nginx onecho "ulimit -SHn 51200" >> /etc/rc.local%files%defattr(-,root,root,-)%doc%dir /usr/lib64/perl5/perllocal.pod%dir /usr/local/lib64/perl5/auto/nginx/.packlist%dir /usr/local/lib64/perl5/auto/nginx/nginx.bs%dir /usr/local/lib64/perl5/auto/nginx/nginx.so%dir /usr/local/lib64/perl5/nginx.pm%dir /usr/local/share/man/man3/nginx.3pm%dir /etc/init.d/nginx/data/nginx%changelog

3?开始制作:

rpmbuild -bb nginx-1.6.2.spec

产生报错如下:

error: File /root/rpmbuild/SOURCES/nginx-1.6.2.tar.gz: No such file or directory

没有文件:将nginx源码包移至/root/rpmbuild/SOURCE/

mv nginx-1.6.2.tar.gz /root/rpmbuild/SOURCES/

再次运行,仍然报错:

Processing files: nginx-1.6.2-1.el6.x86_64error: File not found: /root/rpmbuild/BUILDROOT/nginx-1.6.2-1.el6.x86_64/usr/lib64/perl5/perllocal.poderror: File not found: /root/rpmbuild/BUILDROOT/nginx-1.6.2-1.el6.x86_64/usr/local/lib64/perl5/auto/nginx/.packlisterror: File not found: /root/rpmbuild/BUILDROOT/nginx-1.6.2-1.el6.x86_64/usr/local/lib64/perl5/auto/nginx/nginx.bserror: File not found: /root/rpmbuild/BUILDROOT/nginx-1.6.2-1.el6.x86_64/usr/local/lib64/perl5/auto/nginx/nginx.soerror: File not found: /root/rpmbuild/BUILDROOT/nginx-1.6.2-1.el6.x86_64/usr/local/lib64/perl5/nginx.pmerror: File not found: /root/rpmbuild/BUILDROOT/nginx-1.6.2-1.el6.x86_64/usr/local/share/man/man3/nginx.3pmRPM build errors:    File not found: /root/rpmbuild/BUILDROOT/nginx-1.6.2-1.el6.x86_64/usr/lib64/perl5/perllocal.pod    File not found: /root/rpmbuild/BUILDROOT/nginx-1.6.2-1.el6.x86_64/usr/local/lib64/perl5/auto/nginx/.packlist    File not found: /root/rpmbuild/BUILDROOT/nginx-1.6.2-1.el6.x86_64/usr/local/lib64/perl5/auto/nginx/nginx.bs    File not found: /root/rpmbuild/BUILDROOT/nginx-1.6.2-1.el6.x86_64/usr/local/lib64/perl5/auto/nginx/nginx.so    File not found: /root/rpmbuild/BUILDROOT/nginx-1.6.2-1.el6.x86_64/usr/local/lib64/perl5/nginx.pm    File not found: /root/rpmbuild/BUILDROOT/nginx-1.6.2-1.el6.x86_64/usr/local/share/man/man3/nginx.3pm

将配置文件中的下面几行禁掉,方可以通过

%dir /usr/lib64/perl5/perllocal.pod%dir /usr/local/lib64/perl5/auto/nginx/.packlist%dir /usr/local/lib64/perl5/auto/nginx/nginx.bs%dir /usr/local/lib64/perl5/auto/nginx/nginx.so%dir /usr/local/lib64/perl5/nginx.pm%dir /usr/local/share/man/man3/nginx.3pm 

但是不带上这些文件,订制的包非常不正常,只有几十K 是非常不正常的。终于问题所在配置文件中make install 应该使用 make install DESTDIR=%{buildroot}

# rpmbuild -bb nginx-1.6.2.spec没有报错的情况下,你现在可以去/root/rpmbuild/RPMS/x86_64找到我们刚刚做好的rpm包了

检查包情况:

rpm2cpio nginx-1.6.2-1.el6.x86_64.rpm | cpio -id3814 blocks

安装测试:

补充说明:rpmbuild简单使用,(可用man rpmbuid 进行详细了解) -bl verify %files section from <specfile> *检查<specfile>文件的%files段 -ba build source and binary packages from <specfile> *建立源码和二进制包 -bb build binary package only from <specfile> *只建立二进制包 -bs build source package only from <specfile> *只建立源码包

linux rpmbuild,首发于运维者。

可偏偏。多么温柔,一出口便是相互指责和嘲讽。

linux rpmbuild

相关文章:

你感兴趣的文章:

标签云: