本文共 7252 字,大约阅读时间需要 24 分钟。
• 降低 数据切分带来的复杂多数据库结构 • 提供切分规则并降低 数据切分规则 给应用带来的影响 • 降低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单向步,不会配置访问http://skyson.blog.51cto.com/2497647/556600
- 另请安装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 修改主配置文件
-
<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 &
本文转自 ibelieveme 51CTO博客,原文链接:http://blog.51cto.com/skyson/623449,如需转载请自行联系原作者