It is very troublesome to install the source code every time, so make an RPM package directly
Install the rpm-build package
[root@proxy ~]# yum -y install rpm-build
Generate rpmbuild directory structure
Perhaps the rpmbuild directory and subdirectories will only be generated if a non-existent directory is generated in the home directory
If you want to generate it in the directory you created, you have to create it manually, the subdirectory
[root@proxy ~]# rpmbuild -ba xxx #会报错,没有文件或目录(目的是生成下面的
目录和子目录)
[root@proxy ~]# ls rpmbuild/
Preparation, copy the source code software to the SOURCES directory
Find your tar source package and put it under 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
Explanation of the above
[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
Install dependent packages
yum -y install gcc pcre-devel openssl-devel
rpmbuild Create RPM packages
[root@proxy SPECS]# rpmbuild -ba nginx.spec
[root@proxy SPECS]# cd /root/rpmbuild/RPMS/x86_64/
Test installation 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的描述信息
Errors that may occur after building the RPM package , the following errors occur during the compilation process, follow the prompts that there is no make command to install directly and then re-execute
what are they doing
BUILD/ RPMS/ SOURCES/ SPECS/ SRPMS/
The SPECS directory is used to store the spec file of the RPM package, and write a spec file to describe the details and construction steps of the RPM package
The SOURCES directory is used to store the source code and patch files required by the RPM package
createrepo
Create a directory, put the rpm package in it and run createrepo (install one without this command) directory
There will be a repodata subdirectory inside, and you can create a local yum source at this time