Chinaunix首页 | 论坛 | 博客
  • 博客访问: 573766
  • 博文数量: 130
  • 博客积分: 7473
  • 博客等级: 少将
  • 技术积分: 1466
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-10 22:29
文章分类

全部博文(130)

文章存档

2012年(1)

2011年(22)

2010年(2)

2009年(58)

2008年(47)

分类:

2011-07-19 09:38:07

一、利用amoeba实现高可用下的读写分离

1、  关于amoeba的介绍和安装我这里不做介绍了,请查看:http://blog.chinaunix.net/u3/93755/showart.php?id=2363202,有什么问题我们再一起讨论。

2、  Amoebamysql-mmm架构下的配置

配置的除了amoeba的监听IP外其他的均采用上面mmm分配的浮动IP,因为当出现故障后,浮动IP会自动分配到正常的server上。amoeba.xml的配置如下:

 

 

      

             

                8066

               

               

                192.168.1.163

               

                20

               

               

                30

               

               

                30

               

               

                128

               

               

                true

               

                root

                password

               

               

                60

       

       

       

       

               

                         com.meidusa.amoeba.net.AuthingableConnectionManager

                        

                        

               

       

       

       

               

               

                        

                        

                        

                                 defaultManager

                                

                                

                                 3306

                                

                                

                                 192.168.1.113

                                 test

                                

                                

                                 zhang

                                

                                

                                 zhang123

                                

                        

                        

                        

                        

                                 200

                                 200

                                 10

                                 600000

                                 600000

                                 true

                                 true

                        

               

               

 

               

                        

                        

                        

                                 defaultManager

                                

                                

                                 3306

                                

                                

                                 192.168.1.111

                                 test

                                

                                

                                 zhang

                                

                                

                                 zhang123

                                

                        

                        

                        

                        

                                 200

                                 200

                                 10

                                 600000

                                 600000

                                 true

                                 true

                        

               

 

 

               

                        

                        

                        

                                defaultManager

                                

                                

                                 3306

                                

                                

                                 192.168.1.112

                                 test

                                

                                

                                 zhang

                                

                                

                                 zhang123

                                

                        

                        

                        

                        

                                 200

                                 200

                                 10

                                 600000

                                 600000

                                 true

                                 true

                        

               

 

 

               

                        

                        

                        

                                 defaultManager

                                

                                

                                 3306

                                

                                

                                 192.168.1.114

                                 test

                                

                                

                                 zhang

                                

                                

                                 zhang123

                                

                        

                        

                        

                        

                                 200

                                 200

                                 10

                                 600000

                                 600000

                                 true

                                 true

                        

               

 

 

               

                        

                        

                        

                                 defaultManager

                                

                                

                                 3306

                                

                                

                                 192.168.1.115

                                 test

                                

                                

                                 zhang

                                

                                

                                 zhang123

                                

                        

                        

                        

                        

                                 200

                                 200

                                 10

                                 600000

                                 600000

                                 true

                                 true

                        

               

 

 

 

               

               

                        

                                

                                 1

                                

                                

                                 server1

                        

               

 

               

                        

                                

                                 1

                                

                                

                                 server2,server3,server4,server5

                        

               

               

       

       

       

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

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

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

                1500

                master

                master

                slave

                true

       

 

3、  启动amoeba

       /usr/local/amoeba/bin/amoeba &  

检验启动是否成功(使用的是默认的8066端口):

[root@server3 ~]# ps aux | grep amoeba

root     15390  0.2 21.7 411800 55684 pts/0    Sl   Nov09   0:13 /usr/java/jdk1.6/bin/java -server -Xms256m -Xmx256m -Xss128k -Damoeba.home=/usr/local/amoeba -Dclassworlds.conf=/usr/local/amoeba/bin/amoeba.classworlds -classpath /usr/local/amoeba/lib/classworlds-1.0.jar org.codehaus.classworlds.Launcher

 

4、  测试

为了有权限,请在所有mysql-server上添加上面配置的用户名和密码,比如:

grant all on test.* to zhang@'192.168.1.%' identified by 'zhang123';

flush privileges;

测试的时候比较麻烦,因为如果把主从停掉来看效果的话,mmm会将该同步状态有问题的服务器设置成REPLICATION_FAIL并将该主机上的浮动IP移动到正常服务器,比如:我将server4停掉后,就出出现如下现象:

[root@server3 ~]#  mmm_control show

  db1(192.168.1.161) master/ONLINE. Roles: reader(192.168.1.114), reader(192.168.1.115)

  db2(192.168.1.162) master/ONLINE. Roles: reader(192.168.1.112), writer(192.168.1.113)

  db3(192.168.1.164) slave/REPLICATION_FAIL. Roles:

  db4(192.168.1.165) slave/ONLINE. Roles: reader(192.168.1.111)

暂时没想到很好的测试办法。读写分离测试没有问题。

最近手头没有空闲的机器来做压力测试。等有了机器了再对这个架构做下压力测试!

 

 

二、利用keepalived实现amoeba高可用

Keepalived简介:KeepalivedLinux下面实现VRRP 备份路由的高可靠性运行件。基于Keepalived设计的服务模式能够真正做到主服务器和备份服务器故障时IP瞬间无缝交接。从而提高系统的可用性

1、  keepalived的安装(server6server7上都要安装):

wget
tar zxvf keepalived-1.1.19.tar.gz
cd keepalived-1.1.19
./configure --prefix=/usr/local/keepalived
make
make install
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
mkdir /etc/keepalived
cd /etc/keepalived/

 

2、  keepalived的配置

配置server6keepalived配置文件/etc/keepalived/keepalived.conf,内容如下:

bal_defs {

        notification_email {

               jimo291@gmail.com

        }

        notification_email_from jimo291@gmail.com

        smtp_server 127.0.0.1

        smtp_connect_timeout 30

        router_id test1

}

 

 

vrrp_instance VI_1 {

        state MASTER

        interface eth0

        virtual_router_id 51

        priority 100

        advert_int 1

        smtp_alert

        authentication {

                auth_type PASS

                auth_pass 123

        }

 

        virtual_ipaddress {

                192.168.1.170

        }

}

 

配置server6keepalived配置文件/etc/keepalived/keepalived.conf,内容如下:

bal_defs {

        notification_email {

                jimo291@gmail.com

        }

        notification_email_from jimo291@gmail.com

        smtp_server 127.0.0.1

        smtp_connect_timeout 30

        router_id test2

}

 

vrrp_instance VI_1 {

        state BACKUP

        interface eth0

        virtual_router_id 51

        priority 80

        advert_int 1

        smtp_alert

        authentication {

                auth_type PASS

                auth_pass 123

        }

        virtual_ipaddress {

                192.168.1.170

        }

}

 

3、  keepalived的启动:

server6server7上执行如下命令启动:

/etc/rc.d/init.d/keepalived start

看看server6上是否绑定了虚拟IP192.168.1.170

[root@server6 ~]# ip add | grep 192.168.1.170

inet 192.168.1.170/32 scope global eth0

       可以看到已经成功绑定了192.168.1.170

4、  测试

停掉server6,看看虚拟IP192.168.1.170会不会自动切换到server7上。以及测试mysql -uroot -ppassword -h192.168.1.170登录,看看能否实现读写操作是否正常等等!

 

备注:最后记得将所有的启动命令都写到/etc/rc.local文件中去,实现开机启动!

阅读(1347) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~