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.specName: nginxVersion: 1.4.7Release: 1%{?dist}Summary: nginx rmp package productionGroup: Applications/ArchivingLicense: GPLv2URL: http://www.nginx.orgSource: http://nginx.org/download/nginx-1.4.7.tar.gzBuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)BuildRequires: gccRequires: openssl,openssl-devel,pcre-devel,pcre%descriptionCustom nginx rpm package%preprm -rf $RPM_BUILD_DIR/nginx-1.4.7tar fx $RPM_SOURCE_DIR/nginx-1.4.7.tar.gz%buildcd nginx-1.4.7./configure \--prefix=/home/application/nginx \--with-http_ssl_module \--with-http_stub_status_module \--with-http_gzip_static_modulemake %{?_smp_mflags}%installrm -rf %{buildroot}cd nginx-1.4.7make install DESTDIR=%{buildroot}%cleanrm -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.rpmLoaded plugins: fastestmirrorSetting up Install ProcessExamining /root/rpmbuild/RPMS/x86_64/nginx-1.4.7-1.el6.x86_64.rpm: nginx-1.4.7-1.el6.x86_64Marking /root/rpmbuild/RPMS/x86_64/nginx-1.4.7-1.el6.x86_64.rpm to be installedLoading mirror speeds from cached hostfile * base: mirrors.btte.net * epel: ftp.riken.jp * extras: mirrors.btte.net * updates: mirrors.btte.netResolving Dependencies--> Running transaction check---> Package nginx.x86_64 0:1.4.7-1.el6 will be installed--> Finished Dependency ResolutionDependencies Resolved================================================================================================================================================================================================================== Package Arch Version Repository Size==================================================================================================================================================================================================================Installing: nginx x86_64 1.4.7-1.el6 /nginx-1.4.7-1.el6.x86_64 732 kTransaction Summary==================================================================================================================================================================================================================Install 1 Package(s)Total size: 732 kInstalled size: 732 kDownloading Packages:Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction Installing : nginx-1.4.7-1.el6.x86_64 1/1 Verifying : nginx-1.4.7-1.el6.x86_64 1/1Installed: nginx.x86_64 0:1.4.7-1.el6 Complete!
至此,nginx的RPM包制作完成,并成功安装......大家可以举一反三制作其他软件的RPM包。
本文出自 “命运.” 博客,请务必保留此出处http://hypocritical.blog.51cto.com/3388028/1694545