源码包制作成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 <zsp@tarena.com> 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  ~]#