將源碼包製做成RPM包

前言:c++

RPM包安裝快速、方便。使用源碼包能夠定製想要的功能,而後將其製做成.rpm格式的包。在生產環境中,咱們的開發人員一般下載好源碼包,選擇好本身所需功能,丟給運維人員製做rpm包後。將其丟入本地yum源庫,之後直接調用安裝。。。web


下面咱們以apache WEB源碼包httpd-2.2.25.tar.gz爲例,來製做RPM包。apache


[root@localhost ~]# lsvim

anaconda-ks.cfg  httpd-2.2.25.tar.gz運維

[root@localhost ~]# yum -y install rpm-build gcc gcc-c++ide

[root@localhost ~]# useradd tompost

[root@localhost ~]# cp httpd-2.2.25.tar.gz /home/tom/優化

[root@localhost ~]# su - tomui

[root@localhost Packages]# rpm -qpi httpd-2.2.15-29.el6_4.x86_64.rpm spa

warning: httpd-2.2.15-29.el6_4.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY

Name        : httpd                        Relocations: (not relocatable)

Version     : 2.2.25                            Vendor: Red Hat, Inc.

Release     : 29.el6_4                      Build Date: 2013年08月02日 星期五 20時03分06秒

Install Date: (not installed)               Build Host: x86-002.build.bos.redhat.com

Group       : System Environment/Daemons    Source RPM: httpd-2.2.15-29.el6_4.src.rpm

Size        : 3075393                          License: ASL 2.0

Signature   : RSA/8, 2013年08月12日 星期一 21時49分45秒, Key ID 199e2f91fd431d51

Packager    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>

URL         : http://httpd.apache.org/

Summary     : Apache HTTP Server

Description :

The Apache HTTP Server is a powerful, efficient, and extensible

web server.

//上面咱們能夠看到系統自帶的httpd軟件包的詳細信息。。 

[root@localhost ~]$ vim httpd.spec  此時咱們以普通用戶編輯一個文件,必定要以.spec結尾

Name:httpd   //名稱

Version:2.2.15  //版本號

Release:        1%{?dist}

Summary:HTTP Server by SXS   //描述


Group:System Environment/Daemons  //複製上面的

License:ASL 2.0    //同上

URL:http://www.sxs.com   //網址

Source0:httpd-2.2.25.tar.gz   //源碼包名稱

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


BuildRequires:gcc,gcc-c++,openssl-devel   編譯成RPM包須要的程序

Requires:vsftp        //安裝這個RPM包所需依賴關係,必定要寫,我這是隨便寫的

 

%description

http server by sxs   //描述


%prep

%setup -q



%build 

%configure     編譯安裝的流程

./configure --prefix=/usr/local/httpd --enable-cgi --enable-rewrite --enable-charset-lite --enable-so

make %{?_smp_mflags}



%install

rm -rf %{buildroot}

make install DESTDIR=%{buildroot}



%clean

rm -rf %{buildroot}



%files

%defattr(-,root,root,-)    這個包括了安裝完成源碼包,會在目標目錄生成的文件,以前要先安                     裝一遍!

/usr/local/httpd/bin/*

/usr/local/httpd/build/*

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

%config /usr/local/httpd/conf/*  %config   %dir  %doc 按以下格式寫

/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         源碼包安裝完成所作的軟鏈接及優化

ln -s /usr/local/httpd/bin/* /usr/local/bin/   

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

sed -i '1a # chkconfig: 35 81 81' /etc/init.d/httpd

sed -i '2a # description:Http server by sxs' /etc/init.d/httpd

chkconfig --add httpd


%preun     刪除軟件所需步驟

/etc/init.d/httpd stop

chkconfig --del httpd

rm -rf /usr/local/httpd

rm -rf /etc/init.d/httpd



%changelog   

* Tue Feb 21 2017 Shi xiang shi <120558876@qq.com>2.2.15-1- First to 2.2.15


[root@localhost ~]$ rpmbuild httpd.spec 會提示失敗,ls一下,會多出一個rpmbuild目錄

[root@localhost ~]$ cd rpmbuild

[root@localhost ~]$ cp ../httpd-2.2.25.tar.gz SOURCES/

[root@localhost ~]$ cp ../httpd.spec SPEC/

[root@localhost ~]$ cd SPEC

[root@localhost ~]$ rpmbuild httpd.spec

[root@localhost ~]$接下來會進行編譯安裝及製做過程,製做完畢後,會在RPMS目錄生成RPM包

[root@localhost x86_64]# pwd

/home/tom/rpmbuild/RPMS/x86_64

[root@localhost x86_64]# ls

httpd-2.2.25-1.el6.x86_64.rpm

相關文章
相關標籤/搜索