欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

MySQL互为主从复制实现HA功能

程序员文章站 2024-01-23 15:38:04
...

每个mysql服务器节点都需要运行mmmd_agent,同时在另外一台机器【可以是独立的一台服务器也可以是和AppServer共同享一个服务器】

每个mysql服务器节点都需要运行mmmd_agent,,同时在另外一台机器【可以是独立的一台服务器也可以是和AppServer共同享一个服务器】上运行mmmd_mon
mmm利用了虚拟IP技术,1个网卡可以使用多个IP
所以使用mmm时,需要2*n+1个IP,n为mysql节点数,包括slave和master
当数据库节点fail时,mmmd_mon检测不到mmmd_agent的心跳或者对应的mysql服务器的状态时
mmmd_mon将作出决定并下令给某个正常的数据库节点的mmmd_agent,使得该mmmd_agent“篡位”
【即 使用刚才fail的那个结点的虚拟IP,使得虚拟IP从fail结点指向此时的正常机器】

MySQL互为主从复制实现HA功能

MMMM需要5个IP,两个节点使用固定IP,两个程式读IP(只读),1个 程式写IP(用来更新)
后面这三个虚拟IP是根据节点的可用性在节点之间实现跳转的

一。IP分配
IP分配如下:
A :mysql master 246
固定IP:211.100.97.246
程式读IP:211.100.97.244 (虚拟)

B:mysql master 250
固定IP:211.100.97.250
程式读IP:211.100.97.243 (虚拟)

monitor 245
程式写IP:211.100.97.248 (虚拟)


给246添加虚拟IP 211.100.97.244
ifconfig eth1:1 211.100.97.244 netmask 255.255.255.224 up
[root@XKWB5510 software]# ifconfig -a|grep "inet addr"|head -3|tail -2|awk -F "[ :]+" '{print $4"/"$NF}'
211.100.97.246/255.255.255.224
211.100.97.244/255.255.255.224

给250添加虚拟IP 211.100.97.243
ifconfig eth0:1 211.100.97.243 netmask 255.255.255.224 up
[root@XKWB5705 software]# ifconfig -a|grep "inet addr"|head -2|awk -F "[ :]+" '{print $4"/"$NF}'
211.100.97.250/255.255.255.224
211.100.97.243/255.255.255.224

给245添加虚拟IP:211.100.97.248
ifconfig eth1:1 211.100.97.248 netmask 255.255.255.224 up
[root@CentOS mysql-5.1.56]# ifconfig -a|grep "inet addr"|head -3|tail -2|awk -F "[ :]+" '{print $4"/"$NF}'
211.100.97.245/255.255.255.224
211.100.97.248/255.255.255.224

二 授权
在AB机器添加代理账号 useradd rep_agent
在monitor机器上添加监控账号 useradd rep_monitor

A上授权
mysql> grant all privileges on *.* to 'rep_monitor'@'%' identified by '123456';
mysql> grant all privileges on *.* to 'rep_agent'@'%' identified by '123456';

查看授权情况
mysql> select host,user from mysql.user where user like 'rep%';
+----------------+-------------+
| host | user |
+----------------+-------------+
| % | rep_agent |
| % | rep_monitor |
| 211.100.97.250 | replication |
| localhost | replication |
+----------------+-------------+
4 rows in set (0.01 sec)


B上授权
mysql> grant all privileges on *.* to 'rep_monitor'@'%' identified by '123456';
mysql> grant all privileges on *.* to 'rep_agent'@'%' identified by '123456';

mysql> select host,user from mysql.user where user like 'rep%';
+----------------+-------------+
| host | user |
+----------------+-------------+
| % | rep_agent |
| % | rep_monitor |
| 211.100.97.246 | replication |
| localhost | replication |
+----------------+-------------+
4 rows in set (0.00 sec)


三 mmm安装
CentOS软件仓库默认是不含这些软件的,必须要有epel这个包的支持。故我们必须先安装epel:
wget
rpm -Uvh epel-release-5-4.noarch.rpm

源码包安装mysql-mmm
wget
tar zxf mysql-master-master-1.2.3.tar.gz
cd mysql-master-master-1.2.3
./install.pl

MySQL互为主从复制实现HA功能