这样,整个套件的内容就会被放到/usr/local/xxx中,可根据情况编写%file和%exclude段。
一.RPM制作步骤
我们在企业中有的软件基本都是编译的,我们每次安装都得编译,那怎么办呢?那就根据我们的需求制作RPM安装包吧。先来说说基本布骤:
1.Planning what you want 计划做什么rpm包。软件的?库的?
2.Gathering the software to package 收集原材料,即收集源码包
3.Patch the software as need 如果需要打补丁,收集补丁文件。此布骤不是必须
4.Outling any dependenies 确定依赖关系包
------------------ 上述动作可由我们手动编译一次软件来确定 -------------------
5.Building RPMs 开始动手制作RPM包
5.1 Set up the directory stucture 设定好目录结构,我们在这些目录中制作我们的RPM包,我们需要下列目录
BUILD 源代码解压后的存放目录
RPMS 制作完成后的RPM包存放目录,里面有与平台相关的子目录
SOURCES 收集的源材料,补丁的存放位置
SPECS SPEC文件存放目录
SRMPS 存放SRMPS生成的目录
5.2 Place the Sources in the right directory 把源材料放到正确的位置
5.3 Create a spec file that tell rpmbuild command what to do 创建spec文件,这是纲领文件,rpmbuild命令根据spec文件来制作合适的rpm包
5.4 Build the source and binary RPMS 制作src或二进制rpm包
6.Test RPMS 测试制作的PRM包
7.Add signature for RPM 为RPM包签名
二.RPM包制作实例
我还是用连贯的 话为大家叙述一遍吧,我们首先确实我们要为什么做rpm包,通常我们是为一些软件,比如httpd,nginx等,然后去收集这些软件包的源代码,如果有 需要的话也收集这些补丁文件,手动编译安装一下这个软件(当然如果是不需要编译的就不用演练了),确定依赖的软件包,并记录下来,下面开始准备制作 tengine的PRM包吧:
1.建立一个普通用户,有普通用户来制作rpm,用root的可能会因为代码问题导致毁灭的后果
2.确定我们在 哪个目录下制作RPM,通常这个目录我们topdir,这个需要在宏配置文件中指定,这个配置文件称为macrofiles,它们通常为 /usr/lib/rpm/macros:/usr/lib/rpm/macros.*:~/.rpmmacros,这个在rhel 5.8中可以通过rpmbuild --showrc | grep macrofiles 查看,6.3的我使用这个找不到,但使用是一样的。你可以通过rpmbuild --showrc | grep topdir 查看你系统默认的工作车间
我们还是自定义工作目录(或车间)吧
3.在topdir下建立需要的目录
4.把收集的源码放到SOURCES下
5.在SPECS下建立重要的spec文件
6.用rpmbuild命令制作rpm包,rpmbuild命令会根据spec文件来生成rpm包
我们可以一步步试,先rpmbuild -bp ,再-bc 再-bi 如果没问题,rpmbuild -ba 生成src包与二进制包吧
7.安装测试有没有问题,能否正常安装运行,能否正常升级,卸载有没有问题
root用户测试安装:
8.如果没问题为rpm包签名吧,防止有人恶意更改 ##这个先不写了,有点晚了,以后补上
到此整个流程完毕。下面来说说其中最最重要的spec的格式,先说最简单的,最容易实现的
到此一个简单的tengine RPM包制作好了。
三.RPM包制作拓展
下面我们来拓展一下,比如:我们想为tengine增加控制脚本,可以通过 start|stop控制,我们还想更换一下默认的首页index.html,默认的fastcgi_params是不能直接连接php的,所以我们替换 为新的配置文件,我们也可以用设置好的nginx.conf替换原来的nginx.conf。基于上述步骤下面继续
1.把修改后的首页文件index.html,控制脚本init.nginx,fastCGI配置文件fastcgi_params,Nginx配置文件nginx.conf 放到SOURCES中 。
2 编辑tengine.spec,修改
2.1 介绍区域的SOURCE0下增加如下
2.2 安装区域增加如下
2.3 脚本区域增加如下
2.4 %file区域增加如下
3. 生成rpm文件测试
4. 安装测试
到此RPM包制作完毕,你可以根据你的需求制作RPM包吧。
四.RPM包签名
1.生成GPG签名密钥,我用的是root用户
有时可能因为随机数不够导致卡在那里,这时候你就yum 安装几个包组,马上就够了。
2.查看成生的密钥
3.导出公钥以供大家使用验证
4.编缉 .rpmmacros说明我们用哪一个密钥加密,我们用root加密的那就在/root下编辑
5.为rpm包加签名
到此签名添加成功,下面来验证
6.讲刚才导出的公钥导入rpm中
7.验证
到此整个过程完毕,你也试试吧
Group:
软件包所属类别,具体类别有:
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硬件支持)
测试通过实例:
cat rpmbuild/SPECS/tengine.spec
# This is a sample spec file for test rpm package
%define _prefix /usr/local/nginx
%define _user nobody
%define _user_uid 99
%define _group nobody
%define _group_uid 99
%define _sbin_path /usr/sbin
%define name Tengine
%define summary Tengine for Webserver
%define version 2.1.2
%define release 1
%define license GPL
%define group Application/WebServer
%define source tengine-%{version}.tar.gz
%define url http://tengine.taobao.org/
%define vendor Taobao
%define packager webuser
Name: tengine
Version: 2.1.2
Vendor: Taobao
Release: 1
Summary: GUN Tengine2.1.2
Group: Application/WebServer
License: GPL
URL: http://tengine.taobao.org/
Source0: tengine-%{version}.tar.gz
Source1: index.html
Source2: nginx
Source3: fastcgi_params
Source4: nginx.conf
Packager: webuser
#BuildRoot: /www/rpmbuild/%{name}-%{version}-%{release}-rpmbuild
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
#BuildRequires: gcc>=4.4.7, gcc-c++>=4.4.7, zlib-devel>=1.2.3, pcre-devel>=8.12, openssl-devel>=1.0.1e, autoconf>=2.63, automake>=1.11.1
#BuildRequires: mhash-devel
#BuildRequires: libxml2-devel
#BuildRequires: libxslt-devel
#BuildRequires: libgd-devel
#
#Requires: gcc>=4.4.7, gcc-c++>=4.4.7, zlib-devel>=1.2.3, pcre-devel>=8.12, openssl-devel>=1.0.1e, autoconf>=2.63, automake>=1.11.1
#Requires: mhash-devel
#Requires: libxml2-devel
#Requires: libxslt-devel
#Requires: libgd-devel
%description
The GNU Tengine WEB Server program.
%prep
%setup -q -n tengine-%{version}
%build
./configure \
--user=nobody \
--group=nobody \
--prefix=/usr/local/nginx \
--with-ipv6 \
--with-debug \
--with-http_sub_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_spdy_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_perl_module \
--with-pcre \
--add-module=../ngx_cache_purge-2.3
make
%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
%{__install} -p -D %{SOURCE1} %{buildroot}/usr/local/nginx/html/index.html
%{__install} -p -D -m 0755 %{SOURCE2} %{buildroot}/etc/rc.d/init.d/nginx
%{__install} -p -D %{SOURCE3} %{buildroot}/usr/local/nginx/conf/fastcgi_params
%{__install} -p -D %{SOURCE4} %{buildroot}/usr/local/nginx/conf/nginx.conf
mkdir -p %{buildroot}/%{_initrddir}
(
cat <<'EOF'
#!/bin/bash
# tengine Startup script for the tengine HTTP Server
# this script create it by Luo Hui at 2008.11.11.
# if you find any errors on this scripts,please contact Luo Hui.
# and send mail to farmer.luo at gmail dot com.
#
# chkconfig: - 85 15
# description: tengine is a high-performance web and proxy server.
# processname: tengine
# tengine pidfile: /var/run/tengine.pid
# tengine config: /usr/local/tengine/conf/nginx.conf
nginxd=%{_prefix}/sbin/nginx
nginx_config=%{_prefix}/conf/nginx.conf
nginx_pid=/var/run/tengine.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
ulimit -HSn 65535
# Start tengine daemons functions.
nginx_start() {
if [ -e $nginx_pid ];then
echo "tengine already running...."
exit 1
fi
if [ ! -d %{_prefix}/logs ];then
mkdir -p %{_prefix}/logs
fi
if [ ! -d %{_prefix}/tmp ]; then
mkdir -p %{_prefix}/tmp
fi
if [ -e $nginx_pid ];then
echo "tengine already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/tengine
return $RETVAL
}
# Stop tengine daemons functions.
nginx_stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/tengine $nginx_pid
}
# reload tengine service functions.
nginx_reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
nginx_start
;;
stop)
nginx_stop
;;
reload)
nginx_reload
;;
restart)
nginx_stop
nginx_start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: tengine {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
EOF
) >%{buildroot}/%{_initrddir}/tengine
chmod 755 %{buildroot}/%{_initrddir}/tengine
%clean
rm -rf %{buildroot}
%pre
grep -q ^%{_group}: /etc/group || %{_sbin_path}/groupadd -g %{_group_gid} %{_group}
grep -q ^%{_user}: /etc/passwd || %{_sbin_path}/useradd -g %{_group} -u %{_user_uid} -d %{_prefix} -s /sbin/nologin -M %{_user}
%post
chkconfig --add tengine
chkconfig --level 345 tengine on
%preun
chkconfig --del tengine
#%postun
#if [ $1 = 0 ]; then
# userdel %{_user} > /dev/null 2>&1 || true
#fi
%files
%defattr(-,root,root,-)
%dir %{_prefix}/
%attr(0755,%{_user},%{_group}) %dir %{_prefix}/logs
%dir %{_prefix}/modules
%dir %{_prefix}/sbin
%dir %{_prefix}/conf
%dir %{_prefix}/html
%{_prefix}/sbin/nginx
%{_prefix}/sbin/dso_tool
%{_prefix}/conf/module_stubs
%{_prefix}/conf/fastcgi.conf
%{_prefix}/conf/fastcgi_params.default
%{_prefix}/conf/win-utf
%{_prefix}/conf/koi-utf
%{_prefix}/conf/nginx.conf.default
%{_prefix}/conf/fastcgi.conf.default
%config(noreplace) %{_prefix}/conf/fastcgi_params
%{_prefix}/conf/koi-win
%{_prefix}/conf/mime.types
%config(noreplace) %{_prefix}/conf/nginx.conf
%{_prefix}/conf/mime.types.default
%{_prefix}/conf/scgi_params
%{_prefix}/conf/scgi_params.default
%{_prefix}/conf/uwsgi_params
%{_prefix}/conf/uwsgi_params.default
%{_prefix}/html/50x.html
%{_prefix}/html/index.html
/usr/lib64/perl5/perllocal.pod
/usr/local/lib64/perl5/auto/nginx/.packlist
/usr/local/lib64/perl5/auto/nginx/nginx.bs
/usr/local/lib64/perl5/auto/nginx/nginx.so
/usr/local/lib64/perl5/nginx.pm
%{_prefix}/conf/browsers
%{_prefix}/include/nginx.h
%{_prefix}/include/ngx_alloc.h
%{_prefix}/include/ngx_array.h
%{_prefix}/include/ngx_atomic.h
%{_prefix}/include/ngx_auto_config.h
%{_prefix}/include/ngx_auto_headers.h
%{_prefix}/include/ngx_buf.h
%{_prefix}/include/ngx_channel.h
%{_prefix}/include/ngx_conf_file.h
%{_prefix}/include/ngx_config.h
%{_prefix}/include/ngx_connection.h
%{_prefix}/include/ngx_core.h
%{_prefix}/include/ngx_crc.h
%{_prefix}/include/ngx_crc32.h
%{_prefix}/include/ngx_crypt.h
%{_prefix}/include/ngx_cycle.h
%{_prefix}/include/ngx_errno.h
%{_prefix}/include/ngx_event.h
%{_prefix}/include/ngx_event_busy_lock.h
%{_prefix}/include/ngx_event_connect.h
%{_prefix}/include/ngx_event_openssl.h
%{_prefix}/include/ngx_event_pipe.h
%{_prefix}/include/ngx_event_posted.h
%{_prefix}/include/ngx_event_timer.h
%{_prefix}/include/ngx_file.h
%{_prefix}/include/ngx_files.h
%{_prefix}/include/ngx_gcc_atomic_x86.h
%{_prefix}/include/ngx_hash.h
%{_prefix}/include/ngx_http.h
%{_prefix}/include/ngx_http_busy_lock.h
%{_prefix}/include/ngx_http_cache.h
%{_prefix}/include/ngx_http_config.h
%{_prefix}/include/ngx_http_core_module.h
%{_prefix}/include/ngx_http_perl_module.h
%{_prefix}/include/ngx_http_reqstat.h
%{_prefix}/include/ngx_http_request.h
%{_prefix}/include/ngx_http_script.h
%{_prefix}/include/ngx_http_spdy.h
%{_prefix}/include/ngx_http_spdy_module.h
%{_prefix}/include/ngx_http_ssi_filter_module.h
%{_prefix}/include/ngx_http_ssl_module.h
%{_prefix}/include/ngx_http_upstream.h
%{_prefix}/include/ngx_http_upstream_round_robin.h
%{_prefix}/include/ngx_http_v2.h
%{_prefix}/include/ngx_http_v2_module.h
%{_prefix}/include/ngx_http_variables.h
%{_prefix}/include/ngx_inet.h
%{_prefix}/include/ngx_linux.h
%{_prefix}/include/ngx_linux_config.h
%{_prefix}/include/ngx_list.h
%{_prefix}/include/ngx_log.h
%{_prefix}/include/ngx_md5.h
%{_prefix}/include/ngx_murmurhash.h
%{_prefix}/include/ngx_open_file_cache.h
%{_prefix}/include/ngx_os.h
%{_prefix}/include/ngx_palloc.h
%{_prefix}/include/ngx_parse.h
%{_prefix}/include/ngx_pipe.h
%{_prefix}/include/ngx_proc.h
%{_prefix}/include/ngx_process.h
%{_prefix}/include/ngx_process_cycle.h
%{_prefix}/include/ngx_proxy_protocol.h
%{_prefix}/include/ngx_queue.h
%{_prefix}/include/ngx_radix_tree.h
%{_prefix}/include/ngx_rbtree.h
%{_prefix}/include/ngx_regex.h
%{_prefix}/include/ngx_resolver.h
%{_prefix}/include/ngx_segment_tree.h
%{_prefix}/include/ngx_setaffinity.h
%{_prefix}/include/ngx_setproctitle.h
%{_prefix}/include/ngx_sha1.h
%{_prefix}/include/ngx_shmem.h
%{_prefix}/include/ngx_shmtx.h
%{_prefix}/include/ngx_slab.h
%{_prefix}/include/ngx_socket.h
%{_prefix}/include/ngx_string.h
%{_prefix}/include/ngx_sysinfo.h
%{_prefix}/include/ngx_syslog.h
%{_prefix}/include/ngx_thread.h
%{_prefix}/include/ngx_time.h
%{_prefix}/include/ngx_times.h
%{_prefix}/include/ngx_trie.h
%{_prefix}/include/ngx_user.h
/usr/local/share/man/man3/nginx.3pm
%{_initrddir}/tengine
%doc /usr/local/nginx/html/index.html
%attr(0775,root,root) /etc/rc.d/init.d/nginx
%changelog
* Mon Jul 4 2016 Beijing
- ver 2.1.2