主机类型 | IP | 需要安装包 |
---|
客户端 client | 192.168.152.133 | MySQL |
调度器 DR | 192.168.152.132 | ipvsadm |
服务器 RS1 | 192.168.152.134 | MySQL |
服务器 RS2 | 192.168.152.135 | MySQL |
//配置DIP和VIP
[root@DR ~]
TYPE=Ethernet
BOOTPROTO=static
NAME=ens160
DEVICE=ens160
ONBOOT=yes
IPADDR0=192.168.152.132 //DIP
PREFIX0=24
IPADDR1=192.168.152.111 //VIP
PREFIX1=24
GATEWAY0=192.168.152.2
DNS1=114.114.114.114
//重启网卡
[root@DR ~]
//配置路由信息
[root@DR ~]
//修改内核参数
[root@RS1 ~]
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@RS1 ~]
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
//配置RS1上的RIP和VIP
[root@RS1 ~]
TYPE=Ethernet
BOOTPROTO=static
NAME=ens160
DEVICE=ens160
ONBOOT=yes
IPADDR0=192.168.152.134 //RIP
PREFIX0=24
IPADDR1=192.168.152.111 //VIP
PREFIX1=24
GATEWAY0=192.168.152.2
DNS1=114.114.114.114
//重启网卡
[root@RS1 ~]
//配置路由信息
[root@RS1 ~]
//修改内核参数
[root@RS2 ~]
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@RS2 ~]
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
//配置RS2上的RIP和VIP
[root@RS2 ~]
TYPE=Ethernet
BOOTPROTO=static
NAME=ens160
DEVICE=ens160
ONBOOT=yes
IPADDR0=192.168.152.135 //RIP
PREFIX0=24
IPADDR1=192.168.152.111 //VIP
PREFIX1=24
GATEWAY0=192.168.152.2
DNS1=114.114.114.114
//重启网卡
[root@RS2 ~]
//配置路由信息
[root@RS2 ~]
//在DR上添加并保存规则
[root@DR ~]
[root@DR ~]
[root@DR ~]
[root@DR ~]
[root@DR ~]
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.152.111:3306 rr
-> 192.168.152.134:3306 Route 1 0 0
-> 192.168.152.135:3306 Route 1 0 0
//下载MySQL,启动服务
[root@RS1 ~]
[root@RS1 ~]
//创建数据库并授权
[root@RS1 ~]
MariaDB [(none)]> create database RS1;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> grant all on *.* to 'root'@'192.168.152.%' identified by '123456';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]>
//下载MySQL,启动服务
[root@RS2 ~]
[root@RS2 ~]
//创建数据库并授权
[root@RS2 ~]
MariaDB [(none)]> create database RS2;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> grant all on *.* to 'root'@'192.168.152.%' identified by '123456';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]>
[root@client ~]
PING 192.168.152.132 (192.168.152.132) 56(84) bytes of data.
64 bytes from 192.168.152.132: icmp_seq=1 ttl=64 time=1.79 ms
[root@client ~]
PING 192.168.152.222 (192.168.152.111) 56(84) bytes of data.
64 bytes from 192.168.152.222: icmp_seq=1 ttl=64 time=2.21 ms
[root@client ~]
? (192.168.152.222) at 00:0c:29:99:ef:dd [ether] on ens33
? (192.168.152.1) at 00:50:56:c0:00:08 [ether] on ens33
_gateway (192.168.152.2) at 00:50:56:e5:7c:35 [ether] on ens33
? (192.168.152.132) at 00:0c:29:99:ef:dd [ether] on ens33
[root@client ~]
+--------------------+
| Database |
+--------------------+
| RS2 |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
[root@client ~]
+--------------------+
| Database |
+--------------------+
| RS1 |
| information_schema |
| mysql |
| performance_schema |
+--------------------+