环境准备:

主机名 外网IP 内网IP 应用 角色web0
web01 10.0.0.7 1721.16.1.7 fpm 打包工具
web02 10.0.0.8 1721.16.1.8 yumrepo yum仓库
web03 10.0.0.9 1721.16.1.9 测试rpm包的客户端

web01:fpm打包安装

#安装依赖
[root@web01 ~]# yum install -y rpm-build
#下载fpm打包工具   //可指定目录,这里为了方便就在root下面安装了
[root@web01 ~]# wget http://test.driverzeng.com/other/fpm-1.3.3.x86_64.tar.gz
#解压
[root@web01 ~]# tar xf fpm-1.3.3.x86_64.tar.gz
# 3.安装ruby环境
[root@web01 ~]# yum install -y ruby rubygems ruby-devel
    gem ruby应用商店 .gem
    yum CentOS应用商店 .rpm
    pip python库应用商店
# 查看gem源
[root@web01 ~]# gem source --list
*** CURRENT SOURCES ***
https://rubygems.org/
# 删除官方源
[root@web01 ~]# gem sources --remove https://rubygems.org/
# 更换阿里云gem源
[root@web01 ~]# gem sources -a https://mirrors.aliyun.com/rubygems/
https://mirrors.aliyun.com/rubygems/ added to sources
[root@web01 ~]# gem source --list
*** CURRENT SOURCES ***
https://mirrors.aliyun.com/rubygems/
# 安装fpm   //如果fpm报错 ,则重复安装一便即可
[root@web01 ~]# gem install *.gem
# 检查是否安装成功
[root@web01 ~]# fpm --version
1.3.3
----------------------------------------------------------------------------------------------------
#源码安装nginx
# 安装依赖
[root@web01 nginx-1.22.1]# yum install -y pcre-devel zlib-devel openssl-devel
# 下载nginx源码包
[root@web01 ~]# wget https://nginx.org/download/nginx-1.22.1.tar.gz
#创建目录
mkdir /app
# 解压
[root@web01 ~]# tar xf nginx-1.22.1.tar.gz 
#进入解压后的nginx
[root@web01 ~]# cd nginx-1.22.1.tar.gz 
# 生成
[root@web01 nginx-1.22.1]# ./configure --prefix=/app/nginx-1.22.1 --with-http_ssl_module --with-http_stub_status_module
# 编译安装
[root@web01 nginx-1.22.1]# make && make install
#打包命令解读
fpm
-s dir # 指定将目录、文件打包成rpm
-t rpm # 打包成rpm包
-n nginx # name rpm包的名字
-v 1.6.3 # rpm包的版本
-d 'pcre-devel,openssl-devel' # 指定依赖
--post-install /server/scripts/nginx_rpm.sh # 安装之后,需要执行的命令(脚本)
-f /application/nginx-1.6.3/ # 指定打包的目录
# yum命令可以帮你自动解决依赖关系
## 编写脚本
[root@web01 nginx-1.22.1]# vim /app/nginx-1.22.1/install_nginx.sh
-----------------------------------------------------------------------------------------------------
#!/bin/bash
ln -s /app/nginx-1.22.1 /app/nginx
echo 'export PATH="$PATH:/app/nginx/sbin"' >> /etc/profile.d/nginx.sh
# 生效环境变量
source /etc/profile
#添加启动脚本
cat >> /usr/lib/systemd/system/nginx.service << EOF
[Unit]
Description=nginx - high performance web server
After=network.target

[Service]
Type=forking
ExecStartPre=/app/nginx/sbin/nginx -t -c /app/nginx/conf/nginx.conf
ExecStart=/app/nginx/sbin/nginx -c /app/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF
#重新加载文件
systemctl daemon-reload
-----------------------------------------------------------------------------------------------------
#授权脚本
[root@web01 nginx-1.22.1]# chmod +x /app/nginx-1.22.1/install_nginx.sh
#移动至app目录下
[root@web01 nginx-1.22.1]# cd /app/
#打包
fpm -s dir -t rpm -n nginx -v 1.22.1 -d 'pcre-devel,openssl-devel,zlib-devel' --post-install /app/nginx-1.22.1/install_nginx.sh -f /app/nginx-1.22.1
[root@web01 app]# ll
total 2744
drwxr-xr-x 6 root root      78 Jun 22 18:15 nginx-1.22.1
-rw-r--r-- 1 root root 2808831 Jun 22 18:17 nginx-1.22.1-1.x86_64.rpm

web02 :yum本地仓库制作

#下载http服务nginx
[root@web02 ~]# yum install -y nginx
# 安装仓库制作命令
[root@hadoop101 pub]#yum install createrepo -y
 #创建站点目录
 [root@web02 ~]# mkdir -p /yum/repository 
 #准备rpm安装包   //将web01打包好的nginx rpm包拷贝给web02
 scp nginx-1.22.1-1.x86_64.rpm 10.0.0.8:/yum/repository
 yum install -y pcre-devel zlib-devel openssl-devel --downloadonly --downloaddir=/yum/repository
[root@web02 repository]# ll
total 9788
-rw-r--r-- 1 root root  717384 Oct 15  2020 e2fsprogs-1.42.9-19.el7.x86_64.rpm
-rw-r--r-- 1 root root  172156 Oct 15  2020 e2fsprogs-libs-1.42.9-19.el7.x86_64.rpm
-rw-r--r-- 1 root root   38232 Jul  4  2014 keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm
-rw-r--r-- 1 root root  279860 Dec  1  2022 krb5-devel-1.15.1-55.el7_9.x86_64.rpm
-rw-r--r-- 1 root root  829408 Dec  1  2022 krb5-libs-1.15.1-55.el7_9.x86_64.rpm
-rw-r--r-- 1 root root   43092 Oct 15  2020 libcom_err-1.42.9-19.el7.x86_64.rpm
-rw-r--r-- 1 root root   33016 Oct 15  2020 libcom_err-devel-1.42.9-19.el7.x86_64.rpm
-rw-r--r-- 1 root root  183908 Dec  1  2022 libkadm5-1.15.1-55.el7_9.x86_64.rpm
-rw-r--r-- 1 root root  166012 Apr  4  2020 libselinux-2.5-15.el7.x86_64.rpm
-rw-r--r-- 1 root root  191184 Apr  4  2020 libselinux-devel-2.5-15.el7.x86_64.rpm
-rw-r--r-- 1 root root  241168 Apr  4  2020 libselinux-python-2.5-15.el7.x86_64.rpm
-rw-r--r-- 1 root root  154876 Apr  4  2020 libselinux-utils-2.5-15.el7.x86_64.rpm
-rw-r--r-- 1 root root   78740 Nov 12  2018 libsepol-devel-2.5-10.el7.x86_64.rpm
-rw-r--r-- 1 root root   47812 Oct 15  2020 libss-1.42.9-19.el7.x86_64.rpm
-rw-r--r-- 1 root root   11776 Jul  4  2014 libverto-devel-0.2.5-4.el7.x86_64.rpm
-rw-r--r-- 1 root root  506040 Mar 21 22:46 openssl-1.0.2k-26.el7_9.x86_64.rpm
-rw-r--r-- 1 root root 1582400 Mar 21 22:46 openssl-devel-1.0.2k-26.el7_9.x86_64.rpm
-rw-r--r-- 1 root root 1256452 Mar 21 22:47 openssl-libs-1.0.2k-26.el7_9.x86_64.rpm
-rw-r--r-- 1 root root  491272 Aug 11  2017 pcre-devel-8.32-17.el7.x86_64.rpm
drwxr-xr-x 2 root root    4096 Jun 22 17:10 repodata
-rw-r--r-- 1 root root 2808842 Jun 22 17:09 sc_nginx-1.22.1-1.x86_64.rpm
-rw-r--r-- 1 root root   92260 Mar  8 21:24 zlib-1.2.7-21.el7_9.x86_64.rpm
-rw-r--r-- 1 root root   51488 Mar  8 21:24 zlib-devel-1.2.7-21.el7_9.x86_64.rpm
 #生成仓库信息
[root@hadoop101 pub]#createrepo  /yum/repository
#更新仓库   //每加入或者删除一个rpm包就要更新一下!!!!!!
[root@web02 repository]# createrepo --update /yum/repository/
 #编写nginx配置文件  //记得打包默认文件配置文件
 gzip /etc/nginx/conf.d/default.conf 
 [root@web02 ~]# vim /etc/nginx/conf.d/yum.conf
 server {
        listen 80;
        server_name _;
        root /yum/repository;

        location / {
                autoindex on;
                autoindex_exact_size off;
        }
}
#启动服务
systemctl start nginx
#浏览器访问验证
10.0.0.8

image-20230622172709400

web03测试yum仓库是否成功

# 删除原先yum源,打包也行,这里用于测试环境 。所有删除无影响,生产环境中删除需谨慎
[root@web03 yum.repos.d]# rm /etc/yum.repos.d/*
#编写yum配置文件
[root@web03 yum.repos.d]# vim yum.repo
[jiujiu]
name=shared repository
baseurl=http://10.0.0.8
gpgcheck=0
enabled=1
#清楚yum缓存
yum clean all
#加载缓存
yum makecache
#安装测试
yum install -y pcre-devel zlib-devel openssl-devel
yum install -y nginx
#启动服务   //启动用户为默认,可看情况更改
[root@web03 yum.repos.d]# systemctl start nginx
[root@web03 yum.repos.d]# ps -ef | grep nginx
root       9659      1  0 18:25 ?        00:00:00 nginx: master process /app/nginx/sbin/nginx -c /app/nginx/conf/nginx.conf
nobody     9660   9659  0 18:25 ?        00:00:00 nginx: worker process
root       9662   9526  0 18:25 pts/0    00:00:00 grep --color=auto nginx