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;
 }
}

访问

相关推荐
鸡鸭扣1 小时前
Docker:3、在VSCode上安装并运行python程序或JavaScript程序
运维·vscode·python·docker·容器·js
人工干智能4 小时前
科普:“Docker Desktop”和“Docker”以及“WSL”
运维·docker·容器
落笔画忧愁e4 小时前
FastGPT及大模型API(Docker)私有化部署指南
运维·docker·容器
前端郭德纲4 小时前
前端自动化部署的极简方案
运维·前端·自动化
DC_BLOG5 小时前
Linux-GlusterFS进阶配置
linux·运维·服务器
浮华落定7 小时前
Centos开机自启动
linux·运维·centos
End9289 小时前
如何安装虚拟机cenos7系统
大数据·linux·运维
eight *10 小时前
Dockerfile制作镜像示例 X86版本
运维·docker
5:0010 小时前
Linux:进程间通信(一.初识进程间通信、匿名管道与命名管道、共享内存)
linux·运维·服务器
揽星逐月酒微醺10 小时前
Nginx web服务器+uWSGI web服务器+Django生产环境部署
服务器·前端·nginx