软件准备:
在 Nginx 官网上下载搭建集群所需软件 Nginx:
http://nginx.org/en/download.html
正文:
步骤目录:
步骤一:系统环境要求
步骤二:准备 rpm-build 软件
2.1 安装 rpm-build
2.2 生成 rpm-build 目录
2.3 查看生成的 rpm-build 目录
步骤三:制作 Nginx 软件的 rpm 包
3.1 将 Nginx 的源码安装包放在固定的位置
3.2 制作 Nginx 的 nginx.spec 文件
3.3 SPEC 配置文件里的内容说明
3.4 安装 Nginx 软件的依赖包
3.6 查看新生成的 Nginx rpm 软件包
步骤四:使用新生成的 Nginx rpm 软件包
4.1 安装刚刚新生成的 Nginx rpm 软件包
4.2 启动 Nginx 服务
4.3 查看 Nginx 服务的启动状态
4.3.1 查看 Nginx 网页是否可以访问
4.3.2 查看 Nginx 的端口有没有启动
具体的操作步骤:
步骤一:系统环境要求
(1)服务器的系统是 CentOS 7.X 版本
(2)服务器系统要配置好 yum 源
步骤二:准备 rpm-build 软件
2.1 安装 rpm-build
# yum -y install rpm-build
2.2 生成 rpm-build 目录
# rpmbuild -ba nginx.spec
error: failed to stat /root/nginx.spec: No such file or directory
2.3 查看生成的 rpm-build 目录
# ls /root/rpmbuild/
BUILD BUILDROOT RPMSSOURCES SPECSSRPMS
步骤三:制作 Nginx 软件的 rpm 包
3.1 将 Nginx 的源码安装包放在固定的位置
# cp nginx-1.16.1.tar.gz /root/rpmbuild/SOURCES/
3.2 制作 Nginx 的 nginx.spec 文件
# vi /root/rpmbuild/SPECS/nginx.spec
将部分内容修改如下:
Name:nginx
Version:1.16.1
Release:1.0
Summary:Nginx is a web server software.
License:GPL
URL:www.nginx.org
Source0:%{name}-%{version}.tar
%description
nginx is an HTTP and reverse proxy server ......
%post
useradd nginx
%prep
%setup -q
%build
./configure --user=nginx --group=nginx --with-http_ssl_module
make %{?_smp_mflags}
%install
make install DESTDIR=%{buildroot}
%files
%doc
/usr/local/nginx/*
%changelog
3.3 SPEC 配置文件里的内容说明
Name:nginx #软件的名称
Version:1.16.1 #软件版本
Release:1.0 #RPM 的版本
Summary: Nginx is a web server software. #软件的描述
Group:
License:GPL #软件使用的协议
URL:www.nginx.org #软件的官网
Source0:%{name}-%{version}.tar #软件源码文件的名称
#BuildRequires: #软件编译安装时需要的依赖包
#Requires: #软件安装时所需要的依赖包
%description #软件的详细描述
%post
useradd nginx #软件安装后执行的脚本,例如创建用户,非必要操作
%prep #软件安装前的准备,例如解压
%setup –q #自动解压软件的源码包,并 cd 进入刚刚解压出来的目录
%build #软件编译安装时所需要执行的命令
./configure
make %{?_smp_mflags}
%install #软件安装时需要执行的命令
make install DESTDIR=%{buildroot}
%files
%doc
/usr/local/nginx/* #对软件中的哪些文件与目录打包
%changelog
3.4 安装 Nginx 软件的依赖包
# yum -y install gcc pcre-devel openssl-devel
3.5 生成 Nginx rpm 软件包
# rpmbuild -ba /root/rpmbuild/SPECS/nginx.spec
3.6 查看新生成的 Nginx rpm 软件包
# rpm -qpi /root/rpmbuild/RPMS/x86_64/nginx-1.16.1-1.0.x86_64.rpm
步骤四:使用新生成的 Nginx rpm 软件包
4.1 安装刚刚新生成的 Nginx rpm 软件包
# rpm -ivh /root/rpmbuild/RPMS/x86_64/nginx-1.16.1-1.0.x86_64.rpm
4.2 启动 Nginx 服务
# /usr/local/nginx/sbin/nginx
4.3 查看 Nginx 服务的启动状态
4.3.1 查看 Nginx 网页是否可以访问
# curl http://127.0.0.1/
4.3.2 查看 Nginx 的端口有没有启动
# ss -ntulap | grep 80