• amoeba实现读写分离


    amoeba的运行环境依靠java的jdk;

    下面执行amoeba的安装不走

    # mkdir /usr/local/src/amoeba

    上传文件:amoeba-mysql-binary-2.2.0.tar.gz

    # tar –xvf amoeba-mysql-binary-2.2.0.tar.gz  

    bin     执行文件目录

    conf    配置文件目录

    1.1.1    配置amoeba

    配置主、从mysql服务器链接信息等,下面配置文件中红色字体为需要注意或修改的地方;

    1.1.1.1dbServers.xml

    <?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">test</property>

              

               <!-- mysql user -->

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

              

               <!--  mysql password -->

               <property name="password">root</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="testOnReturn">true</property>

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

           </poolConfig>

        </dbServer>

     

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

           <factoryConfig>

               <!-- mysql ip -->

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

           </factoryConfig>

        </dbServer>

       

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

           <factoryConfig>

               <!-- mysql ip -->

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

           </factoryConfig>

        </dbServer>

       

        <dbServer name="multiPool" 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">master,slave</property>

           </poolConfig>

        </dbServer>

    </amoeba:dbServers>

    1.1.1.2amoeba.xml

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

     

    <!DOCTYPE amoeba:configuration SYSTEM "amoeba.dtd">

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

     

        <proxy>

       

           <!-- service class must implements com.meidusa.amoeba.service.Service -->

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

               <!-- port -->

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

              

               <!-- bind ipAddress -->

               <!--

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

                -->

              

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

              

               <property name="connectionFactory">

                  <bean class="com.meidusa.amoeba.mysql.net.MysqlClientConnectionFactory">

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

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

                  </bean>

               </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>

              

           </service>

          

           <!-- server class must implements com.meidusa.amoeba.service.Service -->

           <service name="Amoeba Monitor Server" class="com.meidusa.amoeba.monitor.MonitorServer">

               <!-- port -->

               <!--  default value: random number

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

               -->

               <!-- bind ipAddress -->

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

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

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

               <property name="connectionFactory">

                  <bean class="com.meidusa.amoeba.monitor.net.MonitorClientConnectionFactory"></bean>

               </property>

              

           </service>

          

           <runtime class="com.meidusa.amoeba.mysql.context.MysqlRuntimeContext">

               <!-- proxy server net IO Read thread size -->

               <property name="readThreadPoolSize">20</property>

              

               <!-- proxy server client process thread size -->

               <property name="clientSideThreadPoolSize">30</property>

              

               <!-- mysql server data packet process thread size -->

               <property name="serverSideThreadPoolSize">30</property>

              

               <!-- per connection cache prepared statement size  -->

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

              

               <!-- query timeout( default: 60 second , TimeUnit:second) -->

               <property name="queryTimeout">60</property>

           </runtime>

          

        </proxy>

       

        <!--

           Each ConnectionManager will start as thread

           manager responsible for the Connection IO read , Death Detection

        -->

        <connectionManagerList>

           <connectionManager name="clientConnectioneManager" class="com.meidusa.amoeba.net.MultiConnectionManagerWrapper">

               <property name="subManagerClassName">com.meidusa.amoeba.net.ConnectionManager</property>

               <!--

                 default value is avaliable Processors

               <property name="processors">5</property>

                -->

           </connectionManager>

           <connectionManager name="defaultManager" class="com.meidusa.amoeba.net.MultiConnectionManagerWrapper">

               <property name="subManagerClassName">com.meidusa.amoeba.net.AuthingableConnectionManager</property>

              

               <!--

                 default value is avaliable Processors

               <property name="processors">5</property>

                -->

           </connectionManager>

        </connectionManagerList>

       

           <!-- default using file loader -->

        <dbServerLoader class="com.meidusa.amoeba.context.DBServerConfigFileLoader">

           <property name="configFile">${amoeba.home}/conf/dbServers.xml</property>

        </dbServerLoader>

       

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

           <property name="ruleLoader">

               <bean class="com.meidusa.amoeba.route.TableRuleFileLoader">

                  <property name="ruleFile">${amoeba.home}/conf/rule.xml</property>

                  <property name="functionFile">${amoeba.home}/conf/ruleFunctionMap.xml</property>

               </bean>

           </property>

           <property name="sqlFunctionFile">${amoeba.home}/conf/functionMap.xml</property>

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

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

          

     

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

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

     

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

        </queryRouter>

    </amoeba:configuration>

    1.1.2    打开8066端口

    # /sbin/iptables -I INPUT -p tcp --dport 8066 -j ACCEPT

    # /etc/rc.d/init.d/iptables save      #修改生效

    # /etc/init.d/iptables status         #查看配置

    1.1.3    启动amoeba

    # ./bin/amoeba start 或 # ./bin/amoeba start &

     

    1.1.4    停止amoeba

    # ./bin/amoeba stop

    1.1.5    问题

    1、JAVA_HOME不认

    jdk安装后测试无问题java –version,但启动amoeba就是报错JAVA_HOME找不到。就修改/amoeba/bin/amoeba文件,在文件最开头直接写入JAVA_HOME环境变量。

    JAVA_HOME=/usr/local/src/java/jdk1.7.0_51

    2、java栈设置小

    默认配置Xss比较小128k,启动时提示太小,则修改/amoeba/bin/amoeba文件,修改为256k即可。

    DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss256k"

    3、amoeba连接的mysql都要开放访问权限

    否则访问拒绝,无法执行SQL语句

  • 相关阅读:
    Configuration Management
    Android Hooking
    技术趋势总结
    Maven Repo Mirror
    拥抱JAVA
    NPM 更新所有依赖项
    Knockout Mvc Compoment FrameSet With Typescript
    Knockoutjs Component问题汇总
    前端编码规范文档
    优秀程序设计的18大原则
  • 原文地址:https://www.cnblogs.com/wangfg/p/10627914.html
Copyright © 2020-2023  润新知