win7下利用amoeba框架来实现mysql的容错

                               mysql主主复制+amoeba框架的搭建


一、环境说明

          三台win7虚拟机 mysql-installer-community-5.7.16.0


          jdk1.8 amoeba-mysql-binary-2.2.0


          ip:10.1.23.198 (安装mysqljdk)


         ip:10.1.23.154 (安装mysqljdk)


         ip:10.1.23.155 (安装mysql客户端和amoebajdk)


二、主主复制(要关闭防火墙,3台机器都可以相互ping通)


         mysql_A:3306host10.1.23.198mysql_B:3307host:10.1.23.154


  1)、分别修改mysql的配置文件开启binlog


                 ip:10.1.23.198修改mysql配置文件my.ini(C:\ProgramData\MySQL\MySQLServer5.7)

                                                                                 (ProgramDataC盘的隐藏文件夹)

                  添加配置:server-id= 1


                                               binlog_checksum=none #如果两个mysql的版本不一样则加入此行

                                              log-bin=C:\whw\Mysql-binlog\mysql-bin


                                              replicate-do-db= world //指定数据库(可写可不写)


                                              auto-increment-increment=2 # 应设为整个结构中服务器的总数


                                              auto-increment-offset= 1 # 设定数据库中自动增长的起点,避免两台服务器数据同步时出现主键冲突


               ip:10.1.23.154 (在my.ini中修改其端口号为3307


                                                 server-id= 2


                                                 log-bin=C:\whw\Mysql-binlog\mysql-bin


                                                 replicate-do-db= world //指定数据库(可写可不写)


                                                 auto-increment-increment=2


                                                auto-increment-offset= 2


2)、mysql_B指定mysql_A为主库


                      1)在10.1.23.198(主库)中创建一个10.1.23.154(从库)中可以登录的


                               MySQL用户,并赋予权限。


                              GRANTREPLICATION SLAVE,RELOAD,SUPER ON *.*TOwhx@'10.1.%'IDENTIFIEDBY '123456';


                              FLUSHPRIVILEGES; 刷新权限


                            (用户名whx密码123456赋予权限:可供10.1.%的客户端实现远程登录)


                     2)在主库中查询当前主库的状态


                              RESETMASTER show MASTER STATUS


                             显示如下:file:mysql-bin.000001


                                              position:154


                    3mysql_B链接主库mysql_A


                              stopSLAVE (10.1.23.154(从库)中)


                               #这里是要连接主库(mysql_A)的端口号,默认是3306

                               CHANGEMASTER TO master_host = '10.1.23.198',

                               master_user= 'whx',

                               master_password= '123456',

                               master_log_file= 'mysql-bin.000001',

                               master_log_pos= 154;


                4)查看当前是否连接成功


                             STARTSLAVE (开启slaveshowSLAVE STATUS \G;

   

                           如果上图中的两个yes存在则成功(必须2个都为yes)


                           slave_lo_running:yes


                          slave_sql_running:yes


3)mysql_A指定mysql_B为主库


                1)在10.1.23.154(主库)中创建一个10.1.23.198(从库)中可以登录的MySQL用户,并赋予权限。


                        GRANTREPLICATION SLAVE,RELOAD,SUPER ON *.*TO whx@'10.1.%'IDENTIFIED BY'123456';


                       FLUSHPRIVILEGES; 刷新权限


                    (用户名whx密码123456赋予权限:可供10.1.%的客户端实现远程登录)


                2)在主库中查询当前主库的状态


                     RESETMASTER show MASTER STATUS


                     显示如下:file:mysql-bin.000001


                     position:154


              3mysql_A链接主库mysql_B


                    stopSLAVE (10.1.23.198(从库)中)


                    这里是要连接主库(mysql_B)的端口号,默认是3306,如果你的主库端口不是3306则要加上这一行

                   CHANGEMASTER TO master_host = '10.1.23.198',

                    master_user= 'whx',

                    master_port=3307, // mysql_B的端口号

                    master_password= '123456',

                    master_log_file= 'mysql-bin.000001',

                    master_log_pos= 154;


            4)查看当前是否连接成功


                             STARTSLAVE (开启slaveshowSLAVE STATUS \G;


                            如果上图中的两个yes存在则成功(必须2个都为yes)


                            slave_lo_running:yes


                            slave_sql_running:yes


                         只要mysql_Amysql_B都出现上面2yes,说明主主搭配成功。


三、amoeba框架的搭建


1)、amoeba的下载及解压

win7下利用amoeba框架来实现mysql的容错_第1张图片

打开cmd,进入amoebabin目录,运行输入命令amoebastart

win7下利用amoeba框架来实现mysql的容错_第2张图片

出现这代表安装成功


2)、amoeba的配置


       conf文件夹下的amoeba.xml




2)、amoeba的配置


conf文件夹下的amoeba.xml




8066

127.0.0.1

true

${clientConnectioneManager}

20

30

30

500

60

com.meidusa.amoeba.net.ConnectionManager

com.meidusa.amoeba.net.AuthingableConnectionManager

${amoeba.home}/conf/dbServers.xml

${amoeba.home}/conf/rule.xml

${amoeba.home}/conf/ruleFunctionMap.xml

${amoeba.home}/conf/functionMap.xml

1500

master1

master1

master2

true


conf文件夹下的dbServers.xml

1"abstractive="true">

${defaultManager}

64

128

//配置所要连接的DBserver的用户名和密码,及所连接的数据库和其相应的端口号

3307

world

whx

123456



500

500

10

600000

600000

true

true

true



1">

10.1.23.154

2"abstractive="true">

${defaultManager}

64

128

3306

world

whx

123456



500

500

10

600000

600000

true

true

true



2">

10.1.23.198


"master1"virtual="true">

1

server1,server2


"master2"virtual="true">

1

server1,server2


四、amoeba启动与其测试

1)、测试其是否可以实现远程登录

         mysql-uwhx -p123456 -h 10.1.23.154 -P3307

         mysql-uwhx -p123456 -h 10.1.23.198

        如可以

2)、输入mysql-uroot -h 10.1.23.155 -P8066 -p123456 登录amoeba,如可正常登录

  win7下利用amoeba框架来实现mysql的容错_第3张图片

3)、可对数据库进行操作


     10.1.23.198上的mysql创建数据库


     createdatabase data2;


   在存在amoebamysql客户端:showdatabases; 如下图

                   win7下利用amoeba框架来实现mysql的容错_第4张图片

关闭10.1.23.154上的msyql的服务器


在存在amoebamysql客户端:showdatabases; 如下图,则搭建成功。

                    win7下利用amoeba框架来实现mysql的容错_第5张图片





你可能感兴趣的:(win7下利用amoeba框架来实现mysql的容错)