nginx tcp负载均衡的具体实现

本站所有内容来自互联网收集,仅供学习和交流,请勿用于商业用途。如有侵权、不妥之处,请第一时间联系我们删除!Q群:迪思分享

免费资源网 – https://freexyz.cn/

mysql负载均衡

安装mysql

yum install -y mariadb-server systemctl start mariadb systemctl enable mariadb ss -ntl

nginx tcp负载均衡的具体实现插图

创建数据库并授权

MariaDB [(none)]> create database wordpress; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> grant all privileges on wordpress .* to “wordpress”@”192.168.33.%” identified by “123456”; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec)

配置nginx

vim /apps/nginx/conf/nginx.conf } stream { upstream mysql_server { server 192.168.33.171:3306 max_fails=3 fail_timeout=30s; } server { listen 192.168.33.180:3306; proxy_connect_timeout 30s; proxy_timeout 300s; proxy_pass mysql_server; } }

写入时闭合http

nginx tcp负载均衡的具体实现插图1

nginx tcp负载均衡的具体实现插图2

 访问

nginx tcp负载均衡的具体实现插图3

redis负载均衡

安装redis

wget https://download.redis.io/releases/redis-6.0.6.tar.gz tar -zxvf redis-6.0.6.tar.gz cd redis-6.0.6 make cd src/ redis-server ss -ntl

nginx tcp负载均衡的具体实现插图4

修改文件

vim /root/redis-4.0.14/redis.conf 修改为bind 0.0.0.0

配置nginx

stream { upstream mysql_server { server 192.168.33.171:3306 max_fails=3 fail_timeout=30s; server 192.168.33.149:6379 max_fails=3 fail_timeout=30s; } server { listen 192.168.33.180:6379; proxy_connect_timeout 30s; proxy_timeout 300s; proxy_pass mysql_server;} server { listen 192.168.33.180:3306; proxy_connect_timeout 30s; proxy_timeout 300s; proxy_pass mysql_server; } }

访问

nginx tcp负载均衡的具体实现插图5

到此这篇关于nginx tcp负载均衡的具体实现的文章就介绍到这了,更多相关nginx tcp负载均衡内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!


© 版权声明
THE END
★喜欢这篇文章吗?喜欢的话,麻烦动动手指支持一下!★
点赞9 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容