①创建虚拟机,安装mysql、jdk等。
参考:电商六十八、搭建mysql集群。三台mysql机器节点。
②安装keepalived。
参考:电商六十二、Nginx负载均衡高可用、keepalived+nginx实现Nginx集群、主分发器和两台备分发器(可以多台备分发器)
③在mysql上配置keepalived.cnf文件。
利用软件连接192.168.10.168
192.168.10.167上的keepalived.cnf内容为:
global_defs {
router_id MySQL-HA
}
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval 2
}
vrrp_sync_group VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
# nopreempt
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
check_run
}
notify_master /home/mysql/master.sh
notify_stop /home/mysql/stop.sh
unicast_src_ip 192.168.10.167
unicast_peer {
192.168.10.168
192.168.10.169
}
virtual_ipaddress {
192.168.100.101
}
}
global_defs {
router_id MySQL-HA
}
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval 2
}
vrrp_sync_group VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
# nopreempt
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
check_run
}
notify_master /home/mysql/master.sh
notify_stop /home/mysql/stop.sh
unicast_src_ip 192.168.10.167
unicast_peer {
192.168.10.168
192.168.10.169
}
virtual_ipaddress {
192.168.100.101
}
}
192.168.10.168上的keepalived.cnf的内容为:
global_defs {
router_id MySQL-HA
}
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval 2
}
vrrp_sync_group VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
# nopreempt
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
check_run
}
notify_master /home/mysql/master.sh
notify_stop /home/mysql/stop.sh
unicast_src_ip 192.168.10.168
unicast_peer {
192.168.10.167
192.168.10.169
}
virtual_ipaddress {
192.168.100.101
}
}
global_defs {
router_id MySQL-HA
}
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval 2
}
vrrp_sync_group VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
# nopreempt
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
check_run
}
notify_master /home/mysql/master.sh
notify_stop /home/mysql/stop.sh
unicast_src_ip 192.168.10.168
unicast_peer {
192.168.10.167
192.168.10.169
}
virtual_ipaddress {
192.168.100.101
}
}
192.168.10.169上的keepalived.cnf的内容为:
global_defs {
router_id MySQL-HA
}
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval 2
}
vrrp_sync_group VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
# nopreempt
priority 98
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
check_run
}
notify_master /home/mysql/master.sh
notify_stop /home/mysql/stop.sh
unicast_src_ip 192.168.10.169
unicast_peer {
192.168.10.167
192.168.10.168
}
virtual_ipaddress {
192.168.100.101
}
}
global_defs {
router_id MySQL-HA
}
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval 2
}
vrrp_sync_group VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
# nopreempt
priority 98
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
check_run
}
notify_master /home/mysql/master.sh
notify_stop /home/mysql/stop.sh
unicast_src_ip 192.168.10.169
unicast_peer {
192.168.10.167
192.168.10.168
}
virtual_ipaddress {
192.168.100.101
}
}