mysql高可用

1 mmm架构

mysql高可用集群    (mysql MMM   +  mysql主从同步)

 

1、公共配置

配置固定物理Ip地址   237   42   101   102    77

所有机器之间彼此可以ping

服务器237   42   101   102 运行mysql数据库服务、

配置YUM

 

在所有服务器237   42   101   102    77上安装

rpm  -q  perl  ||  yum  -y  perl

yum  -y  install  perl-*

 

 

2、配置主主结构 (237   42

 

237的配置

mysql> grant  replication slave  on  *.* to  slaveuser@"172.40.7.42" identified by "123";

 

[root@www mysql]# cat /etc/my.cnf

[mysqld]

log-bin=master237

server_id=237

:wq

[root@www mysql]#  service  mysql  restart

 

 

42的配置

mysql> grant  replication slave  on  *.* to  slaveuser@"%" identified by  "123";

 

vim /etc/my.cnf

[mysqld]

server_id=42

log-bin=master42

log_slave_updates

:wq

 

service  mysql   restart

 

mysql  -uroot  -p123

mysql> change  master  to   master_host="172.40.7.237",master_user="slaveuser",master_password="123",master_log_file="master237.000001",master_log_pos=120;

 

mysql> start  slave;

 

237上把自己配置为42的从数据库服务器

change  master  to   master_host="172.40.7.42",master_user="slaveuser",master_password="123",master_log_file="master42.000001",master_log_pos=120;

 

mysql> start  slave;

 

 

3、配置 101  和  102 42 的从数据库服务器

vim /etc/my.cnf

[mysqld]

server_id=101

:wq

service  mysql  restart

 

mysql> change  master  to   master_host="172.40.7.42",master_user="slaveuser",master_password="123",master_log_file="master42.000001",master_log_pos=120;

mysql> start  slave;

 

 

在所有服务器237   42   101   102    77上安装mysql-mmm软件

unzip  mysql-mmm.zip

cd  mysql-mmm

tar  -zxvf  mysql-mmm-2.2.1.tar.gz

cd mysql-mmm-2.2.1

make  install

 

ls /etc/mysql-mmm/*.conf

 

 

在所有数据库服务器上授权

grant  replication client,process,super  on *.*  to   agent@"%"   identified by  "123456";

 

grant  replication  client  on *.*  to      monitor@"%"   identified by "123456";

----------------------------------------------------------------

mysql-mmm简介?

监控、故障转移     (perl 脚本程序)

 

 

软件安装后提供2种进程

mmm-monitor   监控进程

                              运行在监控端 77

                             负责所有的监控工作的监控守护进

程,决定故                             障节点的移除或恢复

 

mmm-agent       代理进程

           运行在被监控端237  42   101   102

                             提供简单远程服务集、提供给

 监控节点

 

vip   172.40.7.100

 

vip   172.40.7.110

            172.40.7.120

 

 

       

文档详解   

 

mmm_mon.conf     mmm-monitor监控进程的主配置文件

                                  只需要在监控服务器上有

 

mmm_agent.conf   mmm-agent代理进程的主配置文件

                                  只需要在数据库服务器上有

[root@www 桌面]# cat /etc/mysql-mmm/mmm_agent.conf

include  mmm_common.conf

this  master237

[root@www 桌面]#

 

 

mmm_common.conf   所有服务器上都要有的文件。

                                       定义服务器角色的配置文件

 

 

4 启动服务

4.1  启动mmm_agent进程(101  102   42    237)

日志文件  /var/log/mysql-mmm/mmm_agentd.log

 

cd  mysql-mmm

sh  a.sh

 

[root@www mysql-mmm]# /etc/init.d/mysql-mmm-agent start

Daemon bin: '/usr/sbin/mmm_agentd'

Daemon pid: '/var/run/mmm_agentd.pid'

Starting MMM Agent daemon... Ok

[root@www mysql-mmm]#

 

4.2  启动mmm_mon进程(77)

/var/log/mysql-mmm/mmm_mond.log 日志文件

cd  mysql-mmm

sh  a.sh

# /etc/init.d/mysql-mmm-monitor start

# mmm_control   help

[root@svr5 mysql-mmm]# mmm_control show

  master237(172.40.7.237) master/AWAITING_RECOVERY. Roles:

  master42(172.40.7.42) master/AWAITING_RECOVERY. Roles:

  slave101(172.40.7.101) slave/AWAITING_RECOVERY. Roles:

  slave102(172.40.7.102) slave/AWAITING_RECOVERY. Roles:

 

[root@svr5 mysql-mmm]#

[root@svr5 mysql-mmm]# mmm_control show

  master237(172.40.7.237) master/ONLINE. Roles: writer(172.40.7.100)

  master42(172.40.7.42) master/AWAITING_RECOVERY. Roles:

  slave101(172.40.7.101) slave/AWAITING_RECOVERY. Roles:

  slave102(172.40.7.102) slave/AWAITING_RECOVERY. Roles:

 

 

 mmm_control set_online slave101

 

安装获取虚拟ip地址的程序

yum -y install gcc   gcc-c++

gunzip  Net-ARP-1.0.8.tgz

 

   79  tar  -xvf Net-ARP-1.0.8.tar

   80  cd Net-ARP-1.0.8

   81  rpm -q gcc

   82  yum -y install gcc  gcc-c++

   83  perl Makefile.PL

   84  make

   85  make install

 

   86  ip addr show  查看虚拟ip地址的命令