注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

胡益兵的博客

新的岗位,新的方向,新的使命,stem教育进行中。

 
 
 

日志

 
 

【实验通过】利用Amoeba实验mysql读写分离的访问调度(二)  

2015-10-13 22:59:06|  分类: linux应用 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

四、安装amoeba

 root@DS bin]#yum install java-1.8.0

[root@DS bin]#mkdir /usr/local/amoeba

[root@DS bin]#cd /usr/local/amoeba

[root@DS bin]#wget http://sourceforge.net/projects/amoeba/files/Amoeba%20for%20mysql/2.2.x/amoeba-mysql-binary-2.2.0.tar.gz

[root@DS bin]#tar xzvf amoeba-mysql-binary-2.2.0.tar.gz

[root@DS bin]#cd bin

[root@DS bin]# ./amoeba

Error: JAVA_HOME environment variable is not set.

解决方案:环境变量没有设置

cd /

find -name java

./etc/java

./etc/alternatives/java

./etc/pki/java

./etc/pki/ca-trust/extracted/java

./var/lib/alternatives/java

./usr/lib/java

./usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51-1.b16.el6_7.x86_64/jre/bin/java

./usr/bin/java

./usr/share/java

 

找到java安装路径/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51-1.b16.el6_7.x86_64/jre/

 

vi /etc/profile

JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51-1.b16.el6_7.x86_64/jre/

PATH=$PATH:JAVA_HOME/bin

export JAVA_HOME PATH

重新加载:

[root@server7 java]# source /etc/profile

 

./usr/local/amoeba/bin/amoeba 

The stack size specified is too small, Specify at least 228k

Error: Could not create the Java Virtual Machine.

Error: A fatal exception has occurred. Program will exit.

解决办法:

修改amoeba启动参数,增加JAVA虚拟机的内存,

vi /usr/local/amoeba/bin/amoeba

查找DEFAULT_OPTS,修改为以下内容:

DEFAULT_OPTS="-server -Xms1024m -Xmx1024m -Xss256k"

 

 ./amoeba

amoeba start|stop

表示安装成功

 

 

五、Amoeba 读写分离的配置

 1Master Slave1 Slave2 中开放权限给 Amoeba 访问。

 

Master Slave1 Slave2 中分别执行

 mysql> GRANT ALL ON *.* TO 'test_user'@'192.168.12.25' IDENTIFIED BY '1234';

Amoeba 访问三个数据库的账号密码相同(给dbServers.xml配置文件用)。

 

2、配置dbServers.xmlamoeba.xml

Amoeba for mysql读写分离主要涉及两个文件:/usr/local/amoeba/conf/dbServers.xml/usr/local/amoeba/conf/amoeba.xml

/usr/local/amoeba/conf/dbServers.xml配置,此文件定义由Amoeba代理的数据库如何连接,比如最基础的:主机IP、端口、Amoeba使用的用户名和密码等等。

<?xml version="1.0" encoding="gbk"?> 

 

<!DOCTYPE amoeba:dbServers SYSTEM "dbserver.dtd"> 

<amoeba:dbServers xmlns:amoeba="http://amoeba.meidusa.com/"> 

 

        <!--  

            Each dbServer needs to be configured into a Pool, 

            If you need to configure multiple dbServer with load balancing that can be simplified by the following configuration: 

             add attribute with name virtual = "true" in dbServer, but the configuration does not allow the element with name factoryConfig 

             such as 'multiPool' dbServer    

        --> 

 

    <!-- 数据库连接配置的公共部分 -->  

    <dbServer name="abstractServer" abstractive="true"> 

        <factoryConfig class="com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory"> 

            <property name="manager">${defaultManager}</property> 

            <property name="sendBufferSize">64</property> 

            <property name="receiveBufferSize">128</property> 

                 

            <!-- mysql port --> 

            <property name="port">3306</property> 

             

            <!-- mysql schema --> 

            <property name="schema"></property> 

             

            <!-- mysql user --> 

            <property name="user">test_user</property> 

             

            <!--  mysql password --> 

            <property name="password">1234</property> 

             

        </factoryConfig>  

 

        <poolConfig class="com.meidusa.amoeba.net.poolable.PoolableObjectPool"> 

            <property name="maxActive">500</property> 

            <property name="maxIdle">500</property> 

            <property name="minIdle">10</property> 

            <property name="minEvictableIdleTimeMillis">600000</property> 

            <property name="timeBetweenEvictionRunsMillis">600000</property> 

            <property name="testOnBorrow">true</property> 

            <property name="testWhileIdle">true</property> 

        </poolConfig> 

    </dbServer> 

 

    <!-- Master Slave1 Slave2 的独立部分,也就只有 IP --> 

    <dbServer name="master"  parent="abstractServer"> 

        <factoryConfig> 

            <!-- mysql ip --> 

            <property name="ipAddress">192.168.12.15</property> 

        </factoryConfig> 

    </dbServer> 

 

    <dbServer name="slave1"  parent="abstractServer"> 

        <factoryConfig> 

            <!-- mysql ip --> 

            <property name="ipAddress">192.168.12.16</property> 

        </factoryConfig> 

    </dbServer> 

 

    <dbServer name="slave2"  parent="abstractServer"> 

        <factoryConfig> 

            <!-- mysql ip --> 

            <property name="ipAddress">192.168.12.17</property>  

        </factoryConfig> 

    </dbServer>    

     

    <!-- 数据库池,虚拟服务器,实现读取的负载均衡 --> 

    <dbServer name="slaves" virtual="true"> 

        <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool"> 

            <!-- Load balancing strategy: 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA--> 

            <property name="loadbalance">1</property> 

             

            <!-- Separated by commas,such as: server1,server2,server1 --> 

            <property name="poolNames">slave1,slave2</property> 

        </poolConfig> 

    </dbServer> 

         

</amoeba:dbServers> 

/usr/local/amoeba/conf/amoeba.xml配置:

以下是amoeba调度器提供的外部访问用户访问本机的接口参数

                <service name="Amoeba for Mysql" class="com.meidusa.amoeba.net.ServerableConnectionManager">

                       <!--客户机访问调度器的端口,默认8066,可以改为3306,这样可以让用户无法觉察在访问调度器 --> 

                        <property name="port">3306</property>

                        <!-- bind ipAddress -->

                        <!--

                        <property name="ipAddress">127.0.0.1</property>

                         -->

……

                        <property name="authenticator">

                                <bean class="com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator">

 <!--客户机访问调度器账号名--> 

                                        <property name="user">root</property>

 <!--客户机访问调度器密码--> 

                                        <property name="password">root</property>

 

                                        <property name="filter">

                                                <bean class="com.meidusa.amoeba.server.IPAccessController">

                                                        <property name="ipFile">${amoeba.home}/conf/access_list.conf</property>

                                                </bean>

                                        </property>

                                </bean>

                        </property>

 

……

                <property name="LRUMapSize">1500</property>

                <property name="defaultPool">master</property>

                <property name="writePool">master</property>

                <property name="readPool">slaves</property>

                <property name="needParse">true</property>

defaultPool:配置了默认的数据库节点,一些除了SELECTUPDATEINSERTDELETE的语句都会在defaultPool执行。
writePool :配置了数据库写库,通常配为Master,如这里就配置为之前定义的Master数据库。

readPool :配置了数据库读库,通常配为Slave或者Slave组成的数据库池,如这里就配置之前的Slaves数据库池。

 

   

 

最后配置读写分离策略rule.xml

 

<queryRouter class="com.meidusa.amoeba.mysql.parser.MysqlQueryRouter"> 

    <property name="LRUMapSize">1500</property> 

    <property name="defaultPool">server1</property> 

    <property name="writePool">server1</property> 

    <property name="readPool">server2</property> 

    <property name="needParse">true</property> 

</queryRouter> 

 

从以上配置不然发现,写操作路由到server1master),读操作路由到server2slave

 

 

六、启动amoeba

./amoeba start

log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml

2015-10-13 21:51:35,206 INFO  context.MysqlRuntimeContext - Amoeba for Mysql current versoin=5.1.45-mysql-amoeba-proxy-2.2.0

log4j:WARN ip access config load completed from file:/usr/local/amoeba/conf/access_list.conf

2015-10-13 21:51:39,031 INFO  net.ServerableConnectionManager - Amoeba for Mysql listening on 0.0.0.0/0.0.0.0:3306.

2015-10-13 21:51:39,041 INFO  net.ServerableConnectionManager - Amoeba Monitor Server listening on /127.0.0.1:59731.

 表示正常运行

 ./amoeba start & 后台运行

如果出现错误可以tail -f /usr/local/amoeba/logs/root.log文件查找原因

 

 验证:

[root@DS conf]# mysql -uroot -p -h 192.168.12.25

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 519845905

Server version: 5.1.45-mysql-amoeba-proxy-2.2.0 Source distribution

 Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

 Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 mysql>


本想利用搭建好的amoeba实现moodle的数据库分离,但是遗憾的是:

【实验通过】利用Amoeba实验mysql读写分离的访问调度(二) - hyibing - 胡益兵的博客

 虽然后端的真实myslq版本是5.5.45符合moodle2.7以上版本的需求,但是moodle只认前端amoeba调度器显示的5.1.45,拒绝安装,而且

Amoeba早已已经停止更新了,在网上查阅了相关资料Amoeba目前的继任者是mycat,下一步就进入mycat的研究。


参考文献:

http://blog.csdn.net/cutesource/article/details/5710645

http://coolnull.com/1463.html

http://blog.chinaunix.net/uid-20639775-id-154600.html

http://www.iteye.com/topic/1113437

amoeba官网http://docs.hexnova.com/amoeba/

amoeba下载http://sourceforge.net/projects/amoeba/files/(由于3.x和2.x结构不同,本实验使用过的是2.x版)

Amoeba新版本MYSQL读写分离配置http://www.2cto.com/database/201107/97799.html

keepalived+lvs+读写分离+负载均衡http://www.2cto.com/database/201411/353346.html

mycat读写分离http://www.tuicool.com/articles/va2AFj

Spring 实现数据库读写分离http://www.cnblogs.com/surge/p/3582248.html

 mycat官网http://www.mycat.org.cn/

  评论这张
 
阅读(53)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018