1、前提php
谈到 RPM 包,可能咱们不少人都会说,RPM 包不就是执行 yum –y insyall 命令以后安装内容么,是的,没说错,但是,咱们只知道安装的时候用 yum –y install ,可是咱们是否知道 RPM 包是怎么来的么?咱们都清楚,当咱们在 Linux 服务器中安装软件时,有两种方式,一种是用 RPM 包安装,另一种是本身编译源码包来安装,众所周知,编译源码包安装是异常的麻烦,而咱们用 RPM 安装确实很简单的事,只需一条命令就 OK 了。但咱们所用的 RPM 包可都是别人封装好的,说句很差听的话,谁知道它里面有没有病毒呢?因而,在一些比较注重安全的企业中,通常都会用本身封装的 RPM 包进行安装。到这里,也许有人会问,还有这种操做?对,没错,确实有这种操做,下面,咱们就来一步步的说明 RPM 包的制做过程。html
2、准备工做mysql
俗话说,兵马未动,粮草先行,这句话一样适合与咱们的运维行业,活干的漂不漂亮,得看你工具准备的是否齐全,工具齐全,就算你是刚入门的菜鸟,不少时候也会事半功倍,工具准备的不齐全,就算是深刻运维大坑的老鸟,不少时候也会事倍功半。nginx
那么制做 RPM 包呢,首先咱们就得最好制做前的准备:web
一、安装 rpmdevtools 开发工具sql
[root@localhost ~]# yum -y install rpmdevtools
二、了解 rpmbuild 的用法数据库
既然安装了 rpmdevtools 开发工具,咱们就得知道它怎么用。其实咱们在制做 RPM 包的过程当中能用到的命令也就是 rpmbuild ,所在此,咱们了解下 rpmbuild 的用法:vim
①、rpmbuild 的参数选项,以下表:安全
②、查询宏bash
在 RPM 报纸作过程当中,会涉及到不少不少的宏,那么咱们怎么样知道这些宏都表明了什么呢?咱们可使用 rpmbuild –showrc 命令来查看,以下图:
带%的所有为宏,固然咱们可能看不懂,其实不要紧,大部分都没用到,咱们只须要了解个别几个就行,还有知道宏是用来干什么的就行。
③、宏变量的替换
若是咱们不想使用 rpmbuild 系统自带的宏变量,那么咱们能够对 rpmbuild 宏进行自定义,修改家目录下的 .rpmmacros 文件来实现,如图
④、建立工做目录
rpmbuild 必需要在特定的目录中工做,因此,咱们得先建立 rpmbuild 的工做目录,使用 rpmdev-setuptree 命令建立,会在家目录下生成名为 rpmbuild 的目录,再执行 tree rpmbuild 来查看目录结构。
[Xiaoyu@localhost ~]$ rpmdev-setuptree [Xiaoyu@localhost ~]$ tree rpmbuild rpmbuild ├── BUILD #源代码解压后的存放目录 ├── BUILDROOT #RPM 包制做过程当中临时安装目录 ├── RPMS #制做完成后的普通 RPM 包的存放目录 ├── SOURCES #全部收集的额外软件包的存放目录(包括配置文件、补丁包等等) ├── SPECS #spec文件的存放目录 └── SRPMS #制做完成后的 src 格式的 RPM 包的存放目录
3、RPM 包的制做过程
制做 rpm 包通常包含下面 4 个步骤:
一、设置好制做 rpm 包的目录结构(务必不能使用管理源进行,若是制做过程当中,某个命令写错了,那结果多是灾难性的)
二、将源文件放到特定的所规划好的目录当中
三、准备制做过程当中所须要的其余文件,并放进特定的所规划好的目录当中
四、建立一个 spec 文件,spec 文件将决定如何对源文件进行编译
六、编译源代码,生成 rpm 包
4、spec 文件解析
spec 文件作为咱们制做 RPM 包灵魂文件,若是而欧美让你不知道 spec 文件怎么写,那咱们将没法制做 RPM 包,下面,咱们就来说下 spec 文件的组成。
spec 文件分为 7 个部分
一、软件包信息说明段(The introduction section)
字段说明,如上图:
Name:软件包名称,可使用 %{name} 的方式引用
Version:软件包的版本号,务必使用 xx.yy,不能使用横线,后面也可以使用 %{version} 的宏来进行引入
Release: 1%{?dist} ,软件的发布版本,dist 这个宏是能够判断的,若是 dist 这个宏有定义,就会在软件包中带上,若是没有定义,就不会带
Summary:软件包的简单描述,能够写制做者我的 信息
Group:软件包的属组,这个组不能随便乱写,在不一样的系统上有不一样的组,可使用 cat /usr/share/doc/rpm-4.11.3/GROUPS 来查看有哪些组,如图
[Xiaoyu@localhost SPECS]$ cat /usr/share/doc/rpm-4.11.3/GROUPS Amusements/Games(娱乐/游戏) Amusements/Graphics(娱乐/图形) Applications/Archiving(应用/文档) Applications/Communications(应用/通信) Applications/Databases(应用/数据库) Applications/Editors(应用/编辑器) Applications/Emulators(应用/仿真器) Applications/Engineering(应用/工程) Applications/File(应用/文件) Applications/Internet(应用/英特网) Applications/Multimedia(应用/多媒体) Applications/Productivity(应用/产品) Applications/Publishing(应用/印刷) Applications/System(应用/系统) Applications/Text(应用/文本) Development/Debuggers(开发/调试器) Development/Languages(开发/语言) Development/Libraries(开发/函数库) Development/System(开发/系统) Development/Tools(开发/工具) Documentation(文档) System Environment/Base(系统环境/基础) System Environment/Daemons(系统环境/守护) System Environment/Kernel(系统环境/内核) System Environment/Libraries(系统环境/函数库) System Environment/Shells(系统环境/接口) User Interface/Desktops(用户界面/桌面) User Interface/X(用户界面/X窗口) User Interface/X Hardware Support(用户界面/X硬件支持)
License:受权方式,一般是GPL(自由软件)或者GPLv2,BSD,这里必定要写清楚,不然可能会侵权
URL:通常写这个 RPM 能够从哪一个地址下载到
Source0:源代码包的名字,也就是咱们制做的这个 RPM 包的原始的语言文件,格式:%{name}-%{version}.tar.gz,也能够在前面加连接地址
BuildRoot:软件的临时安装根目录,临时安装完成以后打包 RPM 包时会今后目录选择文件进行打包,打包完成以后在清理阶段会将此目录删除
BuildRequires:定义依赖关系,制做 RPM 包的过程所依赖的其余的软件包
Requires:定义依赖关系,安装这个 RPM 包因此来的其余的软件包,定义依赖关系的时候,还能够指定版本号,好比:libpng-devel >= 1.0.20 zlib、bzip2 = %{version}, bzip2-libs =%{version}、perl(Carp)>=3.2
依赖包的格式
Packager:软件报的制做者,通常写 做者+<邮箱>
Vendor:制做者所属的公司或者提供商
%description:详细的描述信息,能够写多段,使用空白行隔开
二、准备阶段(The prep section)
%prep:设定 RPM 包的宏、工做环境等等
%setup:解压软件包并进入目录,这个红还有相关的选项可用,例如,在源代码解压后,假设 %setup 宏产生的目录为 %{name}-%{version},若是当初打包的源代码中的目录不是按照这种格式命名的,可使用-n选项来指定切换目录:
%setup -q 将 tar 命令的频繁输出关闭。
%setup -n newdir 将压源代码程序软件包在 newdir 目录下解压。
%setup -c 在解压源代码程序软件包以前先建立目录。
%setup -bnum 在包含多个源代码程序软件包时,将第num个源程序解压缩。
%setup -T 不使用缺省的解压缩操做。
三、编译阶段(The build section)
%configure:是系统内置的宏
make %{?_smp_mflages}:%{?_smp_mflages} 判断有没有 smp 对称的多处理器的标志位,,若是有则使用,不然就不使用
也能够是
自定义 configure 和使用系统自带的 make 宏
四、安装阶段(The install section)
直接 make install 安装
DESTDIR=%{buildroot}:表示安装到什么地方,以谁为起点
也能够是
%{__rm} -rf %{buildroot}:每次制做过程可能会重复多遍,大多数状况下,每一遍重复会把上次安装的删除,本次在从新安装,为了不以前安装的影响本次安装,因此先删除
若是不须要编译,这里留空,也可使用 install 命令或者 copy 命令,install 命令比 copy 命令功能更强大、更易用,更容易作精确控制。关于 install 命令的使用,能够参考 man install 手册。
五、脚本段(The script section)
%pre:安装前,在 RPM 包的安装命令执行以前就要执行的脚本
%post:安装后,在 RPM 包的安装完成以后就要执行的脚本
%preun:卸载以前,卸载工做开始以前要执行的脚本
%postun:卸载以后,卸载完成以后要执行的脚本
BUILDROOT/ :全部在 BUILDROOT/ 路径下生成的文件除了 debug 文件以外通通都必需要作进 RPM 包
六、清理阶段(The clean section)
该段无关紧要,就是删除此前的制做过程所用到的 buildroot
七、文件段(The files section),用于明肯定义 RPM 包应该包含那些文件
全部 files 字段都必须以 %files 开头,files 字段底下的内容为包含进来的文件,例如:
%defattr(-, root, root, 0755):定义这些文件的默认权限
%doc:明确说明这些文件是作为文档使用的
%config:定义配置文件的路径及名称
/usr/local/bin/mysql:定义想包含的 buildroot 路径下的文件,若是想包含目录下全部文件,则写目录便可
八、版本日志段(The cheange log)
*:修改时间已经版本号
-:定义修改者
5、编写 SPEC 文件(这里咱们以制做 nginx 的 RPM 包为例)
[Xiaoyu@localhost ~]$ cd rpmbuild/SPECS [Xiaoyu@localhost ~]$ vim nginx.spec
这里只截取部分截图,以供参考,下面贴上最终 nginx.spec 文件
Name: nginx Version: 1.14.2 Release: 7%{?dist} Summary: Http Server. Group: Applications/Internet License: BSD URL: http://nginx.org Source0: http://nginx.org/download/%{name}-%{version}.tar.gz Source1: nginx BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root BuildRequires: pcre-devel,zlib-devel,openssl-devel,libxslt-devel,gd-devel Requires: pcre,openssl,gd Requires(pre): shadow-utils Requires(post): chkconfig Requires(preun): chkconfig,initscripts Provides: webserver Packager: situxiaoyu Vendor: situxiaoyu@xxx.com %description This guide gives a basic introduction to nginx and describes some simple tasks that can be done with it. It is supposed that nginx is already installed on the reader’s machine. If it is not, see the Installing nginx page. This guide describes how to start and stop nginx, and reload its configuration, explains the structure of the configuration file and describes how to set up nginx to serve out static content, how to configure nginx as a proxy server, and how to connect it with a FastCGI application. %prep %setup -q %build ./configure \ --prefix=/usr/local/nginx \ --sbin-path=/usr/sbin/nginx \ --conf-path=/usr/local/nginx/config/nginx.conf \ --error-log-path=/var/log/wwwlogs/nginx_error.log \ --http-log-path=/var/log/wwwlogs/nginx_access.log \ --pid-path=/usr/local/nginx/var/run/nginx.pid \ --lock-path=/usr/local/nginx/var/lock/nginx.lock \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-http_degradation_module \ --with-http_v2_module \ --with-http_sub_module \ --with-pcre make %{?_smp_mflags} %pre if [ $1 == 1 ];then useradd -s /bin/false -r nginx 2>/dev/null || : fi %post if [ $1 == 1 ];then chkconfig --add %{name} service %{name} start fi %preun if [ $1 == 0 ];then service %{name} stop >/dev/null 2>&1 chkconfig --del %{name} userdel nginx groupdel nginx fi %postun %{__rm} -rf /usr/local/nginx %{__rm} -rf /etc/init.f/nginx %{__rm} -rf /var/log/wwwlogs %{__rm} -rf /var/log/nginx %{__rm} -rf /var/run/nginx %install %{__rm} -rf %{buildroot} make install DESTDIR=%{buildroot} install -p -d -m 0755 %{buildroot}/var/log/wwwlogs install -p -d -m 0755 %{buildroot}/var/run/nginx install -p -d -m 0755 %{buildroot}/var/log/nginx install -p -d -m 0755 %{buildroot}/usr/local/nginx/var/run install -p -d -m 0755 %{buildroot}/usr/local/nginx/var/lock install -p -D -m 0755 %{SOURCE1} %{buildroot}/etc/rc.d/init.d/nginx install -p -D -m 0755 %{SOURCE1} %{buildroot}/etc/init.d/nginx %clean %{__rm} -rf %{buildroot} %files %defattr(-, root, root, 0755) %doc LICENSE CHANGES README %{_sbindir}/%{name} %dir /var/run/nginx %dir /var/log/nginx %dir /usr/local/nginx/config %config(noreplace) /usr/local/nginx/config/fastcgi.conf %config(noreplace) /usr/local/nginx/config/fastcgi_params %config(noreplace) /usr/local/nginx/config/koi-utf %config(noreplace) /usr/local/nginx/config/koi-win %config(noreplace) /usr/local/nginx/config/mime.types %config(noreplace) /usr/local/nginx/config/nginx.conf %config(noreplace) /usr/local/nginx/config/scgi_params %config(noreplace) /usr/local/nginx/config/uwsgi_params %config(noreplace) /usr/local/nginx/config/win-utf %config(noreplace) /usr/local/nginx/config/fastcgi.conf.default %config(noreplace) /usr/local/nginx/config/fastcgi_params.default %config(noreplace) /usr/local/nginx/config/mime.types.default %config(noreplace) /usr/local/nginx/config/nginx.conf.default %config(noreplace) /usr/local/nginx/config/scgi_params.default %config(noreplace) /usr/local/nginx/config/uwsgi_params.default #%attr(0755, root, root) %{_initrddir}/%{name} %attr(0755, root, root) /etc/rc.d/init.d/nginx %attr(0755, root, root) /etc/init.d/nginx /usr/local/nginx/html/50x.html /usr/local/nginx/html/index.html %changelog * Mon Dec 17 2018 nginx.org <situxiaoyu@xxx.com> - 1.14.2-1 - Install version
说明:此文件可根据我的安装需求进行自定义修改
6、构建RPM包(咱们先进行分段执行)
一、执行 rpmbuild -bp nginx.spec(执行到%prep段),提示咱们没有安装依赖包(rpmbuild 命令会自动检查依赖关系)
咱们根据提示,安装所需的依赖包
[root@localhost ~]# yum -y install pcre-devel zlib-devel openssl-devel libxslt-devel gd-devel
二、依赖包安装完后,在执行一次 rpmbuild -bp nginx.spec 命令,发现正常了,没有报错
[Xiaoyu@localhost SPECS]$ rpmbuild -bp nginx.spec
三、上面执行正常,咱们再执行 rpmbuild -bc nginx.spec 命令(执行到%build段),结果又报错了,以下图:
[Xiaoyu@localhost SPECS]$ rpmbuild -bc nginx.spec
如上图:
通常状况下,咱们不会太在乎图中 1 的部分的 nginx 选项问题,而是直接查找 二、3 部分的错误缘由。可是,在这里,若是咱们没有认真看的话,是很难肯定为何会报错,其实仔细看一下,发现之因此报错,就是由于咱们写的 nginx 编译参数无效,删掉该无效参数便可。
四、删除报错中提示的参数,咱们再执行 rpmbuild -bc nginx.spec 命令,发现一切正常,以下图:
五、既然上一步没有问题了,咱们就开始进行下一步,执行 rpmbuild -bi nginx.spec 命令
发现上图所示错误,同第三步同样的分析方法,只是这里是找不到文件或目录,咱们再检查下 nginx.spec 文件,发现咱们的 %build 段 --sbin-path 路径定义错了,改为 --sbin-path=/usr/bin/nginx 便可
六、再次执行 rpmbuild -bi nginx.spec 命令
如上图,又报错了,提示存在未打包的文件,根据提示,未打包的均为配置文件,咱们将提示中的文件所有添加到 nginx.spec 文件的 files 段中去,以下图
%dir:表示后面的内容是一个目录
%config:表示该文件为配置文件,文件被覆盖为新版本文件,原修改后的文件保存为*.rpmsave
noreplace:表示文件不被覆盖,新rpm包里的文件被保存为 *.rpmnew
七、添加完毕后,再执行一次上面的 rpmbuild -bi nginx.spec 命令
结果如上图,提示没有打包 /usr/local/nginx/html/50x.html、/usr/local/nginx/html/index.html 这两个文件,那么咱们再把这两个文件添加到 nginx.spec 文件的 files 段中去
如上图,添加完后保存退出,从新执行 rpmbuild -bi nginx.spec 命令
我滴个乖乖,此次终于成功了,不容易啊,怀着激动的当心情,咱们开始进行下一步,打包 RPM 包。
既然都已经成功了,那咱们就开是打包 RPM 包吧,执行 rpmbuild -bb nginx.spec 命令
如上图所示,顺利完成,到 RPMS 目录中查看一下是否有生成 RPM 包
[Xiaoyu@localhost SPECS]$ cd ../RPMS/x86_64/ [Xiaoyu@localhost x86_64]$ ll
如 上图,发现有生成两个包,一个带 debuginfo ,一个不带,其实咱们能用到的是没带 debuginfo 的那个包,带 debuginfo 的包是用来调试的,咱们在此能够忽略。
八、RPM 包既然已经生成了,那咱们安装一下呗,看看咱们本身制做的 RPM 包可否安装成功
[root@localhost x86_64]# rpm -ivh nginx-1.14.2-1.el7.x86_64.rpm
惋惜啊,如上图,安装成功,可是启动报错,根据报错内容,咱们大概能知道 2 个问题
①、没有服务启动的脚本文件
②、启动服务的命令有误(命令有误,是由于没有启动脚本)
既然知道存在这两个问题,咱们就好下手了,再次编辑 nginx.spec 文件
首先,如上两图,添加 source 源,而且安装(注意:这里再引用 Source 的时候,必需要大写,这是约定的,若是不大写,则会报错。固然,安装可没必要写两条,有其中一条就行。),再以下图,将两个文件添加到 files 段中。
%attr:表示定义单个文件的属性,若是不写,就继承了默认属性
其次切换到 SOURCES 目录下编写服务启动的脚本文件(此时,还脚本文件能够随便命名,可是安装后,必须为 nginx。)
[root@localhost SOURCES]# vim nginx #! /bin/sh # chkconfig: 2345 55 25 # Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and # run 'update-rc.d -f nginx defaults', or use the appropriate command on your # distro. For CentOS/Redhat run: 'chkconfig --add nginx' ### BEGIN INIT INFO # Provides: nginx # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts the nginx web server # Description: starts nginx using start-stop-daemon ### END INIT INFO # Author: licess # website: https://lnmp.org PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin NAME=nginx NGINX_BIN=/usr/sbin/$NAME CONFIGFILE=/usr/local/nginx/config/$NAME.conf PIDFILE=/usr/local/nginx/var/run/$NAME.pid if [ -s /bin/ss ]; then StatBin=/bin/ss else StatBin=/bin/netstat fi case "$1" in start) echo -n "Starting $NAME... " if $StatBin -tnpl | grep -q nginx;then echo "$NAME (pid `pidof $NAME`) already running." exit 1 fi $NGINX_BIN -c $CONFIGFILE if [ "$?" != 0 ] ; then echo " failed" exit 1 else echo " done" fi ;; stop) echo -n "Stoping $NAME... " if ! $StatBin -tnpl | grep -q nginx; then echo "$NAME is not running." exit 1 fi $NGINX_BIN -s stop if [ "$?" != 0 ] ; then echo " failed. Use force-quit" exit 1 else echo " done" fi ;; status) if $StatBin -tnpl | grep -q nginx; then PID=`pidof nginx` echo "$NAME (pid $PID) is running..." else echo "$NAME is stopped." exit 0 fi ;; force-quit|kill) echo -n "Terminating $NAME... " if ! $StatBin -tnpl | grep -q nginx; then echo "$NAME is is stopped." exit 1 fi kill `pidof $NAME` if [ "$?" != 0 ] ; then echo " failed" exit 1 else echo " done" fi ;; restart) $0 stop sleep 1 $0 start ;; reload) echo -n "Reload service $NAME... " if $StatBin -tnpl | grep -q nginx; then $NGINX_BIN -s reload echo " done" else echo "$NAME is not running, can't reload." exit 1 fi ;; configtest) echo -n "Test $NAME configure files... " $NGINX_BIN -t ;; *) echo "Usage: $0 {start|stop|restart|reload|status|configtest|force-quit|kill}" exit 1 ;; esac
说明:此配置文件必须按照 spec 文件的设置来修改。
最后再切换到 SPECS 目录,执行一次 rpmbuild -bb nginx.spec 命令
九、再次安装咱们上一步生成的 RPM 包
[root@localhost x86_64]# rpm -ivh nginx-1.14.2-1.el7.x86_64.rpm
如上图,成功了,查看下 nginx 进程和端口是否存在
如上图,端口和服务均存在,安装正常。
十、Nginx 的 RPM 包整合 php
在实际环境中,咱们每每要将 nginx 和 php 搭配使用,也就是传说的 lnmp 环境,可是咱们以前所制做的 nginx 的 RPM 包是不能链接 php 的,由于咱们没有对 php 的环境进行相关定义,所以咱们须要从新制做 RPM 包,在本次制做中咱们加入 params 文件。
编辑 params 文件
[Xiaoyu@localhost SPECS]$ vim ../SOURCES/nginx.params fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name;
从新编辑 nginx.spec 文件,在特定的为止加入如下内容
Source2: nginx.params %install mv %{buildroot}/usr/local/nginx/config/fastcgi_params %{buildroot}/usr/local/nginx/config/fastcgi_params.oldinstall -p -D -m 0644 %{SOURCE2} %{buildroot}/usr/local/nginx/config/fastcgi_params %files %config(noreplace) /usr/local/nginx/config/fastcgi_params.old %attr(0655, root, root) /usr/local/nginx/config/fastcgi_params
最终完整版的 nginx.spec 文件粘贴以下:
Name: nginx Version: 1.14.2 Release: 2%{?dist} Summary: Http Server. Group: Applications/Internet License: BSD URL: http://nginx.org Source0: http://nginx.org/download/%{name}-%{version}.tar.gz Source1: nginx Source2: nginx.params BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root BuildRequires: pcre-devel,zlib-devel,openssl-devel,libxslt-devel,gd-devel Requires: pcre,openssl,gd Requires(pre): shadow-utils Requires(post): chkconfig Requires(preun): chkconfig,initscripts Provides: webserver Packager: situxiaoyu Vendor: situxiaoyu@.com %description This guide gives a basic introduction to nginx and describes some simple tasks that can be done with it. It is supposed that nginx is already installed on the reader’s machine. If it is not, see the Installing nginx page. This guide describes how to start and stop nginx, and reload its configuration, explains the structure of the configuration file and describes how to set up nginx to serve out static content, how to configure nginx as a proxy server, and how to connect it with a FastCGI application. %prep %setup -q %build ./configure \ --prefix=/usr/local/nginx \ --sbin-path=/usr/sbin/nginx \ --conf-path=/usr/local/nginx/config/nginx.conf \ --error-log-path=/var/log/wwwlogs/nginx_error.log \ --http-log-path=/var/log/wwwlogs/nginx_access.log \ --pid-path=/usr/local/nginx/var/run/nginx.pid \ --lock-path=/usr/local/nginx/var/lock/nginx.lock \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-http_degradation_module \ --with-http_v2_module \ --with-http_sub_module \ --with-pcre make %{?_smp_mflags} %pre if [ $1 == 1 ];then useradd -s /bin/false -r nginx 2>/dev/null || : fi %post if [ $1 == 1 ];then chkconfig --add %{name} service %{name} start fi %preun if [ $1 == 0 ];then service %{name} stop >/dev/null 2>&1 chkconfig --del %{name} userdel ngix groupdel nginx fi %postun %{__rm} -rf /usr/local/nginx %{__rm} -rf /etc/init.f/nginx %{__rm} -rf /var/log/wwwlogs %{__rm} -rf /var/log/nginx %{__rm} -rf /var/run/nginx %install %{__rm} -rf %{buildroot} make install DESTDIR=%{buildroot} install -p -d -m 0755 %{buildroot}/var/log/wwwlogs install -p -d -m 0755 %{buildroot}/var/run/nginx install -p -d -m 0755 %{buildroot}/var/log/nginx install -p -d -m 0755 %{buildroot}/usr/local/nginx/var/run install -p -d -m 0755 %{buildroot}/usr/local/nginx/var/lock install -p -D -m 0755 %{SOURCE1} %{buildroot}/etc/rc.d/init.d/nginx install -p -D -m 0755 %{SOURCE1} %{buildroot}/etc/init.d/nginx mv %{buildroot}/usr/local/nginx/config/fastcgi_params %{buildroot}/usr/local/nginx/config/fastcgi_params.old install -p -D -m 0644 %{SOURCE2} %{buildroot}/usr/local/nginx/config/fastcgi_params %clean %{__rm} -rf %{buildroot} %files %defattr(-, root, root, 0755) %doc LICENSE CHANGES README %{_sbindir}/%{name} %dir /var/run/nginx %dir /var/log/nginx %dir /usr/local/nginx/config %config(noreplace) /usr/local/nginx/config/fastcgi.conf %config(noreplace) /usr/local/nginx/config/fastcgi_params %config(noreplace) /usr/local/nginx/config/fastcgi_params.old %config(noreplace) /usr/local/nginx/config/koi-utf %config(noreplace) /usr/local/nginx/config/koi-win %config(noreplace) /usr/local/nginx/config/mime.types %config(noreplace) /usr/local/nginx/config/nginx.conf %config(noreplace) /usr/local/nginx/config/scgi_params %config(noreplace) /usr/local/nginx/config/uwsgi_params %config(noreplace) /usr/local/nginx/config/win-utf %config(noreplace) /usr/local/nginx/config/fastcgi.conf.default %config(noreplace) /usr/local/nginx/config/fastcgi_params.default %config(noreplace) /usr/local/nginx/config/mime.types.default %config(noreplace) /usr/local/nginx/config/nginx.conf.default %config(noreplace) /usr/local/nginx/config/scgi_params.default %config(noreplace) /usr/local/nginx/config/uwsgi_params.default #%attr(0755, root, root) %{_initrddir}/%{name} %attr(0755, root, root) /etc/rc.d/init.d/nginx %attr(0755, root, root) /etc/init.d/nginx %attr(0655, root, root) /usr/local/nginx/config/fastcgi_params /usr/local/nginx/html/50x.html /usr/local/nginx/html/index.html %changelog * Tue Dec 18 2018 nginx.org <situxiaoyu@xx.com> - 1.14.2-2 - Install version * Mon Dec 17 2018 nginx.org <situxiaoyu@xx.com> - 1.14.2-1 - Install version
通过以上不停的尝试踩坑与填坑,我想咱们应该可以制做简单 RPM 包了,孰能生巧,作的多了,咱们也就天然明白了
7、总结
RPM 包的制做,关键在于 spec 文件的编写,对于 spec 文件如何编写,咱们刚开始不会,能够照着例子边写边测,通常来讲,若是有问题,测试时系统都能给出比较明确的错误缘由,只要咱们仔细的去发现,当不能被表象所迷惑。