部署Amoeba3.X實現Mysql讀寫分離

來源:互聯網
上載者:User

項目介紹:

   Amoeba for Mysql軟體,致力於MySQL的分散式資料庫前端代理層,它主要在應用程式層訪問MySQL的時候充當SQL路由功能,專註於分散式資料庫代理層Database Proxy)開發。座落與Client、DB之間,對用戶端透明。具有負載平衡、高可用性、SQL過濾、讀寫分離、可路由相關的到目標資料庫、可並發請求多台資料庫合并結果。

實驗環境:

650) this.width=650;" src="http://www.bkjia.com/uploads/allimg/131229/21521M291-0.jpg" />

Master:192.168.0.1

Slave1:192.168.0.2

Slave2:192.168.0.3

Amoeba:192.168.0.4


均在Amoeba機器上操作

安裝JDK,Amoeba for mysq是基於JAVA環境開發的,所以系統要支援JAVA

wget http://download.oracle.com/otn/java/jdk/6u45-b06/jdk-6u45-linux-x64-rpm.binchmod +x jdk-6u45-linux-x64-rpm.bin./jdk-6u45-linux-x64-rpm.bin


配置JAVA環境

JKD預設安裝到/usr/java/下

建立軟連結

ln -s /usr/java/jdk1.6.0_45 /usr/java/jdk

編輯~/.bash_profile,添加以下內容

JAVA_HOME=/usr/java/jdkexport JAVA_HOMEexport CLASSPATH=.:JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarPATH=$PATH:$HOME/bin:$JAVA_HOME/binexport PATH


安裝Amoeba for mysql

wget http://jaist.dl.sourceforge.net/project/amoeba/Amoeba%20for%20mysql/3.x/amoeba-mysql-3.0.5-RC-distribution.zipunzip  amoeba-mysql-3.0.5-RC-distribution.zipmv amoeba-mysql-3.0.5-RC /usr/local/amoeba

Amoeba到此就安裝完畢,接下來就是配置讀寫分離,因為Amoeba3.x較2.x有較大改動,所以貼下我的配置項。

首先,設定conf/dbServer.xml中串連的庫名及帳號密碼

<dbServer name="abstractServer" abstractive="true">- - - - - 省略 - - - - - -                           <!-- mysql port -->            <property name="port">3306</property>                                                                                                                                                                                                                                                                                                                                       <!-- mysql schema -->            <property name="schema">資料庫名</property>                                                                                                                                                                                                                                                                                                                                       <!-- mysql user -->            <property name="user">帳號</property>                                                                                                                                                                                                                                                                                                                                       <property name="password">密碼</property>- - - - - - - - - 省略 - - - - - - -    </dbServer>

    設定資料庫池,其中Slave1,Slave2作輪詢

<dbServer name="Master"  parent="abstractServer">        <factoryConfig>            <!-- mysql ip -->            <property name="ipAddress">192.168.0.1</property>        </factoryConfig>    </dbServer>                                                                                                                                                                                                                                                                                                                 <dbServer name="Slave1"  parent="abstractServer">        <factoryConfig>            <!-- mysql ip -->            <property name="ipAddress">192.168.0.2</property>        </factoryConfig>    </dbServer>    <dbServer name="Slave2"  parent="abstractServer">        <factoryConfig>            <!-- mysql ip -->            <property name="ipAddress">192.168.0.3</property>        </factoryConfig>    </dbServer>    <dbServer name="VirtualPool" 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.xml

<property name="authenticateProvider">- - - - - - 省略 - - -                                       <property name="user">帳號</property>                                                                                                                                                                                                                                                                                                                                    <property name="password">密碼</property>                                                                                                                                                                                                                                                                                                                                    <property name="filter">       - - - - - - 省略 - - -            </property>
<queryRouter class="com.meidusa.amoeba.mysql.parser.MysqlQueryRouter">    - - - - - - 省略 - - - - -           <property name="defaultPool">Master</property>        <property name="writePool">Master</property>        <property name="readPool">VirtualPool</property>    - - - - - - 省略 - - - - -    </queryRouter>

讀寫分離到此配置完成,接著啟動amoebe

/usr/local/amoeba2/bin/launcher


在部署Amoeba時,注意下

1:防火牆要開放8066連接埠

2:給bin目錄執行許可權:chmod +x bin/*

最佳化效能:

1:在amoeba目錄下有個JVM的設定檔,設定其中的JVM_OPTIONS="-server -Xms1024m -Xmx1024m -Xss256k -XX:PermSize=16m -XX:MaxPermSize=96m"可提升JVM效能,具體大小看各位需求;

2:多線程配置:runtime元素;

3:網路相關緩衝區等):connectionFactory

本文出自 “擁抱開源世界分享開源技術” 部落格,請務必保留此出處http://sourceworld.blog.51cto.com/3392968/1294384

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.