若是你對RPM沒有什麼好印像的話,我相信緣由就是它的過複雜的包依賴關係。
但若是本身動手來編繹RPM包的話,這個問題你能夠很愉快的進行控制
若是你有一個很好的軟件版本控制系統的話,你徹底能夠把你全部要用的軟件包都編繹成RPM, 這樣能夠提升一些常規軟件部署效率,好比apache mysql這樣的軟件。
本次目標:在新裝的一臺centos6.4 x86_64位系統上生成根據apache的源碼包生成個apache的rpm文件html
yum-y install wget -ymysql
yuminstall rpm-build -ylinux
wget http://archive.apache.org/dist/httpd/httpd-2.4.4.tar.bz2sql
這些文件的下載能夠放在一個文檔,好比/usr/local/src,本博寫的文件是直接下載在/root目錄下的apache
RPM的創建能夠直接從Apache httpd源碼壓縮包中使用如下命令:centos
rpmbuild-tb httpd-2.4.4.tar.bz2安全
可是若是下載好httpd的源碼包就直接使用這個命令的話是會有以下錯誤提示的服務器
相應的「開發」被安裝在您的構建系統以前創建的RPM包將被要求,rpmbuild的命令會自動計算須要什麼的RPM,並列出在您的系統中缺乏的任何依賴。這些「開發」包不會被構建完成後,能夠安全地刪除。app
根據上面的提示要安裝的包,咱們要下載apr 1.4以上的相關的包和distcache的包,在系統自帶的包裏面的apr的版本過低的。ide
wget http://mirror.bit.edu.cn/apache/apr/apr-1.5.0.tar.bz2
wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.5.3.tar.bz2
以下所示下載好apr的包要是直接用rpmbuild打包也仍是不行,仍是要安裝相關的組件
結和上面關於apr和httpd相關的組件整合在一塊兒安裝以下所示:除了freetds的組件,這個組件要從別的源下載的如epel
yum -y install autoconf libtool doxygen expat expat-devel libuuid-develdb4-devel mysql-devel unixODBC-devel postgresql-devel sqlite-devel pcrepcre-devel lua-devel libxml2-devel openldap-devel nss-devel zlib-devel libselinux-develmake
安裝「freetds freetds-devel」這個相關的組件的,只是這個包在系統自帶的那個包裏是沒有的,需要用外網的源,好比epel、remi等。這裏我就用epel的源
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
yum -y install freetds freetds-devel
安裝好上面相關的組件後就可使用這個命令「rpmbuild-tb apr-1.5.0.tar.bz2」編譯apr的rpm包了。
打包好以後會/root/rpmbuild/RPMS/x86_64/下生成rpm的包的,這裏的這個rpmbuild這個目錄是我在作第一步的時候使用這個命令時「rpmbuild -tb httpd-2.4.6.tar.bz2」它自動生成的,固然也能夠本身建這個目錄的及這個目錄下面的這幾個目錄的(BUILD BUILDROOT RPMS SOURCES SPECS SRPMS)
下面就是安裝apr的包
rpm–ivh /root/rpmbuild/RPMS/x86_64/apr-1.5.0-1.x86_64.rpm
rpm-ivh /root/rpmbuild/RPMS/x86_64/apr-devel-1.5.0-1.x86_64.rpm
rpmbuild -tb apr-util-1.5.3.tar.bz2
rpm -ivh /root/rpmbuild/RPMS/x86_64/apr-util-* //安裝轉爲rpm包的apr-util的全部的包
最後要安裝distcache這個組件:
rpmbuild --rebuild distcache-1.4.5-23.src.rpm //從源碼包創建二進制包
rpm -ivh /root/rpmbuild/RPMS/x86_64/distcache-* //安裝全部製做好的distcache的rpm的包
全部和httpd製做相關的組件都安裝好了,接下來就能夠編譯httpd的rpm包了
rpmbuild -tb httpd-2.4.4.tar.bz2
httpd的rpm包打包好以後就能夠安裝了以下所示,不過在安裝httpd的rpm包以前要先安裝mailcap組件的,否則會提示「
[root@localhost~]# rpm -ivh rpmbuild/RPMS/x86_64/httpd-2.4.4-1.x86_64.rpm
error: Failed dependencies:
/etc/mime.types is needed by httpd-2.4.4-1.x86_64」
yum install mailcap -y
安裝完mailcap組件後再安裝下面的httpd的相關的rpm包:
rpm–ivh /root/rpmbuild/RPMS/x86_64/httpd-2.4.4-1.x86_64.rpm
rpm–ivh /root/rpmbuild/RPMS/x86_64/httpd-devel-2.4.4-1.x86_64.rpm
rpm–ivh /root/rpmbuild/RPMS/x86_64/httpd-tools-2.4.4-1.x86_64.rpm
rpm -ivh /root/rpmbuild/RPMS/x86_64/httpd-manual-2.4.4-1.x86_64.rpm
rpm -ivh /root/rpmbuild/RPMS/x86_64/mod_authnz_ldap-2.4.4-1.x86_64.rpm
rpm -ivh /root/rpmbuild/RPMS/x86_64/mod_lua-2.4.4-1.x86_64.rpm
rpm -ivh /root/rpmbuild/RPMS/x86_64/mod_proxy_html-2.4.4-1.x86_64.rpm
rpm -ivh /root/rpmbuild/RPMS/x86_64/mod_socache_dc-2.4.4-1.x86_64.rpm
rpm -ivh /root/rpmbuild/RPMS/x86_64/mod_ssl-2.4.4-1.x86_64.rpm
service httpd start
rpmbuild --help 命令的解釋說明以下:
————————————————————————————————————————————
*使用命令:rpmbuild ·[OPTION]
Build options with [ <specfile> | <tarball> | <sourcepackage> ]:
*創建包的選項有:[ 從文件<specfile>創建 |從 <tarball>包創建 |從 <source package>包創建]
*從文件<specfile>創建
-bp build through %prep (unpack sources and apply patches) from<specfile>
* -bp 從<specfile>文件的%prep段開始創建(解開源碼包並打補丁)
-bc build through %build (%prep, then compile) from <specfile>
*-bc 從<specfile>文件的%build
-bi build through %install (%prep,%build, then install) from <specfile>
-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>
*只創建源碼包
*從 <tarball>包創建
-tp build through %prep (unpack sources and apply patches) from<tarball>
-tc build through %build (%prep, then compile) from <tarball>
-ti build through %install (%prep, %build,then install) from <tarball>
-ta build source and binary packages from <tarball>
*創建源碼和二進制包
-tb build binary package only from <tarball>
*只創建二進制包
-ts build source package only from <tarball>
*只創建源碼包
*從 <source package>包創建
--rebuild
build binary package from<source package>
*創建二進制包
--recompile
build through %install (%prep,%build, then install) from <source package>
————————————————————————————————————————————
番外的,整合了一下上面所述的命令的,以下所示:
————————————————————————————————————————————
以上的apache的源碼包就打包成了rpm的包,仍是有不少rpm包的。將這些在/root/rpmbuild/RPMS/x86_64/下生成rpm的包或拷貝整個rpmbuild這個目錄到別的服務器上,那些相關的組件也仍是要安裝的,才能安裝這些打包好的rpm包的。這樣就方便多了,不用編譯要等那麼長的時間了,步驟以下所示:
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
yum -y install autoconf libtool doxygen expat expat-devel libuuid-devel db4-develmysql-devel unixODBC-devel postgresql-devel sqlite-devel pcre pcre-devellua-devel libxml2-devel openldap-devel nss-devel zlib-devel libselinux-develmake freetds freetds-devel mailcap
rpm –ivh /root/rpmbuild/RPMS/x86_64/apr-1.5.0-1.x86_64.rpm
rpm -ivh /root/rpmbuild/RPMS/x86_64/apr-devel-1.5.0-1.x86_64.rpm
rpm -ivh /root/rpmbuild/RPMS/x86_64/apr-util-*
rpm -ivh /root/rpmbuild/RPMS/x86_64/distcache-*
rpm –ivh /root/rpmbuild/RPMS/x86_64/httpd-2.4.4-1.x86_64.rpm
rpm –ivh /root/rpmbuild/RPMS/x86_64/httpd-devel-2.4.4-1.x86_64.rpm
rpm –ivh /root/rpmbuild/RPMS/x86_64/httpd-tools-2.4.4-1.x86_64.rpm
rpm -ivh /root/rpmbuild/RPMS/x86_64/httpd-manual-2.4.4-1.x86_64.rpm
rpm -ivh /root/rpmbuild/RPMS/x86_64/mod_authnz_ldap-2.4.4-1.x86_64.rpm
rpm -ivh /root/rpmbuild/RPMS/x86_64/mod_lua-2.4.4-1.x86_64.rpm
rpm -ivh /root/rpmbuild/RPMS/x86_64/mod_proxy_html-2.4.4-1.x86_64.rpm
rpm -ivh /root/rpmbuild/RPMS/x86_64/mod_socache_dc-2.4.4-1.x86_64.rpm
rpm -ivh /root/rpmbuild/RPMS/x86_64/mod_ssl-2.4.4-1.x86_64.rpm
————————————————————————————————————————————