nginx tcp负载均衡的具体实现
作者:诸葛哈哈
Nginx是比较不错的开源Web服务器之一,它也可以用作TCP和UDP负载均衡器,本文主要介绍了nginx tcp负载均衡的具体实现,具有一定的参考价值,感兴趣的可以了解一下
mysql负载均衡
安装mysql
yum install -y mariadb-server systemctl start mariadb systemctl enable mariadb ss -ntl
创建数据库并授权
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
访问
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
修改文件
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负载均衡的具体实现的文章就介绍到这了,更多相关nginx tcp负载均衡内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!