RPM是RedHat Package Manager(RedHat软件包管理工具)的缩写,是一种用于互联网下载包的打包及安装工具,它包含在某些Linux分发版中。它生成具有.RPM扩展名的文件。使用rpm安装软件和管理软件非常的方便。
1.安装rpm-build
[root@YunWei-136 ~]# yum -y install rpm-build redhat-rpm-config
2.建立目录结构
[root@YunWei-136 ~]# mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} [root@YunWei-136 ~]# tree -n ~/rpmbuild/ /root/rpmbuild/ ├── BUILD 存放源代码 ├── RPMS 存放用于管理rpm制作进程的spec文件 ├── SOURCES 解压后的文件存放在这里 ├── SPECS 存放由rpmbuild制作好的二进制包 └── SRPMS 存放由rpmbuild制作好的源码包 5 directories, 0 files
3.下载源码包
[root@YunWei-136 ~]# wget -P ~/rpmbuild/SOURCES/ http://nginx.org/download/nginx-1.4.7.tar.gz
4.制作.spec文件
[root@YunWei-136 ~]# cd ~/rpmbuild/SPECS [root@YunWei-136 SPECS]# vim nginx.specs Name: nginx Version: 1.4.7 Release: 1%{?dist} Summary: nginx rmp package production Group: Applications/Archiving License: GPLv2 URL: http://www.nginx.org Source: http://nginx.org/download/nginx-1.4.7.tar.gz BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) BuildRequires: gcc Requires: openssl,openssl-devel,pcre-devel,pcre %description Custom nginx rpm package %prep rm -rf $RPM_BUILD_DIR/nginx-1.4.7 tar fx $RPM_SOURCE_DIR/nginx-1.4.7.tar.gz %build cd nginx-1.4.7 ./configure --prefix=/home/application/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module make %{?_smp_mflags} %install rm -rf %{buildroot} cd nginx-1.4.7 make install DESTDIR=%{buildroot} %clean rm -rf %{buildroot} %files %defattr(-,root,root,-) /home/application/nginx
5.spec文件解释
#:以#开头是注释,rpm会忽略它。 Summary: 简单描述软件。 Name : 定义rpm的名称。 Version: 定义软件版本 Release: 发行版本 License: 定义许可证 Group: 软件分类 Source: 源码下载地址 URL: 源码相关网站 Distribution: 发行版系列 Packager: 打包人的信息 %description:软件详细描述,可多行 %prep :软件编译之前的处理,如解压。 %build :开始编译软件,如make %install :开始安装软件,如make install %files :指定哪些文件需要被打包,如/usr/local/nginx %preun :定义卸载之前的动作,如杀掉进程。 这里只介绍了几个常用的tag,更详细的请参考:http://www.rpm.org/max-rpm/ch-rpm-inside.html
6.开始RPM制作
[root@YunWei-136 SPECS]# rpmbuild -bb nginx.spec
6.测试RPM包
[root@YunWei-136 SPECS]# yum -y install /root/rpmbuild/RPMS/x86_64/nginx-1.4.7-1.el6.x86_64.rpm Loaded plugins: fastestmirror Setting up Install Process Examining /root/rpmbuild/RPMS/x86_64/nginx-1.4.7-1.el6.x86_64.rpm: nginx-1.4.7-1.el6.x86_64 Marking /root/rpmbuild/RPMS/x86_64/nginx-1.4.7-1.el6.x86_64.rpm to be installed Loading mirror speeds from cached hostfile * base: mirrors.btte.net * epel: ftp.riken.jp * extras: mirrors.btte.net * updates: mirrors.btte.net Resolving Dependencies --> Running transaction check ---> Package nginx.x86_64 0:1.4.7-1.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================================================================================================== Package Arch Version Repository Size ================================================================================================================================================================================================================== Installing: nginx x86_64 1.4.7-1.el6 /nginx-1.4.7-1.el6.x86_64 732 k Transaction Summary ================================================================================================================================================================================================================== Install 1 Package(s) Total size: 732 k Installed size: 732 k Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : nginx-1.4.7-1.el6.x86_64 1/1 Verifying : nginx-1.4.7-1.el6.x86_64 1/1 Installed: nginx.x86_64 0:1.4.7-1.el6 Complete!
至此,nginx的RPM包制作完成,并成功安装......大家可以举一反三制作其他软件的RPM包。
本文出自 “命运.” 博客,请务必保留此出处http://hypocritical.blog.51cto.com/3388028/1694545
原文地址:http://hypocritical.blog.51cto.com/3388028/1694545