1,搭建Epel和Base Yum源
[root@localhost ~]# rpm -ivh epel-release-latest-7.noarch.rpm //安装扩展源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
epel.repo epel-testing.repo xiong xiong.repo //扩展源解压生成的源文件
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-Media.repo epel.repo epel-testing.repo xiong xiong.repo //一共需要用到这四个源文件,之前保存在xiong里面,现在把它移出来
[root@localhost yum.repos.d]# yum -y clean all && yum makecache //清除yum缓存
2,安装ruby环境和gem命令FPM
gem命令是从rubygem仓库安装软件类似yum,从yum仓库安装软件
[root@localhost ~]# yum -y install ruby rubygems ruby-devel //安装需要的软件包
[root@localhost ~]# gem update --system //升级rubygems版本
Updating rubygems-update
Fetching: rubygems-update-3.0.6.gem (100%)
ERROR: Error installing rubygems-update:
rubygems-update requires Ruby version >= 2.3.0. //此时会报错,需要对应版本(版本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
Fetching: rubygems-update-3.0.6.gem (100%)
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
=== 2.3.0 / 2014-06-10
[root@localhost ~]# gem sources -l //查看当前源
*** CURRENT SOURCES ***
https://rubygems.org/
[root@localhost ~]# gem sources -a http://mirrors.aliyun.com/rubygems/ //添加国内源
http://mirrors.aliyun.com/rubygems/ added to sources
[root@localhost ~]# gem sources --remove https://rubygems.org/ //移除国外源
https://rubygems.org/ removed from sources
[root@localhost ~]# gem sources -l //查看当前源
*** CURRENT SOURCES ***
http://mirrors.aliyun.com/rubygems/
[root@localhost ~]# gem install fpm //安装FPM工具
3,打包Nginx生成RPM包
[root@localhost ~]# cat nginx.sh
#!/bin/bash
useradd -M -s /sbin/nologin nginx
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
echo "www.crushlinux.com" > /usr/local/nginx/html/index.html
/usr/local/nginx/sbin/nginx
[root@localhost ~]# fpm -s dir -t rpm -n nginx -v 1.16.1 -d 'pcre-devel,zlib-devel' -f --post-install /root/nginx.sh /usr/local/nginx //在当前目录下生成一个rpm包 指定对一个目录进行打包-t是我要打包成rpm包,我的名字是nginx,我的版本是1.16.1,-d指定它的依赖包,-f是文件 --post-install 安装完成后需要执行nginx.sh这个脚本
如果需要安装这个软件包先下载pcre-devel zlib-devel 这两个软件包。
[root@localhost ~]# rpm -ivh nginx-1.16.1-1.x86_64.rpm //接下来就是把软件包解压就可以用了