linux 源码做成RMP并加入yum源

准备工作

yum(Yellow dog Updater,Modified)主要的功能是方便添加、删除和更新rpm软件包。可以解决软件包依存问题,更便于管理大量的系统更新问题。它可以同时配置多个仓库或叫资源库(repository),就是存放更新和依存的软件包的地方。
实验环境:
[root@cache ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.2 (Maipo)
主机:cache ip地址:192.168.4.2
主机:db1 ip地址:192.168.4.3
注:两个主机都yum源,可以处理其他的依赖关系
下面连接是准备好的源码包,以及做好的rpm包,有需要的可以直接下载使用。
链接: https://pan.baidu.com/s/1RtKyNrssQDK0UL9mzt4q0w 密码: n87r

一,源码做成RPM包

在主机cache上把源码做成RMP包

[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上

二,rpm包加入yum源

在主机db1上将做好的rpm包加入本地的yum源,并安装测试

[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!

猜你喜欢

转载自blog.51cto.com/13667098/2108175