10.1.Nginx编译安装

Nginx编译安装

1.需不需要编译安装

我们根据生成环境需求来选择安装方式,在我们学习中安装方式选择yum的安装方式较多,因为操作比较简单,利于学习。可是当我们生成环境中遇到要求我们需要通过已经安装过nginx的环境去安装一样的环境的nginx时,就需要通过编译安装的方式

2.编译安装思路

2.1 获取原有环境的编译参数

①在这个实验中我们用到两台节点,一台web01(安装过nginx服务),一台nfs(我们需要编译安装的)
②那么我们获取原有的环境的编译参数就是去web01节点上,使用如下命令。
nginx -v  #获取版本
nginx -V  #获取nginx编译参数

在这里插入图片描述

–prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC’ --with-ld-opt=’-Wl,-z,relro -Wl,-z,now -pie’

在生成环境中,有些公司会使用到第三方模块,会已 --add-module=/etc/文件显示出来,我们把模块考进新环境中即可。

2.2 在新的环境重新下载软件包安装(在nfs节点上操作)

①因为在编译安装中,不会像rpm安装时调用创建用户脚本,所以缺少管理nginx服务的nginx用户,我们要手动的把nginx用户创建出来
groupadd nginx
useradd nginx -g nginx
②我们在第一次编译安装时,去nginx官网找寻需要自己编译安装的nginx版本。我们在这里选择安装nginx-1.16.1版本,我们用wget网上在线下载的方式安装在我们需要部署的虚拟机上(nfs节点)

在这里插入图片描述

 wget http://nginx.org/download/nginx-1.16.1.tar.gz
 tar xf nginx-1.16.1.tar.gz 
③编译安装nginx的目录结构

在这里插入图片描述

2.3接下来我们开始编译nginx源码包

① ./configure 定义软件的路径\定义软件模块\ —> Makefile文件

我们把从原有环境提取的编译参数,加上./configure命令 在部署节点上进行操作,来检查依赖关系有没有缺少包.
如果缺少根据提示我们进行安装,如果知道缺少什么包我们可以在编译安装前提前进行一个初始化的安装。

./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx
–modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC’ --with-ld-opt=’-Wl,-z,relro -Wl,-z,now -pie’

我们运行之后提示缺少rewtite模块的有关于PRCE库中的开发包,和https有关的openssl开发包。
我们进行手动填充安装,再进行检测,缺少什么我们就安装什么,最后到检测没有报错。

在这里插入图片描述

yum -y install prce-devel 
yum -y install openssl-devel 

再检查没有缺少的依赖包之后,会在nginx-1.16.1目录下生成Makefile ACSII文件,还有在objs目录下生成Makefile的一个脚本文件。

我们看一下nginx-1.16.1目录下生成Makefile 文件里面

在这里插入图片描述

我们在第二步执行make操作时会读取这个文件,调用objs/Makefile里面的信息。
在这里插入图片描述
在这里插入图片描述

② make 读取清单,然后进行编译的操作 [可执行的二进制文件]

我们在执行make操作后可以用echo $? 查看有无报错
我们在执行make操作后会在objs/下生成一个名称为nginx的二进制文件

在这里插入图片描述

③ make install 将配置文件\二进制文件拷贝到指定的目录下

我们执行make install 操作读取的是objs/Makefile 里面定义的操作 将配置文件\二进制文件拷贝到指定的目录下
在这里插入图片描述

配置好之后,我们nginx -t 语法检查一下,发现缺少关于nginx缓存的一个目录,我们把它创建出来就好了。

mkdir -p  /var/cache/nginx/client_temp

在这里插入图片描述

2.4 启动nginx与关闭

启动Nginx 停止Nginx
		[root@nfs nginx-1.16.1]# nginx -c /etc/nginx/nginx.conf
		[root@nfs nginx-1.16.1]# nginx -s stop
		netstat -lntup #检查nginx端口是否启动
		ps -ef |grep nginx #检查nginx进程是否启动

在这里插入图片描述

在这里插入图片描述

查看一下我们nginx的版本
在这里插入图片描述

2.5 访问一下nginx站点(nfs 10.0.0.31)

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值