内网nginx安装stream模块,配置nginx转发mysql端口

内网安装stream模块 

1.先进到原来nginx的sbin目录,查看原来安装的配置模块
[root@localhost sbin]# ./nginx -V
nginx version: nginx/1.19.5
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) 
built with OpenSSL 1.1.1g  21 Apr 2020
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
2.原来安装的模块没有stream模块,然后进入原来安装nginx解压包的目录里面
[root@localhost ~]# find / -name nginx
/root/soft/nginx-1.19.5/objs/nginx
/var/spool/mail/nginx
/usr/local/nginx
/usr/local/nginx/sbin/nginx
/home/nginx

我原来的目录是在/root/soft/nginx-1.19.5/下面
[root@localhost ~]# cd /root/soft/nginx-1.19.5
[root@localhost nginx-1.19.5]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src
[root@localhost nginx-1.19.5]# ./configure --prefix=/usr/local/nginx --with-stream --with-stream_ssl_module --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module

...
等待编译完成


[root@localhost nginx-1.19.5]# make    #注意不要 make install ! ! !

...
等待make完成


3.然后进入到/root/soft/nginx-1.19.5/objs目录下面将nginx拷贝到现在nginx的目录/usr/local/nginx/sbin/ 下面,注意先备份原来/usr/local/nginx/sbin/下的nginx
[root@localhost nginx-1.19.5]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.back
[root@localhost nginx-1.19.5]# cd objs/
[root@localhost objs]# ls
autoconf.err  Makefile  nginx  nginx.8  ngx_auto_config.h  ngx_auto_headers.h  ngx_modules.c  ngx_modules.o  src
[root@oss-rwrk-22 objs]# cp -ar nginx /usr/local/nginx/sbin/

4.先停掉原来的nginx然后用新的nginx启动
[root@localhost objs]# cd /usr/local/nginx/sbin/
[root@localhost sbin]# ls
[root@localhost sbin]# nginx  nginx.back
[root@localhost sbin]# ./nginx 



配置stream模块转发mysql端口

vim nginx.conf
#user  nobody;
worker_processes  1;

events {
    worker_connections  1024;
}

#这里配置nginx转发mysql端口
stream {
    #方法一:
    upstream mysql_3306 {
       hash $remote_addr consistent;
       server 10.10.10.10:3306 weight=5 max_fails=3 fail_timeout=30s;
    }
    server {
       listen 8080;  #配置本机的监听端口,访问本机的8080端口跳转到10.10.10.10:3306端口
       proxy_connect_timeout 10s;
       proxy_timeout 300s;   #设置客户端和代理服务之间的超时时间,如果5分钟内没操作将自动断开。
       proxy_pass mysql_3306;
    }

    #方法二:
    server {
       listen 8088;
       proxy_pass 10.10.10.11:3306;
    }
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm index.php;
        }
    }
}

你可能感兴趣的:(nginx,运维,服务器)