Amoeba是一個以MySQL為底層數據存儲,並對應用提供MySQL協議接口的proxy。它集中地響應應用的請求,依據用戶事先設置的規則,將SQL請求發送到特定的數據庫上執行,下面我們來看看amoeba mysql的安裝配置教程。
1、配置好mysql的主從環境,服務器如下:
代碼如下
復制代碼
master:172.16.206.129
slave:172.16.206.130
amoeba:172.16.206.131
2、amoeba配置好JDK環境
可以去oracle的官網去下載JDK,安裝目錄一邊不是標准的命名,使用如下命令做軟連接:
ln -s /usr/java/jdk1.8.0_11/ /usr/java/jdk1.8
配置JDK環境:
在/etc/profile文件末尾添加以下環境參數
代碼如下
復制代碼
export JAVA_HOME=/usr/java/jdk1.8
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
PS:下載的JDK需要和平台對應,uname 可以查看平台類型
3、下載amoeba
網上搜索可以去一些開源軟件的網站下載
4、安裝amoeba
安裝路徑/usr/local/amoeba
5、修改amoeba配置參數
/usr/local/amoeba/conf/amoeba.xml 修改如下:
代碼如下
復制代碼
1 <?xml version=”1.0″ encoding=”gbk”?>
2
3 <!DOCTYPE amoeba:configuration SYSTEM “amoeba.dtd”>
4 <amoeba:configuration xmlns:amoeba=”http://amoeba.meidusa.com/”>
5
6 <proxy>
7
8 <!– service class must implements com.meidusa.amoeba.service.Service –>
9 <service name=”Amoeba for Mysql” class=”com.meidusa.amoeba.mysql.server.MySQLService”>
10 <!– port default –>
11 <property name=”port”>8066</property>
12
13 <!– bind ipAddress –>
14 <!–salley 修改綁定IP地址–>
15<property name=”ipAddress”>172.16.206.129</property>
16
17
18 <property name=”connectionFactory”>
19 <bean class=”com.meidusa.amoeba.mysql.net.MysqlClientConnectionFactory”>
20 <property name=”sendBufferSize”>128</property>
21 <property name=”receiveBufferSize”>64</property>
22 </bean>
23 </property>
24
25 <property name=”authenticateProvider”>
26 <bean class=”com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator”>
27 <!– 訪問amoeba的賬戶名 –>
28 <property name=”user”>amoeba</property>
29 <!– 訪問amoeba的密碼 –>
30<property name=”password”>123456</property>
31
32 <property name=”filter”>
33 <bean class=”com.meidusa.toolkit.net.authenticate.server.IPAccessController”>
34 <property name=”ipFile”>${amoeba.home}/conf/access_list.conf</property>
35 </bean>
36 </property>
37 </bean>
38 </property>
39
40 </service>
41
42 <runtime class=”com.meidusa.amoeba.mysql.context.MysqlRuntimeContext”>
43
44 <!– proxy server client process thread size –>
45 <property name=”executeThreadSize”>128</property>
46
47 <!– per connection cache prepared statement size –>
48 <property name=”statementCacheSize”>500</property>
49
50 <!– default charset –>
51 <property name=”serverCharset”>utf8</property>
52
53 <!– query timeout( default: 60 second , TimeUnit:second) –>
54 <property name=”queryTimeout”>60</property>
55 </runtime>
56
57 </proxy>
58
59 <!–
60 Each ConnectionManager will start as thread
61 manager responsible for the Connection IO read , Death Detection
62 –>
63 <connectionManagerList>
64 <connectionManager name=”defaultManager” class=”com.meidusa.toolkit.net.MultiConnectionManagerWrapper”>
65 <property name=”subManagerClassName”>com.meidusa.toolkit.net.AuthingableConnectionManager</property>
66 </connectionManager>
67 </connectionManagerList>
68
69 <!– default using file loader –>
70 <dbServerLoader class=”com.meidusa.amoeba.context.DBServerConfigFileLoader”>
71 <property name=”configFile”>${amoeba.home}/conf/dbServers.xml</property>
72 </dbServerLoader>
73
74 <queryRouter class=”com.meidusa.amoeba.mysql.parser.MysqlQueryRouter”>
75 <property name=”ruleLoader”>
76 <bean class=”com.meidusa.amoeba.route.TableRuleFileLoader”>
77 <property name=”ruleFile”>${amoeba.home}/conf/rule.xml</property>
78 <property name=”functionFile”>${amoeba.home}/conf/ruleFunctionMap.xml</property>
79 </bean>
80 </property>
81 <property name=”sqlFunctionFile”>${amoeba.home}/conf/functionMap.xml</property>
82 <property name=”LRUMapSize”>1500</property>
83<property name=”defaultPool”>master</property>
84 <property name=”writePool”>master</property>
85 <property name=”readPool”>multiPool</property>
86<property name=”needParse”>true</property>
87 </queryRouter>
88 </amoeba:configuration>
/usr/local/amoeba/conf/dbServer.xml 修改如下:
代碼如下
復制代碼
1 <?xml version=”1.0″ encoding=”gbk”?>
2
3 <!DOCTYPE amoeba:dbServers SYSTEM “dbserver.dtd”>
4 <amoeba:dbServers xmlns:amoeba=”http://amoeba.meidusa.com/”>
5
6 <!–
7 Each dbServer needs to be configured into a Pool,
8 If you need to configure multiple dbServer with load balancing that can be simplified by the following configuration:
9 add attribute with name virtual = “true” in dbServer, but the configuration does not allow the element with name factoryConfig
10 such as ‘multiPool’ dbServer
11 –>
12
13 <dbServer name=”abstractServer” abstractive=”true”>
14 <factoryConfig class=”com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory”>
15 <property name=”connectionManager”>${defaultManager}</property>
16 <property name=”sendBufferSize”>64</property>
17 <property name=”receiveBufferSize”>128</property>
18
19 <!– mysql port 訪問MySQL的端口號 –>
20<property name=”port”>3306</property>
21
22 <!– mysql schema 訪問MySQL默認的數據庫–>
23<property name=”schema”>test</property>
24
25 <!– mysql user 訪問MySQL的賬戶名–>
26 <property name=”user”>amoeba</property>
27 <!– mysql password 訪問MySQL的密碼–>
28<property name=”password”>123456</property>
29 </factoryConfig>
30
31 <poolConfig class=”com.meidusa.toolkit.common.poolable.PoolableObjectPool”>
32 <property name=”maxActive”>500</property>
33 <property name=”maxIdle”>500</property>
34 <property name=”minIdle”>1</property>
35 <property name=”minEvictableIdleTimeMillis”>600000</property>
36 <property name=”timeBetweenEvictionRunsMillis”>600000</property>
37 <property name=”testOnBorrow”>true</property>
38 <property name=”testOnReturn”>true</property>
39 <property name=”testWhileIdle”>true</property>
40 </poolConfig>
41 </dbServer>
42
43<dbServer name=”master” parent=”abstractServer”>
44 <factoryConfig>
45 <!– mysql ip –>
46 <property name=”ipAddress”>172.16.206.129</property>
47 </factoryConfig>
48 </dbServer>
49
50 <dbServer name=”slave” parent=”abstractServer”>
51 <factoryConfig>
52 <!– mysql ip –>
53<property name=”ipAddress”>172.16.206.130</property>
54 </factoryConfig>
55 </dbServer>
56
57 <dbServer name=”multiPool” virtual=”true”>
58 <poolConfig class=”com.meidusa.amoeba.server.MultipleServerPool”>
59 <!– Load balancing strategy: 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA–>
60 <property name=”loadbalance”>1</property>
61
62 <!– Separated by commas,such as: server1,server2,server1 –>
63 <property name=”poolNames”>master,slave,slave</property>
64
65 </poolConfig>
66 </dbServer>
67
68 </amoeba:dbServers>
啟動amoeba
/usr/local/amoeba/bin/launcher &
關閉amoeba
/usr/local/amoeba/bin/shutdown
amoeba不支持存儲過程、不支持大數據量查詢,這個比較討厭,所以我最後還是沒有用amoeba