编译nginx平滑添加stream模块
1、操作背景
操作系统版本:CentOS Linux release 7.4. (Core)
nginx版本:1.13.4 nginx从1.9.0版本开始,新增了ngx_stream_core_module模块,使nginx支持四层负载均衡。默认编译的时候该模块并未编译进去,需要编译的时候添加--with-stream,使其支持stream代理。
2、nginx编译添加stream模块
2.1、查看原nginx编译参数
[root@test-server sbin]# nginx -V
nginx version: nginx/1.13.
built by gcc 4.8. (Red Hat 4.8.-) (GCC)
built with OpenSSL 1.0.2k-fips Jan
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_gzip_static_module --http-client-body-temp-path=/usr/local/nginx/tmp/client/ --http-proxy-temp-path=/usr/local/nginx/tmp/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/tmp/fcgi/ --with-poll_module --with-file-aio --with-http_realip_module --with-http_addition_module --with-http_addition_module --with-http_random_index_module --with-http_stub_status_module --http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/nginx/scgi_temp --with-pcre=/usr/local/src/pcre-8.41
2.2、添加stream模块进行重新编译
此处nginx源码目录为:/usr/local/src/nginx-1.13.4,即为编译命令执行目录。 编译命令如下:
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_gzip_static_module --http-client-body-temp-path=/usr/local/nginx/tmp/client/ --http-proxy-temp-path=/usr/local/nginx/tmp/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/tmp/fcgi/ --with-poll_module --with-file-aio --with-http_realip_module --with-http_addition_module --with-http_addition_module --with-http_random_index_module --with-http_stub_status_module --http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/nginx/scgi_temp --with-pcre=/usr/local/src/pcre-8.41 --with-stream
2.3、进行make操作
此处nginx源码目录为:/usr/local/src/nginx-1.13.,即为编译命令执行目录。
make 此处一定不能使用make install命令,执行该命令会将原有nginx目录进行覆盖。
3、关停nginx同时复制新的nginx启动文件
关闭nginx服务
systemctl stop nginx 备份原有nginx二进制文件。
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx-no-strem 复制新编译好的nginx二进制文件。从此处nginx源码目录为:/usr/local/nginx-1.13.4。即为编译命令执行目录。
cp ./objs/nginx /usr/local/nginx/sbin/nginx
4、启动测试
启动nginx。
systemctl start nginx 查看nginx模块信息。
nginx -V
nginx version: nginx/1.13.
built by gcc 4.8. (Red Hat 4.8.-) (GCC)
built with OpenSSL 1.0.2k-fips Jan
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_gzip_static_module --http-client-body-temp-path=/usr/local/nginx/tmp/client/ --http-proxy-temp-path=/usr/local/nginx/tmp/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/tmp/fcgi/ --with-poll_module --with-file-aio --with-http_realip_module --with-http_addition_module --with-http_addition_module --with-http_random_index_module --with-http_stub_status_module --http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/nginx/scgi_temp --with-pcre=/usr/local/src/pcre-8.41 --with-stream 可以看到stream模块已经编译到nginx内了。
5、nginx stream模块配置简析
stream段的配置要与http段在同级目录。此处引用的为官方nginx说明配置。
stream {
upstream backend {
hash $remote_addr consistent; server backend1.example.com: weight=;
server 127.0.0.1: max_fails= fail_timeout=30s;
server unix:/tmp/backend3;
} upstream dns {
server 192.168.0.1:;
server dns.example.com:;
} server {
listen ;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass backend;
} server {
listen 127.0.0.1: udp reuseport;
proxy_timeout 20s;
proxy_pass dns;
} server {
listen [::]:;
proxy_pass unix:/tmp/stream.socket;
}
}
举一个栗子,利用stream模块代理 zk服务的2181端口。
stream {
upstream zk_server {
server 172.16.3.8:2181 weight=5;
}
server {
listen 2181 tcp;
proxy_responses 1;
proxy_timeout 20s;
proxy_pass zk_server;
}
}
6、编译nignx systemd服务启动文件
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target [Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true [Install]
编译nginx平滑添加stream模块的更多相关文章
- 线上nginx 平滑添加新模块;如(--with-http_realip_module)
nginx 添加模块1.查看当前nginx信息(配置文件路径,启动用户...) ps aux | grep nginx 2.查看当前nginx已启用的模块(记录模块信息,安装路径)./nginx -V ...
- nginx 动态添加ssl模块
一.查看nginx模块 /usr/local/nginx/sbin/nginx -V 二.安装openssl包 yum -y install pcre pcre-devel zlib zlib-d ...
- nginx 重装添加http_ssl_module模块
起因: 如果出现“[emerg] 10464#0: unknown directive "ssl" in /usr/local/nginx-0.6.32/conf/nginx.co ...
- 玩玩 Nginx 2-----给Nginx添加第三方模块(动态更新upstream)
接上一篇,我们在初始化安装的时候添加了nginx_lua模块,然后了解到nginx不可以动态加载模块,所以当你安装第三方模块的时候需要覆盖nginx文件.接下来一起看看如何安装nginx第 ...
- Nginx基于TCP/UDP端口的四层负载均衡(stream模块)配置梳理
通过我们会用Nginx的upstream做基于http/https端口的7层负载均衡,由于Nginx老版本不支持tcp协议,所以基于tcp/udp端口的四层负载均衡一般用LVS或Haproxy来做.至 ...
- yum安装的Nginx添加第三方模块支持tcp
需求:生产有个接口是通过socket通信.nginx1.9开始支持tcp层的转发,通过stream实现的,而socket也是基于tcp通信. 实现方法:Centos7.2下yum直接安装的nginx, ...
- nginx 番外----添加第三方模块
#第三方模块需要先进行下载,然后再编译时指定文件目录 1.查看当前编译模块 root@nginx sbin]# ./nginx -V #查看当前添加模块 nginx version: nginx/ b ...
- yum安装下的nginx,如何添加模块,和添加第三方模块
需求:生产有个接口是通过socket通信.nginx1.9开始支持tcp层的转发,通过stream实现的,而socket也是基于tcp通信. 实现方法:Centos7.2下yum直接安装的nginx, ...
- Deepin15.11源码安装Nginx17.5包括stream模块和njs模块
一:先到官网下载nginx-1.17.5.tar.gz包并且解压到当前目录,解压后目录为:nginx-1.17.5: 二:下载njs源码(它没有像stream模块一样附带在了nginx源码里),因此首 ...
随机推荐
- 纯css实现弹窗左右垂直居中效果
1.HTML <div class="container"> <div class="dialog"> <div class=&q ...
- Jquery属性练习
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- 解决eth0网卡无法自动加载的问题
问题:输入ifup eth0显示无法加载网卡所在的文件 解决办法: vi /etc/rc.d/rc.local 最后一行加入: ifup eth0 然后重启虚拟机即可解决问题. 本文为博主原创文章,未 ...
- Fiddler无法抓取某些APP的HTTPS请求,无解!!!
遇到有些APP的HTTPS请求无法抓取!错误提示: !SecureClientPipeDirect failed: System.Security.Authentication.Authenticat ...
- [Python]-pip-ReadTimeoutError: Read timed out 问题
问题描述 就是在安装Python包的时候,由于时间太长引起的超时问题 问题解决 第一个办法是更改源地址:在 ~/.pip/ 下创建文件 pip.conf(如果还没有的话), 模版如下: [global ...
- [清华集训2015 Day1]主旋律-[状压dp+容斥]
Description Solution f[i]表示状态i所代表的点构成的强连通图方案数. g[i]表示状态i所代表的的点形成奇数个强连通图的方案数-偶数个强连通图的方案数. g是用来容斥的. 先用 ...
- JAVAWEB 项目注册登录模块问题总结
tomcat: 假如tomcat服务器启动出现错误,那就可能是servlet或代码的原因 tomcat服务器出现不能访问页面的情况,可以在eclipse tomcat服务器设置里设置为共享服务器模式 ...
- stl源码剖析 详细学习笔记 算法(1)
//---------------------------15/03/27---------------------------- //算法 { /* 质变算法:会改变操作对象之值 所有的stl算法都 ...
- 【分享】20个非常有用的Java程序片段
福利来啦!!! 刚看到的一篇好东东,分享给大家,这些代码留着哦,以后会用得着的... 原文地址:http://developer.51cto.com/art/201306/398347.htm 1. ...
- centos 7 jenkins 部署
安装jenkins 1.拉取库的配置到本地对应文件 sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redha ...