制作RPM包&&createrepo

每次源码安装很费事,所以直接做一个RPM包

安装 rpm-build 软件包 

[root@proxy ~]# yum -y install rpm-build 

 生成 rpmbuild 目录结构

或许只有在家目录下生成一个不存在的目录才会生成 rpmbuild目录和子目录

若想在自己创建的目录下生成只有自己手动去创建,子目录

[root@proxy ~]# rpmbuild -ba xxx #会报错,没有文件或目录(目的是生成下面的
目录和子目录)
[root@proxy ~]# ls rpmbuild/

准备工作,将源码软件复制到 SOURCES 目录 

找到你的tar源码包,放到SOURCES下

[root@proxy ~]# cp lnmp_soft/nginx-1.16.1.tar.gz rpmbuild/SOURCES/
[root@proxy ~]# cd rpmbuild/SPECS/
Name:nginx
Version:1.16.1
Release: 1%{?dist}
Summary:Nginx is a web server
#Group:
License:GPL
URL:www.douniwan.com
Source0:nginx-1.16.1.tar.gz
#BuildRequires:
#Requires:
%description
this is a web server toooooooooooooooooooo
%post
useradd nginx
%prep
%setup -q
%build
./configure
make %{?_smp_mflags}
%install
make install DESTDIR=%{buildroot}
%files
%doc
/usr/local/nginx/*
%changelog

对上文的解释 

[root@proxy SPECS]# vim nginx.spec #以spec结尾,编写配置文件
Name:nginx #源码包软件名称
Version:1.16.1 #源码包软件的版本号
Release: 1%{?dist} #制作的RPM包版本号
Summary:Nginx is a web server #RPM软件的概述
#Group: #nginx不属于其他组包
License:GPL #软件的协议,GPL是可以免费使用,免费修改软件
URL:www.douniwan.com #网址
Source0:nginx-1.16.1.tar.gz #源码包文件的全称
#BuildRequires: #不提示制作RPM时的依赖关系
#Requires: #安装RPM时的依赖关系
%description #软件的详细信息
this is a web server toooooooooooooooooooo
%post #安装后脚本,创建用户
useradd nginx
%prep
%setup -q #自动解压源码包,并cd进入目录
%build
./configure #配置
make %{?_smp_mflags}
%install
make install DESTDIR=%{buildroot}
%files
%doc
/usr/local/nginx/* #对哪些文件与目录打包
%changelog

 安装依赖软件包

yum -y install gcc pcre-devel openssl-devel

rpmbuild 创建 RPM 软件包 

[root@proxy SPECS]# rpmbuild -ba nginx.spec
[root@proxy SPECS]# cd /root/rpmbuild/RPMS/x86_64/

 测试安装 nginx

[root@proxy x86_64]# /usr/local/nginx/sbin/nginx -s stop
[root@proxy x86_64]# rm -rf /usr/local/nginx/
[root@proxy x86_64]# yum -y install nginx-1.16.1-1.el7.centos.x86_64.rpm
[root@web1 ~]# ls /usr/local/nginx/
[root@web1 ~]# yum info nginx #查看nginx的描述信息

 构建RPM包后可能出现的报错,编译过程中出现以下报错,按照提示说没有make命令 直接安装即可重新执行

 

都是干什么的

BUILD/ RPMS/ SOURCES/ SPECS/ SRPMS/

SPECS 目录用于存放 RPM 包的 spec 文件,编写一个 spec 文件来描述 RPM 包的详细信息和构建步骤

SOURCES 目录用于存放 RPM 包所需的源代码和补丁文件

createrepo

创建一个目录,把rpm包放在里面 运行createrepo(没有此命令安装一个) 目录 即可

里面就会有一个repodata的子目录,此时你就可以创建本地yum源了

猜你喜欢

转载自blog.csdn.net/weixin_55000003/article/details/130628665