源碼包製作成RPM包

源碼包製作成RPM包


第一步:首先安裝rpm-build軟件包:實現生成rpm包操作

[root@server1 ~]#rpm -qa | grep rpm-build

[root@server1 ~]#yum install -y rpm-build


第二步:製作httpd.spec文件

注:必須普通用戶來做


[root@server1 ~]# useradd tom

[root@server1 ~]# su - tom

[tom@server1 ~]$ vim httpd.spec

[tom@server1 ~]$ cat httpd.spec

Name:       httpd              //程序名

Version:    2.2.25            //版本號

Release:    1%{?dist}

Summary:    compiled from 2.2.25 by zsp         //描述信息,這個可以自定義寫


Group:      System  Environment/Daemons

License:    GPL

URL:        http://www.tarnea.com              //自定義該信息

Source0:    httpd-2.2.25.tar.gz               //源文件名稱,需和下面第四步對應,文件名稱要一直

BuildRoot:  %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)


BuildRequires:  gcc, gcc-c++, openssl-devel          //生成rpm包所需要的軟件支持

Requires:   wireshark-gnome                        //執行該rpm


%description

Apache web server. Compiled from  2.2.25 by zsp


%prep

%setup -q



%build

./configure  --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-cgi  --enable-ssl --enable-charset-lite --enable-suexec --with-suexec-caller=daemon  --with-suexec-docroot=/usr/local/httpd/htdocs


make %{?_smp_mflags}



%install              //安裝之前需初始化安裝目錄

rm -rf %{buildroot}

make install DESTDIR=%{buildroot}



%clean

rm -rf %{buildroot}



%files                    //安裝之後生成的文件

%defattr(-,root,root,-)

%defattr(-,root,root,-)

/usr/local/httpd/bin/*

/usr/local/httpd/build/*

/usr/local/httpd/cgi-bin/*

%config  /usr/local/httpd/conf/*

/usr/local/httpd/error/*

/usr/local/httpd/htdocs/*

/usr/local/httpd/icons/*

/usr/local/httpd/include/*

/usr/local/httpd/lib/*

%dir  /usr/local/httpd/logs

%doc  /usr/local/httpd/man/*

%doc  /usr/local/httpd/manual/*

/usr/local/httpd/modules/*


%post                         //安裝之後需要執行的動作,將apachectl拷貝成myhttpd

cp  /usr/local/httpd/bin/apachectl /etc/init.d/myhttpd

sed -i '1a # chkconfig:  2345 85 15' /etc/init.d/myhttpd

sed -i '2a #  description: apache web server' /etc/init.d/myhttpd

chkconfig --add myhttpd


%preun                         //卸載該rpm包所執行的一些操作

/etc/init.d/myhttpd stop

chkconfig --del myhttpd



%changelog                       //定義一些日誌文件,可以使用:rpm -q  --changelog httpd查看到

* Wed Mar 26 2014  zhangzhg <[email protected]> 2.2.25

- first rpm from  httpd-2.2.25


[tom@server1 ~]$


第三步:生成相關目錄

[tom@server1  ~]$ ls

httpd-2.2.25.tar.gz  httpd.spec

[tom@server1  ~]$ rpmbuild httpd.spec           //生成相關目錄,有錯誤類型的提示信息,屬正常

error:  File /home/tom/rpmbuild/SOURCES/httpd-2.2.25.tar.gz: No such file or  directory      

[tom@server1  ~]$ ls

httpd-2.2.25.tar.gz  httpd.spec   rpmbuild          //生成之後會出現rpmbuild目錄

[tom@server1  ~]$ ls rpmbuild/

BUILD  BUILDROOT   RPMS  SOURCES  SPECS   SRPMS       //rpmbuild目錄下有這六個目錄



第四步:把文件拷貝到指定目錄

[tom@server1  ~]$ cp httpd.spec rpmbuild/SPECS/

[tom@server1  ~]$ cp httpd-2.2.25.tar.gz rpmbuild/SOURCES/


第五步:生成RPM包

[tom@server1 ~]$ rpmbuild -ba rpmbuild/SPECS/httpd.spec


如果無法執行,則可能會提示沒有安裝gcc、gcc-c++和openssl-devel軟件,退出tom用戶,執行yum安裝即可;[root@server1~]# yum install -y gcc gcc-c++ openssl-devel


安裝完成後,會在在RPMS目錄下生成rpm包,在SRPMS目錄下生成源碼包:

[tom@server1 ~]$ ls rpmbuild/RPMS/x86_64/

httpd-2.2.25-1.el6.x86_64.rpm

[tom@server1 ~]$ ls rpmbuild/SRPMS/

httpd-2.2.25-1.el6.src.rpm

[tom@server1 ~]$



第六步:測試新生成的RPM包

[root@server1  ~]# cp /home/tom/rpmbuild/RPMS/x86_64/httpd-2.2.25-1.el6.x86_64.rpm .

[root@server1  ~]# rpm -ivh httpd-2.2.25-1.el6.x86_64.rpm  

//由於在httpd.spec文件中設置了依賴關係,所以安裝的時候會提示有wireshark-gnome的依賴,做這個設置爲了驗證rpm製作時的依賴選項,所以,可以通過忽略依賴關係安裝。

error:  Failed dependencies:

   wireshark-gnome is needed by  httpd-2.2.25-1.el6.x86_64

[root@server1  ~]# rpm -ivh --nodeps  httpd-2.2.25-1.el6.x86_64.rpm       //忽略依賴關係安裝

Preparing...                 ########################################### [100%]

  1:httpd                   ########################################### [100%]

[root@server1  ~]# rpm -e --nodeps httpd-2.2.25-1.el6.x86_64

httpd  (no pid file) not running        

//由於沒有開啓myhttpd,而在httpd.spec文件中設置了%preun 選項,所以會有提示說httpd沒有運行

[root@server1  ~]#





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章