nginx代理转发mysql

环境描述:

  • 操作系统:Red Hat Enterprise Linux Server release 7.6 (Maipo)
  • 数据库:MySQL 5.7.22
  • 中间件:nginx 1.9.8
  • IP地址:192.168.1.50–生产环境为公网,这里用内网IP代替
  • 实现目标:nginx代理mysql

操作步骤:
1.安装mysql
相信大家都会,过程略

2.编译安装nginx,这一步是关键
2.1.下载并解压nginx安装包,这里使用 nginx 1.9.8

cd /soft
tar zxvf nginx-1.19.8.tar.gz

2.2.编译安装,记得创建nginx用户哦!useradd nginx -s /bin/nologin

cd nginx-1.19.8.tar.gz

./configure --prefix=/usr/local/nginx \
--user=nginx --group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--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_stub_status_module \
--with-http_auth_request_module \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-http_slice_module \
--with-file-aio --with-http_v2_module

3.最后安装

make && make install

4.配置反向代理,添加

#默认配置文件的路径为/usr/local/nginx/conf/nginx.conf


stream {
        upstream mysql {
        server 192.168.1.50:3306 max_fails=3 fail_timeout=30s;
}


server {
        listen       33060;
        proxy_pass mysql;

}
}

5.检查 nginx.conf是否有问题

可使用nginx自带的命令
/usr/local/nginx/sbin/nginx -t

6.启动nginx

/usr/local/nginx/sbin/nginx

7.检查端口,测试

# netstat -an |grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:33060           0.0.0.0:*               LISTEN

看到这,相信你已经成功了,又不对的地方欢迎批评指正!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值