1.安装fpm
yum -y install ruby rubygems ruby-devel rpm-build
gem install fpm
2.编译nginx并创建虚拟目录
mkdir -pv /opt/nginx/{etc/rc.d/init.d,sysconfig}
nginx-1.6.2.tar.gz放在/opt/nginx目录下
进入/opt/nginx目录下
tar -zxvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure --prefix=/usr/local/nginx --pid-path=/usr/local/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_dav_module --with-http_flv_module --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-debug --http-client-body-temp-path=/usr/local/nginx/client --http-proxy-temp-path=/usr/local/nginx/proxy --http-fastcgi-temp-path=/usr/local/nginx/fastcgi --http-uwsgi-temp-path=/usr/local/nginx/uwsgi --http-scgi-temp-path=/usr/local/nginx/scgi
make
make install DESTDIR=/opt/nginx
这里我把已经更改过的nginx配置存放到了里面,以及nginx的启动脚本放到了/opt/nginx/etc/rc.d/init.d/下面,两个shell脚本一个是在安装完成后创建nginx运行用户,和卸载rpm包之后执行的操作
3.在/opt/nginx目录下创建 after_install.sh ,after_remove.sh
vim after_install.sh
#!/bin/bash
source /etc/rc.d/init.d/functions
groupadd -r nginx
useradd -r -g nginx nginx
exit $?
vim after_remove.sh
#!/bin/bash
source /etc/rc.d/init.d/functions
rm -rf /usr/local/nginx
rm -rf /etc/nginx
userdel nginx
exit $?
4.打包命令
fpm -f -s dir
-t rpm \
-n qding-nginx --epoch 0 -v1.6.2 --iteration 1.el6 \
-C /opt/nginx/ \
-p /root/ \
-d 'openssl-devel' -d 'gcc' -d 'gcc-c++' -d 'pcre-devel' -d 'zlib-devel' \
--verbose \
--category 'Development/Languages' \
--description 'nginx applications' \
--url 'nginx.org' \
--license 'BSD' \
-m 'bianji' \
--no-rpm-sign \
--after-install /opt/nginx/after_install.sh \
--after-remove after_remove.sh \
--workdir /opt/nginx/ etc usr
5.FPM参数详解
Usage: fpm [options]
-p, --package PACKAGEFILE 管理的软件包
-n, --name PACKAGENAME 定义生成的软件包的名字
-v, --version VERSION 定义生成的软件包的版本
–iteration ITERATION 为软件包设置 iteration值 (‘release’ for RPM).
–epoch EPOCH 为软件包设置 epoch值
-d, —depends DEPENDENCY 设置软件包的依赖关系
-C DIRECTORY 在搜索files前先进入该目录
-t PACKAGE_TYPE 设置目标包的类型
-s SOURCE_TYPE 设置需要转换的包类型
–after-remote 卸载后执行脚本
–after-install 安装后执行脚本
成功后在/root下
- rpm默认安装时默认的根目录就是系统的’/’:
- rpm手动指定安装时的根目录[ --prefix=/temp/roach]:
[root@localhost ~]# rpm -ivh roach-1.0.1-57.el6.x86_64.rpm --prefix=/temp/roach
- rpm手动指定安装时的根目录[ --prefix=/temp/roach]:
rpm的卸载
[指定卸载的软件时,省略最后的扩展名.rpm]
[root@localhost ~]# rpm -e roach-1.0.1-57.el6.x86_64