lvs-dr实现mysql负载均衡集群
1.配置lvs
DR配置:
[root@DR ~]# yum provides */bin/ipvsadm
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
No matches found
[root@DR ~]# yum provides *bin/ipvsadm
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
yei/filelists_db | 3.1 MB 00:00
ipvsadm-1.27-7.el7.x86_64 : Utility to administer the
: Linux Virtual Server
Repo : yei
Matched from:
Filename : /usr/sbin/ipvsadm
[root@DR ~]# yum -y install ipvsadm-1.27-7.el7.x86_64
[root@DR ~]# route add -host [root@DR ~]# 192.168.116.250/32 dev lo
[root@DR ~]# yum -y install net-tools
[root@DR ~]# ip addr add 192.168.116.250/32 dev lo
[root@DR ~]# yum provides *bin/rount
[root@DR ~]# ipvsadm -A -t 192.168.116.250:3306 -s wrr
[root@yeqixian ~]# ipvsadm -a -t 192.168.116.250:3306 -r 192.168.116.182:3306 -g
[root@yeqixian ~]# ipvsadm -a -t 192.168.116.250:3306 -r 192.168.116.181:3306 -g
[root@DR ~]# ipvsadm -Sn > /etc/sysconfig/ipvsadm
[root@DR ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.116.250:80 wrr
-> 192.168.116.181:80 Route 1 0 0
-> 192.168.116.182:80 Route 1 0 0
RS配置:
[root@RS1 ~]# vim /etc/sysctl.conf
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
[root@RS1 ~]# ip addr add 192.168.116.250/32 dev lo
[root@RS1 ~]# yum -y install net-tools
[root@RS1 ~]# route add -host 192.168.116.250/32 dev lo
[root@RS2 ~]# vim /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@RS2 ~]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@RS2 ~]# ip addr add 192.168.116.250/32 dev lo
[root@RS2 ~]# yum -y install net-tools
[root@RS2 ~]# route add -host 192.168.116.250/32 dev lo
- 配置数据库
[root@yei ~]# yum -y install mariadb
[root@yei ~]# systemctl start mariadb
[root@yei ~]# mysql
MariaDB [(none)]> grant all on . to ‘root’@‘192.168.%.%’ identified by ‘123456’;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> create database yei;
Query OK, 1 row affected (0.00 sec)
[root@rs2 ~]# yum -y install mariadb
[root@rs2 ~]# systemctl start mariadb
[root@rs2 ~]# mysql
MariaDB [(none)]> grant all on . to ‘root’@‘192.168.%.%’ identified by ‘123456’;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> create database rs2;
Query OK, 1 row affected (0.00 sec)