(1)安裝src格式的rpm包html
源碼格式的rpm包(一般是src格式)沒法直接使用,須要加工製做後才能使用java
[root@localhost ~]# cd /yum/package/nginx
[root@localhost package]# lsweb
axel-2.4 nginx-1.7.10-1.el6.ngx.src.rpm # 如今想安裝使用源碼格式的nginx,但這個軟件包不是二進制格式的,安裝了之後沒法正常使用 axel-2.4.tar.gz repodata 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
[root@localhost package]# rpm -qpl nginx-1.7.10-1.el6.ngx.src.rpm apache
# 這個包安裝了之後會生成如下文件 warning: nginx-1.7.10-1.el6.ngx.src.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY logrotate nginx-1.7.10.tar.gz # 這就是源碼文件 nginx.conf nginx.init nginx.service nginx.spec # 製做rpm包所須要的spec文件 nginx.suse.init nginx.suse.logrotate nginx.sysconf nginx.upgrade.sh nginx.vh.default.conf nginx.vh.example_ssl.conf
[root@localhost package]# rpm -ivh nginx-1.7.10-1.el6.ngx.src.rpm bash
warning: nginx-1.7.10-1.el6.ngx.src.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY 1:nginx warning: user builder does not exist - using root warning: group builder does not exist - using root # 提示用戶不存在,須要建立該用戶 ... warning: user builder does not exist - using root warning: group builder does not exist - using root
[root@localhost package]# useradd builder服務器
[root@localhost package]# rpm -ivh nginx-1.7.10-1.el6.ngx.src.rpm dom
warning: nginx-1.7.10-1.el6.ngx.src.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY 1:nginx ########################################### [100%]
(2)rpmbuild目錄介紹ide
[root@localhost ~]# lsui
anaconda-ks.cfg Documents if_exist.sh install.log.syslog Music Public Templates Desktop Downloads install.log mkscript Pictures rpmbuild Videos # 安裝到了rpmbuild目錄下
[root@localhost ~]# cd rpmbuild/
[root@localhost rpmbuild]# ls
SOURCES SPECS
[root@localhost rpmbuild]# cd SOURCES/
[root@localhost SOURCES]# ls
logrotate nginx.init nginx.suse.logrotate nginx.vh.default.conf nginx-1.7.10.tar.gz nginx.service nginx.sysconf nginx.vh.example_ssl.conf nginx.conf nginx.suse.init nginx.upgrade.sh # 該目錄用來存放全部製做rpm包所須要的源碼、配置文件等
[root@localhost SOURCES]# cd ../SPECS/
[root@localhost SPECS]# ls
nginx.spec #此文件將被用來製做rpm包
[root@localhost SPECS]# rpmbuild -ba nginx.spec
# -ba表示編譯生成一個源碼格式以及一個二進制格式的包,若是是-bb,表示只生成二進制格式 error: Failed build dependencies: pcre-devel is needed by nginx-1.7.10-1.el6.ngx.x86_64 #報錯表示須要不少依賴的包
(3)經過spec文件來製做rpm包
解決了依賴包的問題後,再次使用rpmbuild命令來製做rpm包:
[root@localhost SPECS]# rpmbuild -ba nginx.spec
... checking for socklen_t ... found checking for in_addr_t ... found ... Wrote: /root/rpmbuild/RPMS/x86_64/nginx-debuginfo-1.7.10-1.el6.ngx.x86_64.rpm Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.uOpvTX + umask 022 + cd /root/rpmbuild/BUILD + cd nginx-1.7.10 + /bin/rm -rf /root/rpmbuild/BUILDROOT/nginx-1.7.10-1.el6.ngx.x86_64 + exit 0
[root@localhost SPECS]# cd ..
[root@localhost rpmbuild]# ls
BUILD BUILDROOT RPMS SOURCES SPECS SRPMS #多了幾個目錄,其中RPMS就是用來存放製做好的rpm包的
[root@localhost RPMS]# ls
x86_64
[root@localhost RPMS]# cd x86_64/
[root@localhost x86_64]# ls
nginx-1.7.10-1.el6.ngx.x86_64.rpm nginx-debuginfo-1.7.10-1.el6.ngx.x86_64.rpm nginx-debug-1.7.10-1.el6.ngx.x86_64.rpm
此時使用rpm -ivh命令安裝便可
(4)安裝使用rpm包
[root@localhost x86_64]# rpm -ivh nginx-1.7.10-1.el6.ngx.x86_64.rpm
Preparing... ########################################### [100%] 1:nginx ########################################### [100%] ---------------------------------------------------------------------- Thanks for using nginx! Please find the official documentation for nginx here: * http://nginx.org/en/docs/ Commercial subscriptions for nginx are available on: * http://nginx.com/products/ # 安裝成功
[root@localhost x86_64]# cd ../..
[root@localhost rpmbuild]# ls
BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
[root@localhost rpmbuild]# cd SRPMS/
[root@localhost SRPMS]# ls
nginx-1.7.10-1.el6.ngx.src.rpm # SRPMS包中存放的是src格式的rpm包
nginx是個服務器,如今能夠啓動它:
[root@localhost x86_64]# apachectl stop
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message httpd (no pid file) not running # 先關閉apache服務器
[root@localhost x86_64]# service nginx start
Starting nginx: [ OK ]
啓動成功,訪問web服務以檢驗網頁: