十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
Keepalived+MariaDB10配置双主高可用数据库
10多年的沂南网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。营销型网站的优势是能够根据用户设备显示端的尺寸不同,自动调整沂南建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联公司从事“沂南网站设计”,“沂南网站推广”以来,每个客户项目都认真落实执行。
OS | RS | 子网掩码 | 路由网关 |
Centos6.6 MariaDB10 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数据库服务观察。