标签:keepalived+mariadb10 配置双主 主从 高可用 数据库 mysql
Keepalived+MariaDB10配置双主高可用数据库
OS | RS | 子网掩码 | 路由网关 |
Centos6.6 Keepalived
| Eth0:192.168.26.210 | 255.255.252.0 | 192.168.25.3 |
VIP:192.168.27.210 | 255.255.255.252 | ||
Centos6.6 MariaDB10 Keepalived | Eth0:192.168.26.211 | 255.255.252.0 | 192.168.25.3 |
VIP:192.168.27.210 | 255.255.255.255 | ||
Win7(client) | IP:192.168.26.70 | 255.255.252.0 | 192.168.25.3 |
在两台服务器上分别安装MYSQL:
yum -y install MariaDB (这里略)
安装完后配置双主模型:
编辑配置文件26.210:vim /etc/my.cnf.d/server.cnf
在配置文件中加入以前几个参数设置:
log-bin=mysql-bin
server-id = 210
relay-log =relay-bin
编辑配置文件26.211:vim /etc/my.cnf.d/server.cnf
log-bin =mysql-bin
server-id = 211
relay-log = relay-bin
分别启动两台服务器的MYSQL服务:service mysql start
服务器设置双主:
26.210:
mysql
grant replication slave ,replication client on *.* to ‘jerry‘@‘192.168.%.%‘ identified by ‘jerrypass‘;
change master to master_host=‘192.168.26.211‘,master_user=‘jerrymy‘,master_password=‘jerrypass‘,master_log_file=‘mysql-bin.000006‘,master_log_pos=558;
start slave;
show slave status\G; #查看从状态IO和SQL 运行状态均为YES表示配置成功
26.211:
mysql
grant replication slave ,replication client on *.* to ‘jerrymy‘@‘192.168.%.%‘ identified by ‘jerrypass‘;
change master to master_host=‘192.168.26.210‘,master_user=‘jerry‘,master_password=‘jerrypass‘,master_log_file=‘mysql-bin.000007‘,master_log_pos=540;
start slave;
show slave status\G; #查看从状态IO和SQL 运行状态均为YES表示配置成功
显示状态为成功,我们再创建数据库来测试,看看双主是否运行正常。
双主设置成功。
26.210:安装Keepalived
安装报错未安装gcc
yum -y install gcc
yum -y install openssl-devel
安装组件后编译成功:
编辑配置文件:vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs {
router_id mysql-ha
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 20
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.27.210
}
}
virtual_server 192.168.27.210 3306 {
delay_loop 2
lb_algo rr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.26.210 3306 {
weight 1
notify_down /etc/keepalived/mysql.sh
TCP_CHECK {
connect_port 3306
connect_timeout 3
nb_get_retry 2
delay_before_retry 1
}
}
}
保存退出启动Keepalived服务。
service keepalived start
26.211:安装Keepalived。
编辑配置文件26.211: vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs {
router_id mysql-ha
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 20
priority 99
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.27.210
}
}
virtual_server 192.168.27.210 3306 {
delay_loop 2
lb_algo rr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.26.211 3306 {
weight 1
notify_down /etc/keepalived/mysql.sh
TCP_CHECK {
connect_port 3306
connect_timeout 3
nb_get_retry 2
delay_before_retry 1
}
}
}
保存退出启动26.211上的Keepalived
service keepalived start
测试VIP是否可用:ping 192.168.27.210 -t
回到26.210或211都可以 上,创建一个数据库访问测试用户账号密码。
grant all on *.* to ‘jerrytest‘@‘192.168.%.%‘ identified by ‘jerrypass‘;
下面通过 VIP访问数据库观察访问:
VIP在26.210这台服务器上,因此我们访问的26.210上的数据库。
下面停掉26.210上的MYSQL观察:
首先观察VIP网络出现波动后恢复。
数据库访问成功:
VIP已经转移动26.211服务器上了。
我们再恢复26.210上的MYSQL数据库服务观察。
本文出自 “在路上” 博客,请务必保留此出处http://jdonghong.blog.51cto.com/3473478/1883361
Keepalived+MariaDB10配置双主高可用数据库
标签:keepalived+mariadb10 配置双主 主从 高可用 数据库 mysql
原文地址:http://jdonghong.blog.51cto.com/3473478/1883361