源码安装fpm yum仓库nginx 定制rpm包梳理


1.制作一个nginx的yum仓库
2.nginx打好的rpm包和nginx所有的依赖包cd放入yum仓库
3.其他机器,不使用其他yum源情况下,只使用自定义nginx仓库安装nginx

安装fpm 10.0.0.108

选择一台新的虚拟机10.0.0.108操作

# 1.安装ruby环境
[root@localhost <sub>]# yum install -y ruby rubygems ruby-devel rpm-build
# 2.更改gem源
## 查看gem源
[root@localhost </sub>]# gem sources
*<strong> CURRENT SOURCES </strong>*
https://rubygems.org/
## 删除官方gem源
[root@localhost <sub>]# gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources
## 添加阿里云gem源
[root@localhost </sub>]# gem sources --add https://mirrors.aliyun.com/rubygems/

[root@localhost <sub>]# gem sources
*<strong> CURRENT SOURCES </strong>*

https://mirrors.aliyun.com/rubygems/

# 3.下载fpm包
[root@localhost </sub>]# wget http://test.driverzeng.com/other/fpm-1.3.3.x86_64.tar.gz

[root@localhost <sub>]# yum install -y lrzsz
[root@localhost </sub>]# rz -E
rz waiting to receive.

# 4.解压
[root@localhost <sub>]# mkdir fpm
[root@localhost </sub>]# ll
total 1264
-rw-------. 1 root root 1287 Mar 14 22:34 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Apr 30 10:32 fpm
-rw-r--r--. 1 root root 1288103 Apr 28 10:41 fpm-1.3.3.x86_64.tar.gz

[root@localhost <sub>]# mv fpm-1.3.3.x86_64.tar.gz fpm
[root@localhost </sub>]# cd fpm/
[root@localhost fpm]# ll
total 1260
-rw-r--r--. 1 root root 1288103 Apr 28 10:41 fpm-1.3.3.x86_64.tar.gz
[root@localhost fpm]# tar xf fpm-1.3.3.x86_64.tar.gz
[root@localhost fpm]# ll
total 2572
-rw-r--r--. 1 root root 15360 Jun 27 2016 arr-pm-0.0.10.gem
-rw-r--r--. 1 root root 88064 Jun 27 2016 backports-3.6.8.gem
-rw-r--r--. 1 root root 21504 Jun 27 2016 cabin-0.8.1.gem
-rw-r--r--. 1 root root 29184 Jun 27 2016 childprocess-0.5.9.gem
-rw-r--r--. 1 root root 24576 Jun 27 2016 clamp-0.6.5.gem
-rw-r--r--. 1 root root 881664 Jun 27 2016 ffi-1.9.10.gem
-rw-r--r--. 1 root root 114176 Jun 27 2016 fpm-1.3.3.gem
-rw-r--r--. 1 root root 1288103 Apr 28 10:41 fpm-1.3.3.x86_64.tar.gz
-rw-r--r--. 1 root root 152064 Jun 27 2016 json-1.8.2.gem
5.安装fpm工具
[root@localhost fpm]# cd fpm
[root@localhost fpm]# gem install *.gem

源码安装nginx

# 0.开启yum安装包缓存
[root@localhost <sub>]# vim /etc/yum.conf
keepcache=0成keepcache=1
# 1.安装依赖包
[root@localhost </sub>]# find /var/cache/yum/ -type f -name '*.rpm'
[root@localhost <sub>]# yum install -y gcc gcc-c++ glibc pcre-devel openssl-devel

[root@localhost </sub>]# find /var/cache/yum/ -type f -name '*.rpm'
/var/cache/yum/x86_64/7/base/packages/libselinux-devel-2.5-15.el7.x86_64.rpm
/var/cache/yum/x86_64/7/base/packages/pcre-devel-8.32-17.el7.x86_64.rpm
/var/cache/yum/x86_64/7/updates/packages/krb5-devel-1.15.1-51.el7_9.x86_64.rpm
/var/cache/yum/x86_64/7/updates/packages/openssl-devel-1.0.2k-25.el7_9.x86_64.rpm


5.安装fpm工具
[root@localhost fpm]# cd fpm
[root@localhost fpm]# gem install *.gem

[root@localhost fpm]# echo $?
0
# 2.查找yum缓存,把所有rpm包拷贝到opt目录下
[root@localhost <sub>]# find /var/cache/yum/ -type f -name '*.rpm'|xargs cp -t /opt/

# 3.把所有依赖包打成一个tar包
[root@localhost </sub>]# cd /opt
[root@localhost opt]# ll
total 2492
-rw-r--r--. 1 root root 279472 Apr 30 20:43 krb5-devel-1.15.1-51.el7_9.x86_64.rpm
-rw-r--r--. 1 root root 191184 Apr 30 20:43 libselinux-devel-2.5-15.el7.x86_64.rpm
-rw-r--r--. 1 root root 1581956 Apr 30 20:43 openssl-devel-1.0.2k-25.el7_9.x86_64.rpm
-rw-r--r--. 1 root root 491272 Apr 30 20:43 pcre-devel-8.32-17.el7.x86_64.rpm

[root@localhost opt]# tar zcf nginx_require.tar.gz *.rpm

# 4.创建安装包存放目录和安装目录
## 安装包存放的目录
[root@localhost <sub>]# mkdir /pkg_tools

## 应用安装目录
[root@localhost </sub>]# mkdir /application

# 5.下载nginx源码包
[root@localhost <sub>]# wget -O /pkg_tools/nginx-1.20.2.tar.gz https://nginx.org/download/nginx-1.20.2.tar.gz

[root@localhost </sub>]# ll /pkg_tools/
total 1040
-rw-r--r--. 1 root root 1062124 Nov 16 22:51 nginx-1.20.2.tar.gz


# 6.解压
[root@localhost ~]# cd /pkg_tools/
[root@localhost pkg_tools]# tar xf nginx-1.20.2.tar.gz

# 7.进入源码包目录
[root@localhost pkg_tools]# cd nginx-1.20.2
[root@localhost nginx-1.20.2]# ll
total 792
drwxr-xr-x. 6 1001 1001 4096 Apr 30 21:12 auto
-rw-r--r--. 1 1001 1001 312251 Nov 16 22:44 CHANGES
-rw-r--r--. 1 1001 1001 476577 Nov 16 22:44 CHANGES.ru
drwxr-xr-x. 2 1001 1001 168 Apr 30 21:12 conf
-rwxr-xr-x. 1 1001 1001 2590 Nov 16 22:44 configure
drwxr-xr-x. 4 1001 1001 72 Apr 30 21:12 contrib
drwxr-xr-x. 2 1001 1001 40 Apr 30 21:12 html
-rw-r--r--. 1 1001 1001 1397 Nov 16 22:44 LICENSE
drwxr-xr-x. 2 1001 1001 21 Apr 30 21:12 man
-rw-r--r--. 1 1001 1001 49 Nov 16 22:44 README
drwxr-xr-x. 9 1001 1001 91 Apr 30 21:12 src
## 8.生成
[root@localhost nginx-1.20.2]# ./configure --prefix=/application/nginx-1.20.2 --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module
# 9.编译 && 安装
[root@localhost nginx-1.20.2]# make && make install
[root@localhost nginx-1.20.2]# ll /application/
total 0
drwxr-xr-x. 6 root root 54 Apr 30 21:24 nginx-1.20.2

将nginx源码包打成rpm包

#1.创建脚本目录
[root@localhost <sub>]# mkdir /scripts

#2.写安装后的脚本
[root@localhost </sub>]# vim /scripts/post_install_nginx.sh

id nginx &>/dev/null || useradd nginx -s /sbin/nologin -M
ln-s /application/nginx-1.20.2 /application/nginx
echo'PATH="/application/nginx/sbin:$PATH"' > /etc/profile.d/nginx.sh

# 3.卸载后要执行的脚本

# 4.打rpm包
[root@localhost <sub>]# fpm -s dir -t rpm -n nginx -v 1.20.2 -d 'openssl-devel,pcre-devel' --post-install /scripts/post_install_nginx.sh -f /application/nginx-1.20.2
或者
[root@localhost </sub>]# fpm -s dir \
> -t rpm \
> -n nginx \
> -v 1.20.2 \
> -d 'openssl-devel,prce-devel' \
> --post-install /scripts/post_install_nginx.sh \
> -f /application/nginx-1.20.2
no value for epoch is set, defaulting to nil {:level=>:warn}
no value for epoch is set, defaulting to nil {:level=>:warn}
Created package {:path=>"nginx-1.20.2-1.x86_64.rpm"}

[root@localhost ~]# echo $?
0



--post-uninstal

nginx做yum仓库

##yum仓库10.0.0.107机器

# 1.安装nginx

1)安装wget命令
[root@localhost <sub>]# yum install -y wget
2)换epel CentOS-Base.repo源
[root@localhost </sub>]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

[root@localhost <sub>]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
3)安装nginx
[root@localhost yum.repos.d]# yum install -y nginx



# 2.修改nginx配置文件

[root@localhost </sub>]# yum install -y vim
[root@localhost <sub>]# vim /etc/nginx/nginx.conf
:set nu加上行号查看 更改42 43
42 root /yum_repo;
43 autoindex on;

# 3.启动nginx
[root@localhost </sub>]# nginx
[root@localhost <sub>]# ps -ef|grep nginx
root 12138 1 0 12:39 ? 00:00:00 nginx: master process nginx
nginx 12139 12138 0 12:39 ? 00:00:00 nginx: worker process

# 4.创建/yum_rpeo目录
[root@web01 </sub>]# mkdir /yum_repo
# 5.创建nginx仓库目录
[root@web01 <sub>]# mkdir /yum_repo/nginx
# 6.安装制作yum仓库的命令
[root@localhost </sub>]# yum install -y createrepo

[root@localhost nginx]# createrepo /yum_repo/nginx/

10.0.0.108拷贝打包机器上所有rpm包到yum仓库中

10.0.0.108拷贝打包机器上所有rpm包到yum仓库中
# 7.拷贝打包机器上所有rpm包到yum仓库中
[root@localhost <sub>]# scp nginx-1.20.2-1.x86_64.rpm root@10.0.0.107:/yum_repo/nginx
root@10.0.0.107's password:
nginx-1.20.2-1.x86_64.rpm 100% 2736KB 88.1MB/s 00:00
[root@localhost </sub>]# ll
total 2744
-rw-------. 1 root root 1448 Apr 30 18:36 anaconda-ks.cfg
drwxr-xr-x. 2 root root 230 Apr 30 19:17 fpm
-rw-r--r--. 1 root root 2802071 Apr 30 22:06 nginx-1.20.2-1.x86_64.rpm
[root@localhost <sub>]# ll /opt
total 4604
-rw-r--r--. 1 root root 279472 Apr 30 20:43 krb5-devel-1.15.1-51.el7_9.x86_64.rpm
-rw-r--r--. 1 root root 191184 Apr 30 20:43 libselinux-devel-2.5-15.el7.x86_64.rpm
-rw-r--r--. 1 root root 2160326 Apr 30 20:45 nginx_require.tar.gz
-rw-r--r--. 1 root root 1581956 Apr 30 20:43 openssl-devel-1.0.2k-25.el7_9.x86_64.rpm
-rw-r--r--. 1 root root 491272 Apr 30 20:43 pcre-devel-8.32-17.el7.x86_64.rpm

[root@localhost </sub>]# scp /opt/nginx_require.tar.gz root@10.0.0.107:/yum_repo/nginx
root@10.0.0.107's password:
nginx_require.tar.gz 100% 2110KB 68.1MB/s 00:00

10.0.0.107yum仓库机

8.解压依赖包
[root@localhost <sub>]# ll /yum_repo/nginx
total 4852
-rw-r--r--. 1 root root 2802071 May 1 13:30 nginx-1.20.2-1.x86_64.rpm
-rw-r--r--. 1 root root 2160326 May 1 13:32 nginx_require.tar.gz

[root@localhost </sub>]# cd /yum_repo/nginx/
[root@localhost nginx]# tar xf nginx_require.tar.gz
[root@localhost nginx]# ll
total 7344
-rw-r--r--. 1 root root 279472 Apr 30 20:43 krb5-devel-1.15.1-51.el7_9.x86_64.rpm
-rw-r--r--. 1 root root 191184 Apr 30 20:43 libselinux-devel-2.5-15.el7.x86_64.rpm
-rw-r--r--. 1 root root 2802071 May 1 13:30 nginx-1.20.2-1.x86_64.rpm
-rw-r--r--. 1 root root 2160326 May 1 13:32 nginx_require.tar.gz
-rw-r--r--. 1 root root 1581956 Apr 30 20:43 openssl-devel-1.0.2k-25.el7_9.x86_64.rpm
-rw-r--r--. 1 root root 491272 Apr 30 20:43 pcre-devel-8.32-17.el7.x86_64.rpm
# 9.制作yum仓库
[root@localhost <sub>]# createrepo /yum_repo/nginx/

# 10.关闭防火墙,关闭selinux
[root@localhost </sub>]# systemctl stop firewalld
[root@localhost ~]# setenforce 0

测试其他机器10.0.0.109

# 1.压缩所有其他系统的yum源
[root@localhost <sub>]# gzip -r /etc/yum.repos.d/
[root@localhost </sub>]# ll /etc/yum.repos.d/
total 36
-rw-r--r--. 1 root root 549 Oct 23 2020 CentOS-Base.repo.gz
-rw-r--r--. 1 root root 735 Oct 23 2020 CentOS-CR.repo.gz
-rw-r--r--. 1 root root 426 Oct 23 2020 CentOS-Debuginfo.repo.gz
-rw-r--r--. 1 root root 232 Oct 23 2020 CentOS-fasttrack.repo.gz
-rw-r--r--. 1 root root 381 Oct 23 2020 CentOS-Media.repo.gz
-rw-r--r--. 1 root root 506 Oct 23 2020 CentOS-Sources.repo.gz
-rw-r--r--. 1 root root 813 Oct 23 2020 CentOS-Vault.repo.gz
-rw-r--r--. 1 root root 272 Oct 23 2020 CentOS-x86_64-kernel.repo.gz
-rw-r--r--. 1 root root 254 Dec 26 2020 epel.repo.gz

# 2.手写yum源配置文件
[root@localhost <sub>]# vim /etc/yum.repos.d/nginx.repo
[shiying_nginx]
name=Ningx Repository By shiying
baseurl=http://10.0.0.107/nginx/ ##ip地址要写创建yum仓库的虚拟机
gpgcheck=0
enabled=1

[root@localhost </sub>]# yum repolist
[root@localhost ~]# yum install -y nginx
Dependencies Resolved

======================================================================================================
Package Arch Version Repository Size
======================================================================================================
Installing:
nginx x86_64 1.20.2-1 ying_nginx 2.7 M
Installing for dependencies:
keyutils-libs-devel x86_64 1.5.8-3.el7 ying_nginx 37 k
krb5-devel x86_64 1.15.1-51.el7_9 ying_nginx 273 k
libcom_err-devel x86_64 1.42.9-19.el7 ying_nginx 32 k
libkadm5 x86_64 1.15.1-51.el7_9 ying_nginx 179 k
libselinux-devel x86_64 2.5-15.el7 ying_nginx 187 k
libsepol-devel x86_64 2.5-10.el7 ying_nginx 77 k
libverto-devel x86_64 0.2.5-4.el7 ying_nginx 12 k
openssl-devel x86_64 1:1.0.2k-25.el7_9 ying_nginx 1.5 M
pcre-devel x86_64 8.32-17.el7 ying_nginx 480 k
zlib-devel x86_64 1.2.7-19.el7_9 ying_nginx 50 k
Updating for dependencies:
krb5-libs x86_64 1.15.1-51.el7_9 ying_nginx 809 k
openssl x86_64 1:1.0.2k-25.el7_9 ying_nginx 494 k
openssl-libs x86_64 1:1.0.2k-25.el7_9 ying_nginx 1.2 M
zlib x86_64 1.2.7-19.el7_9 ying_nginx 90 k

Transaction Summary
===================================================================================================