需求:生产有个接口是通过socket通信。nginx1.9开始支持tcp层的转发,通过stream实现的,而socket也是基于tcp通信。

实现方法:Centos7.2下yum直接安装的nginx,添加新模块支持tcp转发;重新编译Nginx并添加 --with-stream 参数。

实现过程:

1.  查看nginx版本模块

[root@pre ~]# nginx -V

2.  下载一个同版本可编译的Nginx

cd /opt
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar xf nginx-1.12.2.tar.gz && cd nginx-1.12.

3.  备份原Nginx文件

mv /usr/sbin/nginx /usr/sbin/nginx.bak
cp -r /etc/nginx{,.bak}

4.  重新编译Nginx

检查模块是否支持,比如这次添加 limit 限流模块 和 stream 模块:
./configure –help | grep limit
这里写图片描述
ps:-without-http_limit_conn_module disable 表示已有该模块,编译时,不需要添加

./configure –help | grep stream
这里写图片描述
ps:–with-stream enable 表示不支持,编译时要自己添加该模块

根据第1步查到已有的模块,加上本次需新增的模块: --with-stream

cd /opt/nginx-1.12.2

./configure --prefix=/usr/share/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-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --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

以上编译时,如出现缺少依赖,一般需要安装以下模块,安装完再次编译:

yum -y install libxml2 libxml2-dev libxslt-devel
yum -y install gd-devel
yum -y install perl-devel perl-ExtUtils-Embed
yum -y install GeoIP GeoIP-devel GeoIP-data
yum -y install pcre-devel
yum -y install openssl openssl-devel

5.  编译通过,继续验证 
继续输入:make  
make完成后不要继续输入“make install”,以免现在的nginx出现问题 
以上完成后,会在objs目录下生成一个nginx文件,先验证:

/opt/nginx-1.12.2/objs/nginx -t
/opt/nginx-1.12.2/objs/nginx -V

6.  替换Nginx文件并重启

cp /opt/nginx-1.12.2/objs/nginx /usr/sbin/
nginx -s reload

7.  检查

[root@pre ~]# nginx -V

添加模块成功!!!

yum安装下的nginx,如何添加模块,和添加第三方模块的更多相关文章

  1. Python学习手册之__main__ 模块,常用第三方模块和打包发布

    在上一篇文章中,我们介绍了 Python 的 元组拆包.三元运算符和对 Python 的 else 语句进行了深入讲解,现在我们介绍 Python 的 __main__ 模块.常用第三方模块和打包发布 ...

  2. yum安装 lnmp (linux+nginx+php7.1+mysql5.7)

    1.第一步先更新yum update 2.yum安装nginx安装nginx最新源:yum localinstall http://nginx.org/packages/centos/7/noarch ...

  3. centos6服务器YUM安装LNMP(LINUX+NGINX+MYSQL+PHP)

    之前都用的lamp,这次配置一个lnmp来看看,试试Nginx是不是好用 关闭SELINUXvi /etc/selinux/config#SELINUX=enforcing #注释掉#SELINUXT ...

  4. centos yum安装redis,nginx

    先安装源 yum install epel-release 之后 分别安装redis,nginx

  5. python_way ,day5 模块,模块3 ,双层装饰器,字符串格式化,生成器,递归,模块倒入,第三方模块倒入,序列化反序列化,日志处理

    python_way.day5 1.模块3 time,datetime, json,pickle 2.双层装饰器 3.字符串格式化 4.生成器 5.递归 6.模块倒入 7.第三方模块倒入 8.序列化反 ...

  6. ubuntu 下编译安装 mysql php nginx 及常见错误 (持续添加)

    mysql mysql 可以使用mysql 官方提供的apt源进行安装 参见这里 php 安装前先安装一些常见库 sudo apt-get install libpng16-16 libpng16-d ...

  7. centos7 yum 安装最新的nginx 1.16

    参考:https://www.cnblogs.com/opsprobe/p/10773582.html nginx官方文档说明:http://nginx.org/en/linux_packages.h ...

  8. 解决centos yum安装"No package nginx available."问题

    问题原因: nginx位于第三方的yum源里面,而不在centos官方yum源里面 解决方法: 安装epel(Extra Packages for Enterprise Linux) a.去epel网 ...

  9. yum 安装 PHP,apache,nginx,mysql

    如果是Centos OS 64 位,首先更新 rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarc ...

随机推荐

  1. 基于JMH的Benchmark解决方案

    原始Benchmark做法 在设计新框架的时候,往往需要评估待接入的组件的性能,这个时候我们可能会利用UnitTest来进行,写一个方法,然后在循环里面跑,利用System.CurrentTimeMi ...

  2. oracle 导出某用户下的表

    exp test/test@orcl owner=test file=E:/all.dmp

  3. Eureka的使用

    一.项目配置文件:application.yml #------ eureka配置,默认不开启,如需使用rest负载模式需开启 start ------------- eureka: instance ...

  4. js splice函数 数组增加,替换,删除

    splice函数参数介绍: 第一个参数: 对于数数组的操作起始位置. 第二个参数: 从第一个参数开始,删除数组中的个数. 从第三个参数之后所有参数(如果有):执行完第二步之后,都插入到第一个参数的起始 ...

  5. Julia安装以及使用扩展包package(ERROR: UndefVarError: Pkg not defined)

    刚刚安装好Julia1.0,想进行第一步尝试: Pkg.add("PyPlot") 却出现错误:ERROR: UndefVarError: Pkg not defined 问题描述 ...

  6. 3 第一个Django应用 第2部分(管理站点)

    Django会根据你写的模型文件完全自动地生成管理界面. 管理界面不是让访问网站的人使用的,它服务于网站管理者. 它用于网站的管理员. 3.1创建一个管理员用户 3.2进入管理站点 3.3管理站点的功 ...

  7. eclipse工具类及插件(设置注释模板)

    (摘抄原地址)https://blog.csdn.net/xb12369/article/details/79850476(设置注释模板) 首先打开Eclipse配置选项:Window->Pre ...

  8. alias-unalias

    一.用一条命令完成创建目录/data/test,即在/目录下创建/data目录,及其子目录/data/test 解答:mkdir -p /data/test 实践过程: 二.已知/tmp目录下已经存在 ...

  9. vs2015和Oracle在一起时的Shit问题

    VS2015在连接Oracle时,必须要安装到一个不含有空格的目录中去,否则连接不上Oracle,至于为什么,不知道,鬼知道,日的. 如果你不幸以前安装过VS2015,安装到它的默认的什么“progr ...

  10. JAVA将汉字转换为全拼以及返回中文的首字母,将字符串转移为ASCII码

    import net.sourceforge.pinyin4j.PinyinHelper;import net.sourceforge.pinyin4j.format.HanyuPinyinCaseT ...