由于源码安装步骤比较繁琐
rpm好处: 直接安装 启动服务就可以了
如何做rpm包
例子:nginx的rpm包制作过程
1、支持的源类型包
- dir: 将目录打包成所需要的类型,可以用于源码编译安装的软件包
- rpm: 对rpm进行转换
- gem: 对rubygem包进行转换
- python: 将Python模块打包成相应的类型
- rpm: 转换为rpm包
- deb: 转换为deb包
- solaris: 转换为solaris包
- puppet: 转换为puppet包
2、支持目标类型包
3、FPM常用参数
-s:指定源类型
-t:指定目标类型,即想要制作为什么包
-n:指定包的名字
-v:指定包的版本号
-C:指定打包的相对路径
-d:指定依赖于哪些包
-f:第二次包时目录下如果有同名安装包存在,则覆盖它
-p:制作的rpm安装包存放路径,不想放在当前目录下就需要指定;
--post-install:软件包安装完成之后所要运行的脚本;同--offer-install
--pre-install:软件包安装完成之前所要运行的脚本;同--before-install
--post-uninstall:软件包卸载完成之后所要运行的脚本;同--offer-remove
--pre-uninstall:软件包卸载完成之前所要运行的脚本;同—before-remove
--prefix:制作好的rpm包默认安装路径
4、基于FPM制作RPM包
4.1、搭建Epel Yum源
[root@localhost ~]# rpm -ivh epel-release-latest-7.noarch.rpm//安装扩展源
[root@localhost ~]# ls /etc/yum.repos.d/
backup CentOS-Base.repo CentOS-Media.repo epel.repo epel-testing.repo
[root@Crushlinux yum.repos.d]# yum clean all && yum makecache
4.2、安装ruby环境和gem命令FPM
gem命令是从rubygem仓库安装软件类似yum从yum仓库安装软件
[root@Crushlinux ~]# yum install -y ruby rubygems ruby-devel
[root@Crushlinux ~]# gem update --system//升级rubygems版本
Updating rubygems-update
ERROR: Error installing rubygems-update:
rubygems-update requires Ruby version >= 2.3.0.
ERROR: While executing gem ... (NoMethodError)
undefined method `version' for nil:NilClass
[root@localhost ~]# gem install rubygems-update -v 2.3.0
Fetching: rubygems-update-2.3.0.gem (100%)
Successfully installed rubygems-update-2.3.0
Parsing documentation for rubygems-update-2.3.0
Installing ri documentation for rubygems-update-2.3.0
1 gem installed
[root@localhost ~]# gem update --system
Updating rubygems-update
ERROR: Error installing rubygems-update:
rubygems-update requires Ruby version >= 2.3.0.
Installing RubyGems 2.3.0
RubyGems 2.3.0 installed
Parsing documentation for rubygems-2.3.0
Installing ri documentation for rubygems-2.3.0
[root@Crushlinux ~]# gem sources -a http://mirrors.aliyun.com/rubygems/ //添加国内源
[root@Crushlinux ~]# gem sources --remove https://rubygems.org///移除国外源:
[root@Crushlinux ~]# gem sources -l//查看当前源:
*** CURRENT SOURCES ***
http://mirrors.aliyun.com/rubygems/
[root@Crushlinux ~]# gem install fpm //安装FPM工具
4.3、编译Nginx
[root@Crushlinux ~]# tar xf nginx-1.10.2.tar.gz -C /usr/src/
[root@Crushlinux nginx-1.10.2]# yum -y install pcre-devel zlib-devel
[root@Crushlinux nginx-1.10.2]# ./configure --prefix=/usr/local/nginx --with-pcre && make &&make install
4.4、打包Nginx生成RPM包
[root@Crushlinux ~]# vim nginx.sh
#!/bin/bash
useradd -M -s /sbin/nologin nginx
ln -s /usr/local/nginx/sbin/nginx /sbin/
echo www.crushlinux.com > /usr/local/nginx/html/index.html
nginx
[root@Crushlinux fpm]# fpm -s dir -t rpm -n nginx -v 1.10.2 -d 'pcre-devel,zlib-devel' -f --post-install /root/nginx.sh /usr/local/nginx//会在当前目录下生成一个rpm包
[root@Crushlinux fpm]# rpm -ivh nginx-1.10.2-1.x86_64.rpm
[root@Crushlinux fpm]# rpm -qi nginx
Name : nginx Relocations: /
Version : 1.10.2 Vendor: root@master
Release : 1 Build Date: Fri 06 Apr 2018 10:09:39 AM EDT
Install Date: Fri 06 Apr 2018 10:10:21 AM EDT Build Host: master
Group : default Source RPM: nginx-1.10.2-1.src.rpm
Size : 3467318 License: unknown
Signature : (none)
Packager : <root@master>
URL : http://example.com/no-uri-given
Summary : no description given
Description :
no description given