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