1、搭建Epel Yum源
安装在线yum源
[root@localhost ~]# rpm -ivh epel-release-latest-7.noarch.rpm //安装扩展源 [root@localhost yum.repos.d]# ls a epel-release-latest-7.noarch.rpm epel-testing.repo Centos-7.repo epel.repo
或
[root@localhost ~]# ls /etc/yum.repos.d/
backup CentOS-Base.repo CentOS-Media.repo epel.repo epel-testing.repo
修改epel.repo
[root@Crushlinux yum.repos.d]# yum clean all && yum makecache //清除并新建yum缓存
2、安装ruby环境和gem命令(gem命令是从rubygem仓库安装软件,类似yum从yum仓库安装软件)
安装软件包,安装时要出现3个安装的软件 [root@localhost yum.repos.d]# yum -y install ruby rubygems ruby-devel [root@localhost ~]# gem update --system //升级rubygems版本 [root@localhost ~]# gem install rubygems-update -v 2.3.0 //安装新版本 [root@localhost ~]# gem update --system //升级 [root@localhost ~]# gem sources -a http://mirrors.aliyun.com/rubygems/ //添加国内源 [root@localhost ~]# gem sources --remove https://rubygems.org/ //移除国外源 [root@localhost ~]# gem sources -l //查看当前源 [root@localhost ~]# gem install fpm //安装fpm工具
3、编译nginx,在保证nginx安装完的基础上打包,查看nginx的80端口
[root@localhost ~]# netstat -anpt | grep :80 //查询nginx的接口
4、打包nginx包生成rpm包
脚本 [root@localhost ~]# 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 //在网页文件中写入测试内容 /usr/local/nginx/sbin/nginx //开启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/ 报错信息 Need executable 'rpmbuild' to convert dir to rpm {:level=>:error} 修改 [root@localhost ~]# yum list | grep build [root@localhost ~]# yum -y install rpm-build [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包 Created package {:path=>"nginx-1.16.1-1.x86_64.rpm"}
5、安装自己制作的软件包,并查看端口
[root@localhost ~]# rpm -ivh nginx-1.16.1-1.x86_64.rpm //安装自己制作的包 [root@localhost ~]# netstat -anpt | grep 80 //查看端口