您好,登錄后才能下訂單哦!
小編給大家分享一下Amoeba新版本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="">
<!--
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..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 &
看完了這篇文章,相信你對“Amoeba新版本MYSQL讀寫分離如何配置”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。