lvs配置-MySQL负载均衡

本文详细介绍了如何通过lvs在Linux系统中配置DR模式,进行MySQL数据库的负载均衡。首先,讲述了如何设置DR模式的lvs配置,接着是IP地址的配置,然后详细说明了数据库的配置步骤。最后,在客户端进行了验证,确保负载均衡的正确实施。

lvs配置-MySQL负载均衡

实验环境主机名主机IP地址
centos7client客户端192.168.88.131
centos7lvslvs服务器DIP:192.168.88.128
VIP:192.168.88.250/32
centos7rs1RS1VIP:192.168.88.250/32
RIP:192.168.88.129
centos7rs2RS2VIP:192.168.88.250/32
RIP:192.168.88.130

首先配置好DR模式

配置IP地址

//配置client的IP地址 
[root@client ~]# hostname -I
192.168.88.131

//配置lvs服务器
[root@lvs ~]# hostname -I
192.168.88.128

//配置lvs的VIP地址
[root@lvs ~]# ip addr add 192.168.88.250/32 dev lo

//配置rs的RIP
[root@rs1 ~]# hostname -I
192.168.88.129 

[root@rs2 ~]# hostname -I
192.168.88.130

//修改RS网卡内核参数
[root@rs1 ~]# vim /etc/sysctl.conf
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv4.conf.all.arp_ignore = 1    //添加以下两行
net.ipv4.conf.all.arp_announce = 2

[root@rs1 ~]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2

//配置RS的vip
[root@rs1 ~]# ip addr add 192.168.88.250/32 dev lo

//rs2同上

//配置路由信息:lvs和rs都要配
[root@lvs ~]# route add -host 192.168.88.250 dev lo

[root@rs1 ~]# route add -host 192.168.88.250 dev lo

[root@rs2 ~]# route add -host 192.168.88.250 dev lo

//lvs添加规则
[root@lvs ~]# yum -y install ipvsadm
[root@lvs ~]# ipvsadm -A -t 192.168.88.250:3306 -s rr
[root@lvs ~]# ipvsadm -a -t 192.168.88.250:3306 -r 192.168.88.129:3306 -g
[root@lvs ~]# ipvsadm -a -t 192.168.88.250:3306 -r 192.168.88.130:3306 -g
[root@lvs ~]# ipvsadm -S > /etc/sysconfig/ipvsadm

配置数据库

//安装数据库
[root@rs1 ~]# yum -y install mariadb*

//设置开机自动启动
[root@rs1 ~]# systemctl enable --now mariadb.service

//在RS1上创建数据库
[root@rs1 ~]# mysql -e 'create database RS1;'

//数据库授权,rs1和rs2都要做
[root@rs1 ~]# mysql 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> grant all on *.* to root@'192.168.88.%' identified by '12321';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit
Bye

在client上验证

[root@client ~]# yum -y install mariadb
[root@client ~]# for i in $(seq 5);do mysql -uroot -p12321 -h192.168.88.250 -e 'show databases;';done
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
+--------------------+
| Database           |
+--------------------+
| information_schema |
| RS1                |
| mysql              |
| performance_schema |
| test               |
+--------------------+
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
+--------------------+
| Database           |
+--------------------+
| information_schema |
| RS1                |
| mysql              |
| performance_schema |
| test               |
+--------------------+
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值