The linux source code is made into RMP and added to the yum source

Ready to work

The main function of yum (Yellow dog Updater, Modified) is to facilitate adding, deleting and updating rpm packages. It can solve the problem of package dependencies and make it easier to manage a large number of system update problems. It can configure multiple repositories or repositories at the same time, which is where updated and dependent packages are stored.
Experimental environment:
[root@cache ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.2 (Maipo)
host: cache ip address: 192.168.4.2
host: db1 ip address: 192.168.4.3
Note: two hosts Both yum sources can handle other dependencies.
The following link is the prepared source package and the prepared rpm package, which can be downloaded and used directly if necessary.
Link: https://pan.baidu.com/s/1RtKyNrssQDK0UL9mzt4q0w Password: n87r

First, the source code is made into an RPM package

Make the source code into an RMP package on the host cache

[root@cache ~]# yum -y install rpm-build        //用于做rpm包的工具
[root@cache ~]# rpmbuild  -ba nginx-1.8.0.tar.gz     //故意让这个命令报错,用于生成6个文件
[root@cache ~]# ls                         //查看/root下会生成rpmbuild目录
anaconda-ks.cfg  Downloads             nginx-1.8.0.tar.gz  rpmbuild
[root@cache ~]# ls /root/rpmbuild/            //查看6个自动生成的目录
BUILD  BUILDROOT  RPMS  SOURCES  SPECS  SRPMS
[root@cache ~]# cp /root/nginx-1.8.0.tar.gz   /root/rpmbuild/SOURCES/                              //将下载好的源码包拷贝到SOURCES目录下
[root@cache ~]# ls /root/rpmbuild/SOURCES/
nginx-1.8.0.tar.gz
[root@cache ~]# cd /root/rpmbuild/SPECS/          //存放spec文件的目录
[root@cache SPECS]# vim nginx.spec      //创建nginx.spec文件,文件内会自动在文件生成一些内容,以下是删除一部分的内容
Name:nginx                    //不能任意,为软件名
Version:1.8.0                  //不能任意,为软件版本号
Release:1                      //第几次打rpm包
Summary:      this is nginx rpm   //概述,内容可以任意
License:GPL                              //可以任意修改,复制,发布  
Source0:nginx-1.8.0.tar.gz       //不能任意,必须和源码包名字一样
%description
%prep
%setup -q                                //自动解压并cd
%build
./configure                               //把% 改成./
make %{?_smp_mflags}
%install
make install DESTDIR=%{buildroot}
%files
%doc
/usr/local/nginx/*                      //对这个文件压缩
[root@cache SPECS]# yum -y install gcc pcre-devel openssl-devel                                       //安装依赖包
[root@cache SPECS]# ls /root/rpmbuild/RPMS/x86_64/
nginx-1.8.0-1.x86_64.rpm  nginx-debuginfo-1.8.0-1.x86_64.rpm
[root@cache x86_64]# scp nginx-1.8.0-1.x86_64.rpm 192.168.4.3:/root                  //将rpm包拷贝到db1上

Second, the rpm package is added to the yum source

Add the prepared rpm package to the local yum source on the host db1, and install it for testing

[root@db1 ~]# mkdir /nginx                   //创建nginx目录,用于做本地的yum源,目录名字任意
[root@db1 ~]# cp nginx-1.8.0-1.x86_64.rpm /nginx/    将做好的rmp包拷贝到yum源目录
[root@db1 ~]# createrepo /nginx/       //创建yum仓库的,createrepo 目录
[root@db1 ~]# ls /nginx/         //查看,会多个自动生成的repodata目录
nginx-1.8.0-1.x86_64.rpm  repodata
[root@db1 ~]# yum-config-manager --add file:///nginx    //添加本地yum仓库
[root@db1 ~]# yum clean all        //清除
[root@db1 ~]# yum repolist         //显示yum源信息列
源标识                       源名称                                          状态
192.168.4.254_rh7dvd_        added from: http://192.168.4.254/rh7dvd/        4,620
nginx                        added from: file:///nginx                           1
repolist: 4,621
[root@db1 ~]# yum -y install nginx      //用yum安装nginx
[root@db1 ~]# /usr/local/nginx/sbin/nginx       //启动nginx,启动前80端口必须被释放
[root@db1 ~]# ss -anptu | grep :80                    //查看80端口被nginx占用
tcp    LISTEN     0      128       *:80                    *:*                   users:(("nginx",pid=8384,fd=6),("nginx",pid=8383,fd=6))
[root@db1 ~]# rpm -qi nginx          //查看安装的nginx信息,和nginx.spec内的信息一致
Name        : nginx
Version     : 1.8.0
Release     : 1
Architecture: x86_64
Install Date: 2018年04月26日 星期四 03时28分19秒
Group       : Unspecified
Size        : 660775
License     : GPL
Signature   : (none)
Source RPM  : nginx-1.8.0-1.src.rpm
Build Date  : 2018年04月26日 星期四 03时15分45秒
Build Host  : cache
Relocations : (not relocatable)
Summary     : this is nginx rpm
Description :

共勉:I hear and I forget , I see and I remember, I do and I understand!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324973407&siteId=291194637
Recommended