IT俱乐部 Nginx nginx tcp负载均衡的具体实现

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负载均衡内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部! 

本文收集自网络,不代表IT俱乐部立场,转载请注明出处。https://www.2it.club/server/nginx/11643.html
上一篇
下一篇
联系我们

联系我们

在线咨询: QQ交谈

邮箱: 1120393934@qq.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部