nginx安装–with-stream模块
- nginx -V确保nginx安装了–with-stream如果没有,重新用安装nginx
- 安装
yum -y install epel-release
- 安装所有modules
yum -y install nginx-all-modules.noarch
- vi nginx.conf顶部加一行
load_module /usr/lib64/nginx/modules/ngx_stream_module.so;
或者
include /usr/share/nginx/modules/*.conf;
nginx.conf配置文章来源:https://www.toymoban.com/news/detail-833408.html
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
#load_module /usr/lib64/nginx/modules/ngx_stream_module.so;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
stream {
# 代理MYSQL 1
upstream mysql_01{
hash $remote_addr consistent;
server 172.168.0.11:3306 weight=5 max_fails=3 fail_timeout=30s;
}
server {
listen 25674; # 数据库服务器监听端口
proxy_connect_timeout 10s;
proxy_timeout 300s; # 设置客户端和代理服务之间的超时时间,如果5分钟内没操作将自动断开。
proxy_pass mysql_01;
}
# 代理MYSQL 2
upstream mysql_02{
hash $remote_addr consistent;
server 192.168.0.3:3306 weight=5 max_fails=3 fail_timeout=30s;
}
server {
listen 25675; # 数据库服务器监听端口
proxy_connect_timeout 10s;
proxy_timeout 300s; # 设置客户端和代理服务之间的超时时间,如果5分钟内没操作将自动断开。
proxy_pass mysql_02;
}
# 代理Redis
upstream redis {
server 172.168.0.12:6379 max_fails=3 fail_timeout=30s; #redis替换为真实地址
}
server {
listen 8085; # 对外暴露端口号
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass redis;
}
# 代理Oracle
upstream oracle {
server 172.168.0.13:1521 weight=1 max_fails=2 fail_timeout=30s; #原oracle地址
}
server {
listen 3335;# 反向代理后监听的端口,
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass oracle;
}
}
http {}
测试TCP代理,链接mysql:文章来源地址https://www.toymoban.com/news/detail-833408.html
mysql -h127.0.0.1 -P3306 -u username -p'password'
到了这里,关于nginx配置stream模块TCP代理的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!