龙空技术网

Nginx之stream模块的编译和使用详细教程

活力小子2050 150

前言:

今天各位老铁们对“nginx slice”大体比较注重,姐妹们都需要学习一些“nginx slice”的相关内容。那么小编也在网摘上搜集了一些关于“nginx slice””的相关内容,希望各位老铁们能喜欢,看官们快快来了解一下吧!

一、yum安装nginx

1.yum install nginx -y 当前默认版本为1.20.1

2.nginx -V查看当前nginx配置模块

3.操作命令

systemctl start nginx.service -------------- 启动

systemctl stop nginx.service -------------- 停止

systemctl restart nginx.service -------------- 重启

systemctl reload nginx.service -------------- 重新加载配置

systemctl enable nginx.service -------------- 设置开机自启动

二、编译安装stream模块

1.下载一个同版本可编译的nginx

cd /opt wget

tar -zxvf nginx-1.20.1.tar.gz && cd nginx-1.20.1

2.备份原nginx文件

cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf-20200101

3.安装依赖

yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmakepcre-develnanowget gcc gcc-c++ ncurses-devel per redhat-rpm-config.noarch

4.重新编译nginx文件

在第2步查到的模块配置后追加

./configure --prefix=/usr/local/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 --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --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-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --with-stream

5.如编译时缺少依赖可执行以下命令

yum -y install libxml2 libxml2-dev libxslt-devel

yum -y install gd-devel

yum -y installperl-devel perl-ExtUtils-Embed

yum -y install GeoIP GeoIP-devel GeoIP-data

yum -y install pcre-devel

yum -y install openssl openssl-devel

6.如遇到一下错误可以按下面方式解决

错误1:./configure: error: the invalid value in --with-ld-opt="-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E"

解决方法:yum -y install redhat-rpm-config.noarch

错误2:./configure: error: the HTTP image filter module requires the GD library.

解决方法: yum -y install gd-devel

错误3:./configure: error: perl module ExtUtils::Embed is required

解决方法:yum -y install perl-devel perl-ExtUtils-Embed

7.编译通过,继续验证

注:编译完成make一下就可以了,不要make install。若是用make install则相当于重新安装nginx,会覆盖之前的配置文件。

/opt/software/nginx-1.20.1/objs/nginx -t

/opt/software/nginx-1.20.1/objs/nginx -V

8.暂停nginx,替换nginx文件并重启

cp /opt/software/nginx-1.20.1/objs/nginx /usr/local/nginx/sbin

systemctl start nginx

三、添加stream配置,并验证(conf文件:/etc/nginx/nginx.conf)

stream {

upstream web1{

server 10.10.10.1:4430;

}

server {

listen 4430;

proxy_connect_timeout 5s;

proxy_timeout 300s;

proxy_pass web1;

}

标签: #nginx slice