NginxStream-配置转发MySQL
# Nginx 配置转发MySQL
# 安装stream模块
(1)查看已安装Nginx编译参数
[root@test11 local]# nginx -V
nginx version: nginx/1.15.9
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module
1
2
3
4
5
6
2
3
4
5
6
(2)下载对应版本Nginx源码并重新编译
下载地址:http://nginx.org/en/download.html (opens new window)
wget http://nginx.org/download/nginx-1.15.9.tar.gz
1
tar -zxvf nginx-1.15.9.tar.gz
cd nginx-1.15.9
1
2
2
编译
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-stream --with-stream_realip_module --without-http_rewrite_module
1
(3)执行make
注意:只执行make,不执行make install ,执行make install 会把原有nginx目录覆盖
make
1
(4)关闭Nginx服务
nginx -s stop
1
(5)替换原有的nginx启动文件
# 备份原有的启动文件
cp /usr/bin/nginx /usr/bin/nginx-no-stream
# 将我们编译生成的nginx文件复制过去,并覆盖
cp /usr/local/src/nginx-1.15.9/objs/nginx /usr/bin/nginx
cp:是否覆盖"/usr/bin/nginx"? y
# 确认是否覆盖成功
[root@test11 nginx-1.15.9]# md5sum /usr/local/src/nginx-1.15.9/objs/nginx /usr/bin/nginx
90ac5d23625cfc5557084fe8d94d6a7f /usr/local/src/nginx-1.15.9/objs/nginx
90ac5d23625cfc5557084fe8d94d6a7f /usr/bin/nginx
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
(6)配置成功
# 配置转发MySQL
(1)修改nginx配置文件
stream {
upstream mysql {
server 10.8.10.13:3306;
}
server {
listen 13333;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass mysql;
}
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
(2)重启Nginx
nginx -s relaod
1
(3)配置成功
直接通过 ip:13333 访问数据库即可
上次更新: 2023/03/10, 16:49:38