rpm包制作之——nginx

来源:互联网 发布:强生隐形眼镜 知乎 编辑:程序博客网 时间:2024/06/04 18:07

环境:CentOS release 6.5

rpmbuild安装

# yum install -y rpmdevtools rpm-build

创建一个RPM构建根目录结构(默认将再当前用户主目录下),如果需要改变次默认位置,可以修改配置文件:~/.rpmmacros中变量_topdir对应

# rpmdev-setuptree

查看所有的宏

# rpmbuild –showrc

目录结构

--BUILD #编译之前,如解压包后存放的路径--BUILDROOT #编译后存放的路径--RPMS #打包完成后rpm包存放的路径--SOURCES #源包所放置的路径--SPECS #spec文档放置的路径--SPRMS #源码rpm包放置的路径自动配置命令创建一个RPM构建根目录结构,并配置一些必要操作。

rpmbuild命令的用法:

1 从spec文档建立有以下选项:

-bp  #只执行spec的%pre 段(解开源码包并打补丁,即只做准备)-bc  #执行spec的%pre和%build 段(准备并编译)-bi  #执行spec中%pre,%build与%install(准备,编译并安装)-bl  #检查spec中的%file段(查看文件是否齐全)-ba  #建立源码与二进制包(常用)-bb  #只建立二进制包(常用)-bs  #只建立源码包

2 从tarball包建立,与spec类似

-tp #对应-bp-tc #对应-bc-ti #对应-bi-ta #对应-ba-tb #对应-bb-ts #对应-bs

3 从源码包建立

--rebuild  #建立二进制包,通-bb--recompile  #同-bi* rpmbuild的其他参数--buildroot=DIRECTORY   #确定以root目录建立包--clean  #完成打包后清除BUILD下的文件目录--nobuild  #不进行%build的阶段--nodeps  #不检查建立包时的关联文件--nodirtokens--rmsource  #完成打包后清除SOURCES--rmspec #完成打包后清除SPEC--short-cricuit--target=CPU-VENDOR-OS #确定包的最终使用平台

软件包所属类别,具体类别有:

# less /usr/share/doc/rpm-4.8.0/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硬件支持)

其他

make %{?_smp_mflags}
它就自动将软件安装时的路径自动设置成如下约定:
可执行程序/usr/bin
依赖的动态库/usr/lib或者/usr/lib64视操作系统版本而定。
二次开发的头文件/usr/include
文档及手册/usr/share/man

%setup 不加任何选项,仅将软件包打开。
%setup -n newdir 将软件包解压在newdir目录。
%setup -c 解压缩之前先产生目录。
%setup -b num 将第num个source文件解压缩。
%setup -T 不使用default的解压缩操作。
%setup -T -b 0 将第0个源代码文件解压缩。
%setup -c -n newdir 指定目录名称newdir,并在此目录产生rpm套件。
%patch 最简单的补丁方式,自动指定patch level。
%patch 0 使用第0个补丁文件,相当于%patch ?p 0。
%patch -s 不显示打补丁时的信息。
%patch -T 将所有打补丁时产生的输出文件删除。

/sbin/install-info –delete %{_infodir}/%{name}.info %{_infodir}/dir 2> /dev/null || :
These two scriptlets tell install-info to add entries for the info pages to the main index file on installation and remove them at erase time. The “|| :” in this case prevents failures that would typically affect systems that have been configured not to install any %doc files, or have read-only mounted, %_netsharedpath /usr/share.

Nginx rpm

# vim ~/rpmbuild/SPECS/httpd.spec

Name:   nginx   # 软件包名称Version:    1.9.9   # 版本号,(不能使用-)Release:    1%{?dist}   # release号,对应下面的changelog,如 nginx-1.9.9-1.el6.x86_64.rpmSummary:    nginx_install   # 简要描述信息Group:  System Environment/Daemons License:    GPLv2URL:    http://nginx.org/downloadSource0:    %{name}-%{version}.tar.gz   # source主要是引用一下自己定义好的脚本,配置文件之类的内容Source1:    nginx_initSource2:    nginx.confBuildRoot:  %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)BuildRequires:  gcc,gcc-c++,pcre-devel,zlib-devel,make,openssl-devel,gd-develRequires:   pcre-devel,zlib-devel,openssl-devel,gd-devel#软件包详述%descriptionBuild nginx-1.9.9.tar.gz to nginx-1.9.9.rpm#构建包前的处理%prep#静默模式解压并cd%setup -q#生成:这里主要是构建二进制包的的时候执行编译生成二进制文件%build export DESTDIR=%{buildroot}./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid  --lock-path=/var/lock/nginx.lock --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre --with-http_image_filter_module --with-file-aio# 多处理器的话,可以加 -j 参数make %{?_smp_mflags}#构建的时候把当前文件安装到系统目录$RPM_BUILD_ROOT/下,二进制安装的时候是安装文件到/根目录下    %installrm -rf %{buildroot}make install DESTDIR=%{buildroot}#%{__install}这个宏代表install命令%{__install} -p -D -m 0755 %{SOURCE1} %{buildroot}/etc/rc.d/init.d/nginx%{__install} -p -D %{SOURCE2} %{buildroot}/etc/nginx/nginx.conf#rpm安装前执行的脚本#$1有3个值,代表动作,安装类型,处理类型 1:表示安装 2:表示升级 0:表示卸载%preif [ $1 == 1 ];then    /usr/sbin/groupadd nginx 2> /dev/null    /usr/sbin/useradd -g nginx -M -s /sbin/nologin nginx 2> /dev/nullfi#rpm安装后执行的脚本%postif [ $1 == 1 ];then    /sbin/chkconfig --add nginx    /sbin/install-info %{_infodir}/%{name}.info %{_infodir}/dir 2> /dev/null || :    mkdir -p /var/log/nginx/    touch /var/log/nginx/error.log /var/log/nginx/access.log    mkdir -p /var/run/nginx/    touch /var/run/nginx/nginx.pidfi#rpm卸载前执行的脚本%preunif [ $1 == 0 ];then    /usr/sbin/groupdel nginx 2> /dev/null    /usr/sbin/userdel -r nginx 2> /dev/null    /sbin/chkconfig --del nginx 2> /dev/null    /etc/init.d/nginx stop > /dev/null 2>&1    /sbin/install-info --delete %{_infodir}/%{name}.info %{_infodir}/dir 2> /dev/null || :fi#rpm卸载后执行的脚本%postun#清理段,clean的主要作用就是删除BUILD%cleanrm -rf %{buildroot}#文件列表段,这个阶段是把前面已经编译好的内容要打包了,其中exclude是指要排除什么不打包进来%files#%%defattr (-,root,root) 指定包装文件的属性,分别是(mode,owner,group),-表示默认值,对文本文件是0644,可执行文件是0755%defattr(-,root,root,-)/etc/nginx/%attr(0755,root,root) /etc/rc.d/init.d/nginx%config(noreplace) /etc/nginx/nginx.conf#/usr/html/index.html#/usr/html/50x.html/usr/local/nginx/html/50x.html/usr/local/nginx/html/index.html/usr/sbin/nginx%doc#变更日志%changelog*  Thu Dec 01 2016 tian <tangytchn@foxmail.com> - 1.9.9-1.el6- Initial version
0 0
原创粉丝点击