目录
定制rpm包
定制rpm包概述
什么是定制rpm包
将原本,使用源码安装的服务,打包成rpm包
为什么要定制rpm包
使用源码安装,步骤繁琐复杂,浪费时间,把源码包打成rpm包安装可以节省时间,提高工作效率,做好rpm包,可以将rpm包放入yum仓库中,方便安装
如何定制rpm包
-
fpm
-
rpmbuild
安装fpm
fpm是ruby语法写的一种,定制rpm包的工具,所以安装fpm之前,需要安装ruby环境
# 1.下载阿里云的base源和epel源
[root@localhost ~]# gzip -r /etc/yum.repos.d/
[root@localhost ~]# ll /etc/yum.repos.d/
total 32
-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
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
[root@localhost ~]# yum repolist all
# 2.安装ruby环境
[root@localhost ~]# yum -y install ruby rubygems ruby-devel
# 3.查看gem默认的源
[root@localhost ~]# gem sources
*** CURRENT SOURCES ***
https://rubygems.org/
gem作用:gem和yum差不多,是包管理工具,yum来管理.rpm包,gem来管理.gem包
# 4.删除gem默认官方源
[root@localhost ~]# gem source --remove https://rubygems.org/
https://rubygems.org/ removed from sources
[root@localhost ~]# gem sources
*** CURRENT SOURCES ***
# 5.添加阿里云的gem源
[root@localhost ~]# gem sources -a https://mirrors.aliyun.com/rubygems/
https://mirrors.aliyun.com/rubygems/ added to sources
[root@localhost ~]# gem sources
*** CURRENT SOURCES ***
https://mirrors.aliyun.com/rubygems/
# 6.安装fpm
[root@localhost ~]# gem install fpm -v 1.3.3 # 贼慢
# 使用fpm压缩包
[root@localhost ~]# mkdir lza
[root@localhost ~]# ll
total 1264
-rw-------. 1 root root 1448 Apr 25 12:01 anaconda-ks.cfg
-rw-r--r--. 1 root root 1288103 Apr 28 10:40 fpm-1.3.3.x86_64.tar.gz
drwxr-xr-x. 2 root root 6 Apr 28 16:51 lza
[root@localhost ~]# mv fpm-1.3.3.x86_64.tar.gz lza/
[root@localhost lza]# tar xf fpm-1.3.3.x86_64.tar.gz
[root@localhost lza]# gem install *.gem
源码安装nginx
# 0.开启yum安装包缓存
[root@localhost ~]# vim /etc/yum.conf
keepcache=0 改成 keepcache=1
# 1.nginx官网,下载源码包
[root@localhost ~]# wget http://nginx.org/download/nginx-1.20.2.tar.gz
[root@localhost ~]# ll
total 1044
-rw-r--r--. 1 root root 1062124 Nov 16 22:51 nginx-1.20.2.tar.gz
# 2.解压
[root@localhost ~]# tar xf nginx-1.20.2.tar.gz
# 3.生成
[root@localhost ~/nginx-1.20.2]# ./configure --prefix=/opt/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module
# 4.安装依赖包
[root@localhost nginx-1.20.2]# yum install -y pcre-devel openssl-devel gcc gcc-c++ glibc zlib-devel
# 5.编译(让系统能识别你的代码,并且把刚才指定的功能和路径编译到源码中)
[root@localhost nginx-1.20.2]# make
# 6.安装
[root@localhost nginx-1.20.2]# make install
# 7.做软链接
[root@localhost nginx-1.20.2]# ln -s /opt/nginx-1.20.2/ /opt/nginx
# 8.添加nginx的环境变量,让nginx程序可以直接运行
[root@localhost opt]# vim /etc/profile.d/nginx.sh
export PATH="$PATH:/opt/nginx/sbin"
# 9.加载环境变量
[root@localhost opt]# source /etc/profile
# 10.启动nginx
[root@localhost ~]# nginx
# 11.检查nginx是否启动成功(端口)
[root@localhost ~]# netstat -lntup|grep nginx
# 12.检查nginx进程
[root@localhost ~]# ps -ef|grep nginx
# 13.关闭防火墙
[root@localhost ~]# systemctl stop firewalld
# 14.关闭selinux
[root@localhost ~]# setenforce 0
# 15.编辑配置文件
[root@localhost /opt/nginx/html]# cd /opt/nginx/conf/
[root@localhost /opt/nginx/conf]# vi nginx.conf
检测nginx配置文件语法
[root@localhost ~]# nginx -t
# 16.重启nginx
[root@localhost /opt/nginx/conf]# nginx -s reload
# 17.创建目录
[root@localhost ~]# mkdir -p /data/yum_data
使用fpm定制rpm包
fpm
-s:指定将什么打成rpm包(dir将目录打成rpm包)
-t:打成什么包(rpm 打成rpm包)
-n:指定包名,-n如何指定,yum就如何安装(nginx) yum install -y nginx
-v:指定版本号
-d:指定依赖包,在这指定后,yum安装的时候,会根据-d的内容自动安装对应的依赖
--post-innstall:安装rpm之后,要执行的脚本
--pre-install:安装rpm之前,要执行的脚本
--post-uninstall:卸载rpm包之后,要执行的脚本
--pre-uninstall:卸载rpm包之前,要执行的脚本
-f:指定要打包的路径
# 安装nginx之后
1.做软链接
2.添加nginx的环境变量
# 先写脚本
[root@localhost ~]# vim nginx.sh
ln -s /opt/nginx-1.20.2 /opt/nginx
echo 'PATH="/opt/nginx/sbin:$PATH"' > /etc/profile.d/nginx.sh
# fpm打包
[root@localhost ~]# fpm -s dir -t rpm -n nginx -v 1.20.2 -d 'openssl-devel,pcre-devel,gcc,gcc-c++,glibc ' --post-install /root/nginx.sh -f /opt/nginx-1.20.2
# 将nginx安装包剪切到/data/yum_data目录下
[root@localhost yum_data]# mv /root/nginx-1.20.2-1.x86_64.rpm ./
安装依赖包
[root@localhost yum_data]# ll
total 31472
-rw-r--r--. 1 root root 16963328 Oct 15 2020 gcc-4.8.5-44.el7.x86_64.rpm
-rw-r--r--. 1 root root 7531804 Oct 15 2020 gcc-c++-4.8.5-44.el7.x86_64.rpm
-rw-r--r--. 1 root root 5595673 Apr 28 18:44 nginx-1.20.2-1.x86_64.rpm
-rw-r--r--. 1 root root 1581408 Aug 23 2019 openssl-devel-1.0.2k-19.el7.x86_64.rpm
-rw-r--r--. 1 root root 491272 Aug 11 2017 pcre-devel-8.32-17.el7.x86_64.rpm
-rw-r--r--. 1 root root 51128 Nov 12 2018 zlib-devel-1.2.7-18.el7.x86_64.rpm
# 把目录变成仓库
[root@localhost yum_data]# createrepo /data/yum_data
# 编辑其它机器.repo配置
[root@localhost ~]# gzip -r /etc/yum.repos.d
[root@localhost ~]# vi /etc/yum.repos.d/lzayuan.repo
# 使用yum安装
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
[root@localhost ~]# yum repolist all
作业
1.制作一个nginx的yum仓库
2.nginx打好的rpm包和nginx所有的依赖包放入yum仓库
3.其他机器,不使用其他yum源情况下,只使用自定义nginx仓库安装nginx
安装fpm
# 1.安装ruby环境
[root@localhost ~]# yum install -y ruby rubygems ruby-devel rpm-build
# 2.更改gem源
## 查看gem源
[root@localhost ~]# gem sources
*** CURRENT SOURCES ***
https://rubygems.org/
## 删除官方genm源
[root@localhost ~]# gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources
## 添加阿里云gem源
[root@localhost ~]# gem sources --add https://mirrors.aliyun.com/rubygems/
# 3.下载fpm包
[root@localhost ~]# wget http://test.driverzeng.com/other/fpm-1.3.3.x86_64.tar.gz
# 4.解压
[root@localhost ~]# mkdir fpm
[root@localhost ~]# ll
drwxr-xr-x 2 root root 6 Apr 29 09:00 fpm
-rw-r--r-- 1 root root 1288103 Jul 14 2016 fpm-1.3.3.x86_64.tar.gz
[root@localhost ~]# mv fpm-1.3.3.x86_64.tar.gz fpm
[root@localhost ~]# cd fpm/
[root@localhost fpm]# ll
total 1260
-rw-r--r-- 1 root root 1288103 Jul 14 2016 fpm-1.3.3.x86_64.tar.gz
[root@localhost fpm]# tar xf fpm-1.3.3.x86_64.tar.gz
# 5.安装fpm工具
[root@localhost fpm]# gem install *.gem
源码安装nginx
# 0.开启yum安装包缓存
[root@localhost ~]# vim /etc/yum.conf
keepcache=0 改成 keepcache=1
# 1.安装依赖包
[root@localhost ~]# find /var/cache/yum/ -type f -name '*.rpm'
[root@localhost ~]# yum install -y pcre-devel openssl-devel
# 2.查找yum缓存,把所有rpm包拷贝到opt目录下
[root@localhost ~]# find /var/cache/yum/ -type f -name '*.rpm'|xargs cp -t /opt/
# 3.把所有依赖包打成一个tar包
[root@localhost opt]# tar zcf nginx_require.tar.gz *.rpm
# 4.创建安装包存放目录和安装目录
## 安装包存放的目录
[root@localhost ~]# mkdir /pkg_tools
## 应用安装目录
[root@localhost ~]# mkdir /application
# 5.下载nginx源码包
[root@localhost ~]# wget -O /pkg_tools/nginx-1.20.2.tar.gz
http://nginx.org/download/nginx- 1.20.2.tar.gz
# 6.解压
[root@localhost ~]# cd /pkg_tools/
[root@localhost pkg_tools]# ll
total 1040
-rw-r--r-- 1 root root 1062124 Nov 16 22:51 nginx-1.20.2.tar.gz
[root@localhost pkg_tools]# tar xf nginx-1.20.2.tar.gz
# 7.进入源码包目录
[root@localhost pkg_tools]# cd nginx-1.20.2/
# 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
将nginx源码包打成rpm包
# 1.创建脚本目录
[root@localhost ~]# mkdir /scripts
# 2.写安装后的脚本
[root@localhost ~]# 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 ~]# 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
--post-uninstall
nginx做yum仓库
# 1.安装nginx
[root@web01 ~]# yum install -y nginx
# 2.修改nginx配置文件
[root@web01 ~]# vim /etc/nginx/nginx.conf
42 root /yum_repo;
43 autoindex on;
# 3.启动nginx
[root@web01 ~]# nginx
# 4.创建/yum_rpeo目录
[root@web01 ~]# mkdir /yum_repo
# 5.创建nginx仓库目录
[root@web01 ~]# mkdir /yum_repo/nginx
# 6.安装制作yum仓库的命令
[root@web01 ~]# yum install -y createrepo
# 7.拷贝打包机器上所有rpm包到yum仓库中
[root@localhost ~]# scp nginx-1.20.2-1.x86_64.rpm [email protected]:/yum_repo/nginx
[root@localhost ~]# scp /opt/nginx_require.tar.gz [email protected]:/yum_repo/nginx
# 8.解压依赖包
[root@web01 nginx]# tar xf nginx_require.tar.gz
# 9.制作yum仓库
[root@web01 nginx]# createrepo /yum_repo/nginx/
# 10.关闭防火墙,关闭selinux
[root@web01 nginx]# systemctl stop firewalld
[root@web01 nginx]# setenforce 0
测试其它机器
# 1.压缩所有其他系统的yum源
[root@db01 ~]# gzip -r /etc/yum.repos.d/
# 2.手写yum源配置文件
[root@db01 ~]# vim /etc/yum.repos.d/nginx.repo
[zls_nginx]
name=Ningx Repository By ZLS
baseurl=http://10.0.0.7/nginx/
gpgcheck=0
enabled=1
# 3.测试
[root@db01 ~]# yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
zls_nginx
| 2.9 kB 00:00:00
zls_nginx/primary_db
| 16 kB 00:00:00
repo id repo name
status
zls_nginx Ningx Repository By ZLS
22
repolist: 22
[root@db01 ~]# yum install -y nginx
标签:--,rpm,nginx,yum,定制,root,localhost
From: https://www.cnblogs.com/LZA1218/p/16769924.html