Many of my friends asked me how to create an RPM package, but they could not make the compiled software directories on other servers complicated to apply them directly on other servers... Here is a brief introduction, which is not advanced and complex.
This method is to compile the spec file and use rpmbuild to package an RPM.
Take nginx as an Example
Production Platform: centos 5.x x86_64
Step 4:
Step 1: create a directory structure-
Mkdir/usr/src/RedHat/{sources, Specs, build, rpms, srpms}-P
Related directory introduction:
/Usr/src/RedHat/sources # Store source code, patches, and other files/usr/src/RedHat/specs # store spec files for managing RPM production processes/usr/src/RedHat/ build # The decompressed file storage directory/usr/src/RedHat/RPMS # store the binary package prepared by rpmbuild/usr/src/RedHat/srpms # store the source package prepared by rpmbuild step 2: place the source code package in the sources directory
CD/usr/src/RedHat/sources
Wget http://nginx.org/download/nginx-1.2.0.tar.gz
Step 3: generate the nginx. spec File
CD/usr/src/RedHat/specs cat nginx. spec # spec file for nginx # Build 2012-07-17 # By opsren # Summary: High Performance Web server name: nginx version: 1.2 Release: 0. el5.ngx license: 2-clause BSD-like license group: Applications/Server Source: http://nginx.org/download/nginx-1.2.0.tar.gz URL: http://nginx.org distribution: centos/RedHat packager: qiuzhijun <250621008@qq.com> % description nginx ("engine X") is a high performance HTTP and reverse proxy server, as well as a mail (IMAP/POP3/SMTP) proxy server. % prep tar zxf $ rpm_source_dir/nginx-1.2.0.tar.gz % build CD nginx-1.2.0. /configure -- prefix =/usr/local/webserver/nginx -- with-http_stub_status_module -- with-http_ssl_module -- With-PCRE -- lock-Path =/var/run/nginx. lock -- PID-Path =/var/run/nginx. PID make % install CD nginx-1.2.0 make install % preun if [-z "'ps aux | grep nginx | grep-V grep '"]; then pkill nginx>/dev/null exit 0 fi % files/usr/local/webserver/nginx Step 4: Create an RPM package
First, the system must install the necessary production tools: GCC, rpmbuild, etc.
Yum-y install GCC rpm-build PCRE-devel CD/usr/src/RedHat/specs/rpmbuild-BB nginx. spec uses the above command to generate the nginx-1.2.0-1.el5.ngx.x86_64.rpm file under/usr/src/RedHat/RPMS/x86_64/
-The BB option is used to create a Binary Package (build Binary Package only from <specfile>)
Briefly describe the spec file content:
Spec file is the core of RPM package creation!
NOTE Information starting with #. Summary: a brief description of the Software. Name: defines the name of the RPM package. Version: defines the software version. Release: release version. License: defines the license group: description of the Application Type of the software source: software source code URL: software-related official site distribution: Release packager series: simple information of the producer % Description: Detailed description of the software % prep: process before software compilation % build: compile software % install: Install software % preun: define action before uninstallation % files: Specify the software package to be packaged, here is/usr/local/webserver/nginx for more detailed instructions, please refer to the official information: http://www.rpm.org/max-rpm/ch-rpm-inside.html
The following is an Apache spec file instance:
# Spec file for Apache # Build 2012-07-17 # By opsren # Summary: High Stability web server name: Apache version: 2.2 release: 22. el5license: 2-clause BSD-like license group: Applications/Server Source: http://apache.etoak.com/httpd/httpd-2.2.22.tar.gz URL: http://apache.org distribution: centos/RedHat packager: qiuzhijun <250621008@qq.com> % description Apache is a first web server % prep tar zxf $ R Pm_source_dir/httpd-2.2.22.tar.gz % build CD httpd-2.2.22. /configure -- prefix =/usr/local/webserver/Apache -- enable-so -- enable-Deflate -- enable-headers -- enable-mod-shared = all -- enable-Rewrite make % install CD httpd-2.2.22 make install % preun if [-z "'ps aux | grep httpd | grep-V grep'"]; then pkill httpd>/dev/null exit 0 fi % files/usr/local/webserver/Apache later, you can install and deploy rpm on the same or similar platforms on other servers.
There is also an RPM packaging method: rpm_create
This is a new RPM tool. You only need simple shell commands to complete the packaging operation without the spec language. It is very convenient to combine the spec language and checkinstall, this method is much simpler than spec!
Official station: http://code.google.com/p/rpmcreate/
Download Site: wget http://rpmcreate.googlecode.com/files/rpm_create-1.7.5-9.x86_64.rpm
You can go to the official site for reference!
This article from the Linux community website (www.linuxidc.com) original link: http://www.linuxidc.com/Linux/2012-09/70096.htm