定制rpm包

定制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

1651136097940

源码安装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包

1651218862384

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
posted @   安(za)  阅读(63)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示