程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> Amoeba新版本MYSQL讀寫分離配置

Amoeba新版本MYSQL讀寫分離配置

編輯:MySQL綜合教程

官方簡介
Amoeba的中文意思是變型蟲
主要解決:
• 降低 數據切分帶來的復雜多數據庫結構
• 提供切分規則並降低 數據切分規則 給應用帶來的影響
• 降低db 與客戶端的連接數
• 讀寫分離

個人簡單描述
可能你還沒明白Amoebla這鬼東西主要干麻的呢!比方說PHP環境眾所周知,PHP沒有數據連接池,如果PHP環境下MYSQL訪問量大時會蹦掉,除非配置Cluster集群,而Amoeba就是在PHP程序和MYSQL之間,充當一個緩沖的作用。

准備工作
Server:192.168.1.208 #Amoeba
Server:192.168.1.11  #NDBD1(主)
Server:1921.68.1.13  #NDBD2(從)
注:11和13兩台服務器上,事先請安裝好MYSQL單向步

另請安裝MYSQL版本必須5.1以上,因為新版的Amoeba2.10對5.1以下版本不穩定。

 

結構圖

 

Step 1:配置Amoeba192.168.2.8讀寫分離 
1:解壓安裝包
[root@Management down]# mkdir /usr/local/amoeba
[root@Management down]# tar -zxf amoeba-mysql-binary-2.1.0-RC5.tar.gz -C /usr/local/amoeba/
2:進入配置目錄,浏覽文件
[root@Management down]# cd /usr/local/amoeba/
[root@Management amoeba]# ll
total 88
drwxr-xr-x 2 root root    4096 Jul 26 11:57 benchmark
drwxr-xr-x 2 root root    4096 Feb 28 09:25 bin
-rw-r--r-- 1 root root    3983 May 18 13:43 changelogs.txt
drwxr-xr-x 2 root root    4096 Jul 26 11:57 conf
drwxr-xr-x 3 root root    4096 Jul 26 11:57 lib
-rw-r--r-- 1 root root 34520 May 18 13:43 LICENSE.txt
-rw-r--r-- 1 root root    2031 May 18 13:43 README.html
3:進入主配置文件目錄
[root@Management amoeba]# cd conf/
[root@Management conf]# ls
access_list.conf    amoeba.xml        dbServers.xml    functionMap.xml    log4j.xml    ruleFunctionMap.xml
amoeba.dtd                dbserver.dtd    function.dtd     log4j.dtd                rule.dtd     rule.xml
在這裡我主要介紹配置  amoeba.xml、    dbServers.xml、 log4j.xml 三個主要的配置文件,其它文件沒有特殊需要默認就可以了奪
4:vi amoeba.xml 修改主配置文件
4.1)把默認端口8066改成3306
<property name="port">3066</property>
4.2)把默認連接用戶名和密碼改成自己的
<property name="user">sky</property>

                                                                                <property name="password">123456</property>
4.3)把默認的客戶端線程數,請求數及服務端回應數改成200,300,300
<property name="readThreadPoolSize">200</property>

                                                <!-- proxy server client process thread size -->
                                                <property name="clientSideThreadPoolSize">300</property>

                                                <!-- mysql server data packet process thread size -->
                                                <property name="serverSideThreadPoolSize">300</property
4.4)把默認注釋掉的讀寫分離選項,把注釋去掉並readpool修改成server2
<!--
                                -->
                                <property name="writePool">server1</property>
                                <property name="readPool">server2</property>

                                    
 5:vi dbServers.xml 增加SEVER2模塊,裡面的連接用戶名密碼及地址都表示兩台MYSQL的物理機器,192.168.1.11和192.168.1.13 另SERVER1是寫,SERVER是讀
需要手動增加SERVER2代碼如下:
  <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">123456</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>

 

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

    <factoryConfig>

      <!-- mysql ip -->

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

    </factoryConfig>

  </dbServer>


最終改變成如下:
<?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">123456</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>

 

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

    <factoryConfig>

      <!-- mysql ip -->

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

    </factoryConfig>

  </dbServer>

 

 

      <!-- ########################把如上的內容復制到下面,來增加SERVER2############################ -->

 

 

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

       

      <property name="password">123456</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>

 

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

    <factoryConfig>

      <!-- mysql ip -->

      <property name="ipAddress">192.168.2.13</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">server1</property>

    </poolConfig>

  </dbServer>

    

</amoeba:dbServers>

 

6:修改log4j.xml 取消日志文件生成(太大了,磁盤很容易滿)
<param name="file" value="${amoeba.home}/logs/project.log"/>
改成
<param name="file" value="<![CDATA[${amoeba.home}/logs/project.log>/dev/null]]>"/>
7:性能優化,打開bin/amoeba

DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss128k"
改成
DEFAULT_OPTS="-server -Xms512m -Xmx512m -Xmn100m -Xss1204k"
8:啟動amoeba
nohup /usr/local/amoeba/bin/amoeba start 2>&1 >/dev/null &

 


本文出自 “Intelligence” 博客

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved