2020-06-26 14:35:28
fpm定制化RPM包之nginx rpm包的制作
# yum -y install ruby rubygems ruby-devel
gem sources -a http://mirrors.aliyun.com/rubygems/
http://mirrors.aliyun.com/rubygems/ added to sources
移除原生的ruby仓库
gem sources --remove http://rubygems.org/
centos6:
gem install json -v 1.8.3
gem install fpm -v 1.3.3
centos7直接使用如下命令:
[root@slave02 ~]# gem install fpm
Fetching: cabin-0.9.0.gem (100%)
Successfully installed cabin-0.9.0
Fetching: backports-3.8.0.gem (100%)
Successfully installed backports-3.8.0
Fetching: arr-pm-0.0.10.gem (100%)
Successfully installed arr-pm-0.0.10
Fetching: clamp-1.0.1.gem (100%)
Successfully installed clamp-1.0.1
Fetching: ffi-1.9.18.gem (100%)
Building native extensions. This could take a while...
Successfully installed ffi-1.9.18
Fetching: childprocess-0.7.0.gem (100%)
Successfully installed childprocess-0.7.0
Fetching: archive-tar-minitar-0.5.2.gem (100%)
Successfully installed archive-tar-minitar-0.5.2
Fetching: io-like-0.3.0.gem (100%)
Successfully installed io-like-0.3.0
Fetching: ruby-xz-0.2.3.gem (100%)
Successfully installed ruby-xz-0.2.3
Fetching: stud-0.0.22.gem (100%)
Successfully installed stud-0.0.22
Fetching: mustache-0.99.8.gem (100%)
Successfully installed mustache-0.99.8
Fetching: insist-1.0.0.gem (100%)
Successfully installed insist-1.0.0
Fetching: dotenv-2.2.1.gem (100%)
Successfully installed dotenv-2.2.1
Fetching: pleaserun-0.0.29.gem (100%)
Successfully installed pleaserun-0.0.29
Fetching: fpm-1.8.1.gem (100%)
Successfully installed fpm-1.8.1
Parsing documentation for cabin-0.9.0
Installing ri documentation for cabin-0.9.0
Parsing documentation for backports-3.8.0
Installing ri documentation for backports-3.8.0
Parsing documentation for arr-pm-0.0.10
Installing ri documentation for arr-pm-0.0.10
Parsing documentation for clamp-1.0.1
Installing ri documentation for clamp-1.0.1
Parsing documentation for ffi-1.9.18
Installing ri documentation for ffi-1.9.18
Parsing documentation for childprocess-0.7.0
Installing ri documentation for childprocess-0.7.0
Parsing documentation for archive-tar-minitar-0.5.2
Installing ri documentation for archive-tar-minitar-0.5.2
Parsing documentation for io-like-0.3.0
Installing ri documentation for io-like-0.3.0
Parsing documentation for ruby-xz-0.2.3
Installing ri documentation for ruby-xz-0.2.3
Parsing documentation for stud-0.0.22
Installing ri documentation for stud-0.0.22
Parsing documentation for mustache-0.99.8
Installing ri documentation for mustache-0.99.8
Parsing documentation for insist-1.0.0
Installing ri documentation for insist-1.0.0
Parsing documentation for dotenv-2.2.1
Installing ri documentation for dotenv-2.2.1
Parsing documentation for pleaserun-0.0.29
Installing ri documentation for pleaserun-0.0.29
Parsing documentation for fpm-1.8.1
Installing ri documentation for fpm-1.8.1
15 gems installed
yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre pcre-devel glib glib-devel
useradd nginx -M -s /sbin/nologin
tar xf nginx-1.12.0.tar.gz
cd nginx-1.12.0
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-http_dav_module --with-pcre
make && make install
软件包卸载前、卸载后的脚本,可以根据情况是否编写,不编写问题也不大。但是rpm安装后的脚本是必须的。
mkdir /data/scripts/ -p
cd /data/scripts/
编写一个rpm安装后需要执行的脚本
vim nginx_post_install.sh
#!/bin/bash
useradd nginx -M -s /sbin/nologin
chmod +x /etc/init.d/nginx
chkconfig --add nginx
echo 'PATH=/user/local/nginx/sbin:$PATH'>> /etc/profile.d/nginx.sh
卸载nginx后需要执行的脚本
# cat after_remove.sh
#!/bin/bash
rm -rf /usr/local/nginx
rm -f /etc/rc.d/init.d/nginx
准备个启动脚本,如下:
vim /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=([^ ]*).*/1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
$nginx -s reload
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
将nginx启动脚本和注意的配置及启动文件拷贝到打包目录
mkdir -p /data/scripts/etc/rc.d/init.d
cp /etc/init.d/nginx /data/scripts/etc/rc.d/init.d/
mkdir -p /data/scripts/usr/local/nginx/
cp -r /usr/local/nginx/ /data/scripts/usr/local/nginx/
/data/scripts目录结构
[root@master scripts]# tree
.
├── after_remove.sh
├── etc
│ └── rc.d
│ └── init.d
│ └── nginx
├── nginx-1.12.0-1.el6.x86_64.rpm
├── nginx_post_install.sh
└── usr
└── local
└── nginx
├── client_body_temp
├── conf
│ ├── fastcgi.conf
│ ├── fastcgi.conf.default
│ ├── fastcgi_params
│ ├── fastcgi_params.default
│ ├── koi-utf
│ ├── koi-win
│ ├── mime.types
│ ├── mime.types.default
│ ├── nginx.conf
│ ├── nginx.conf.default
│ ├── scgi_params
│ ├── scgi_params.default
│ ├── uwsgi_params
│ ├── uwsgi_params.default
│ └── win-utf
├── etc
│ └── rc.d
│ └── init.d
│ └── nginx
├── fastcgi_temp
├── html
│ ├── 50x.html
│ └── index.html
├── logs
│ ├── access.log
│ ├── error.log
│ └── nginx.pid
├── proxy_temp
├── sbin
│ └── nginx
├── scgi_temp
└── uwsgi_temp
打包,即将准备好的文件打包成rpm
# fpm -f -s dir -t rpm -n nginx --epoch 0 -v 1.12.0 --iteration 1.el6 -C /data/scripts/ -d 'pcre-devel,openssl-devel,autoconf,glib-devel' --post-uninstall /data/scripts/nginx_post_install.sh --post-uninstall /data/scripts/after_remove.sh --workdir /data/scripts/ etc usr
Created package {:path=>"nginx-1.12.0-1.el6.x86_64.rpm"}
报错:
Need executable 'rpmbuild' to convert dir to rpm {:level=>:error}
解决:
yum install rpm-build -y
注意:我们可以操作前修改下主机名,这样打包出来的Build Host就会跟着改变。
yum命令安装rpm包
yum -y localinstall nginx-1.12.0-1.x86_64.rpm
这个命令会自动先安装rpm包的依赖,然后再安装rpm包。
FPM常用参数:
-f :强制覆盖[覆盖同名rpm包] -n :指定的rpm包名 -p :指定的rpm包文件放置位置 -v :指定的rpm包版本 -d :指定依赖的软件 ( [-d ‘name’] or [-d ‘name > version’] 例子: -d ‘libstdc++ >= 4.4.3’) -a :指定系统架构,如果是noarch则为’-a all’ 或者 ‘-a native’ [x86_64] 当软件不区分64位或32位的时候可以 noarch -s :指定INPUT的数据类型 ([“-s dir”] 省略数据类型) -m :指定打包人员[Packager] ([ -m ‘user’]) -C :指定打包的相对路径,类似于buildroot. 譬如-C /tmp/apr/ 而打包机器的数据包路径是/tmp/apr/{opt,usr,etc} 那安装这个rpm包后,在本地的数据就是/opt/,/usr/,/etc/ -t :指定需要制作成什么包,可选项有(deb,rpm,solaris,etc)支持的源类型::
"dir" "rpm" "gem" "python" "empty" "tar" "deb" "cpan" "npm" "osxpkg" "pear" "pkgin" "virtualenv" "zip"
支持的目标类型:
"rpm" "deb" "solaris" "puppet" "dir" "osxpkg" "p5p" "puppet" "sh" "solaris" "tar" "zip"
--description :软件包描述
--conflicts :指定冲突软件
--url :指定站点[惯例都是添加软件的官网 例如: --url "http://www.cnblog.com/roach57" ]
--verbose :安装过程详细打印
--after-install :包安装之后执行的脚本 也可写作 --post-install FILE
--before-install :包安装之前执行的脚本
--after-remove :包卸载之后执行的脚本
--before-remove :包卸载之前执行的脚本
--after-upgrade :包更新之后执行的脚本[仅支持 deb 和 rpm 这两种包]
--before-upgrade :包更新之前执行的脚本
--iteration :发布序号[就是rpm包里面的release]
--epoch :纪元 [不知道干嘛用的]
--no-rpm-sign :不使用rpm签名 Signature
--license :证书许可 [可选项有 'BSD(开源软件)' 'GPLv2(自由软件)' 'MIT' 'Public Domain(公共域)' 'Distributable(贡献)' 'commercial(商业)' 'Share(共享)等',一般的开发都写'BSD'或'GPL']
--vendor :供应商名称 [ --vendor 'roach57@163.com']
--no-depends :代表没有任何依赖包,和-d是对立的,不能共用
--config-files :指定配置文件,可以指定目录[递归]
--directories :指定包目录
--category :软件所属的类别[这是个什么软件]下面有个对应的表格:
[参考这个文件 /usr/share/doc/rpm-x.x.x/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硬件支持]
RPM包的组成格式:
roach-1.0.1-57.el6.x86_64.rpm
| | | | |
软件名称| | | |
版本号 | | |
发布号 | |
硬件平台 |
扩展名
例子备注:
roach :软件名称 1.0.1 :软件版本号 57.el6 :发布号主要是对软件存在的bug或漏洞进行修补,在软件功能上并没有变化,el6指的是rhel6系统中发布 x86_64 :指64位的PC架构,另外还有’i386′ ‘i686’ 等32位的PC架构,noarch是指不区分硬件架构 rpm :扩展名nginx编译安装动态模块(不需重新编译nginx)
06-25
centos7安装配置gitlab(使用外部nginx)
06-11
docker部署zabbix监控系统(nginx mysql)
06-28
saltstack快速批量安装nginx
07-16
使用nginx limit_req限制用户请求速率
06-06
使用nginx ngx_http_referer_module模块配置防盗链
06-28
开启nginx的gzip压缩功能,节省流量
05-28
CentOS 7 rpm安装mysql 5.7.18
04-27
CentOS-5 rpm安装yum
04-28
php-fpm性能优化实例分析
05-13
Byteman 4.0.11 发布,Java 字节码注入工具
06-03
GIF制作软件Vibosoft Animated GIF Maker安装教程
10-12
Linux网站压力测试工具webbench
06-25
Office通用正式卸载工具
05-16
Power2go软件制作光盘映像并把制作的映像刻录到光盘上
03-26
Supervisor安装与配置(Linux/Unix进程管理工具)
05-29
bind nsupdate动态dns更新工具介绍
05-03
centos系统安装配置phpMyAdmin数据库管理工具
04-27
shell脚本制作俄罗斯方块游戏
02-27
wget多线程下载工具Axel介绍
05-06
rpg maker vx(rpg游戏制作工具)V1.0.2.2 免费版
38.1M
下载usboot (U盘启动盘制作工具)v1.70 绿色版
0.35MB
下载visio 2007(图标制作工具)2021 免费版
377MB
下载字幕大师(字幕制作工具) V3.1 破解版
43.57 MB
下载手机铃声制作工具(iphone铃声制作软件) v1.0.20 最新版
14.7M
下载Cencrack在线工具包 v5.26 绿色版
2.04M
下载coreldrawx6(矢量图形快速设计和制作的工具)v6.0 免费版
7 KB
下载sniffer pro(网络抓包工具) V4.70 官方版
40.59 MB
下载ai cs6(矢量图制作软件) v16.0 免费版
1.97G
下载deadpixeltest(相机坏点检测工具)v1.0 绿色版
0.16MB
下载easyrecovery pro(硬盘数据恢复工具) v14.0.0.4 官方版
87.8M
下载gghost一键恢复(系统备份还原工具)v10.03.09 中文版
14.5M
下载onekeyghost(备份还原工具)v14.5.8 绿色版
6.09MB
下载photocap(图片编辑工具)V7.0 绿色版
14.8MB
下载手机铃声制作软件下载
3.63 MB
下载Section软件免费版安装包下载 v4.7.3
8.16mb
下载office2007兼容包下载
27.24 MB
下载xp仿vista主题(xp系统主题包)免费版
9.94 MB
下载压缩包修复下载
2.8M
下载Enigma Virtual Box下载
4.2M
下载