①创建虚拟机,安装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
}
}

本文介绍了如何搭建基于keepalived的MySQL集群,详细阐述了从创建虚拟机、安装mysql和相关软件,到配置keepalived.cnf文件、创建监控脚本,以及实现mysql数据库的主主同步步骤。涉及内容包括三台节点的权限设置、日志检查和数据同步授权等关键环节。
最低0.47元/天 解锁文章
879

被折叠的 条评论
为什么被折叠?



