首页 > 代码库 > 将源码包制作成RPM包
将源码包制作成RPM包
前言:
RPM包安装快速、方便。使用源码包可以定制想要的功能,然后将其制作成.rpm格式的包。在生产环境中,我们的开发人员通常下载好源码包,选择好自己所需功能,丢给运维人员制作rpm包后。将其丢入本地yum源库,以后直接调用安装。。。
下面我们以apache WEB源码包httpd-2.2.25.tar.gz为例,来制作RPM包。
[root@localhost ~]# ls
anaconda-ks.cfg httpd-2.2.25.tar.gz
[root@localhost ~]# yum -y install rpm-build gcc gcc-c++
[root@localhost ~]# useradd tom
[root@localhost ~]# cp httpd-2.2.25.tar.gz /home/tom/
[root@localhost ~]# su - tom
[root@localhost Packages]# rpm -qpi httpd-2.2.15-29.el6_4.x86_64.rpm
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
本文出自 “11000174” 博客,请务必保留此出处http://11010174.blog.51cto.com/11000174/1900296
将源码包制作成RPM包