使用Amoeba Aladdin连接Oracle数据库

Amoeba是一个数据库代理,用他可以完成数据库Replication,Sharding,读写分离等等。Amoeba本身最适合mysql数据库,但是使用Amoeba Aladdin也可以链接其他支持jdbc的数据库。对于mysql数据库的配置,amoeba的 官方文档 有比较详细的介绍,但是对于aladdin很不详细(那个官方文档好像是根本没写完的样子)。经过一番摸索,配置了用amoeba连接Oracle的sharding集群。虽然和mysql的配置区别不大,还是在这里记录一下备忘。

首先,配置dbServer.xml:

[html]  view plain copy
  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.     <dbServer name="abstractServer" abstractive="true">  
  7.               
  8.             <factoryConfig class="com.meidusa.amoeba.jdbc.JdbcConnectionFactory">  
  9.                 <property name="driver">  
  10.                     <bean class="com.meidusa.amoeba.jdbc.DriverWrapper">  
  11.                         <property name="driver">  
  12.                             <bean class="oracle.jdbc.driver.OracleDriver"/>  
  13.                         </property>  
  14.                     </bean>  
  15.                 </property>  
  16.                   
  17.                    
  18.                 <!-- jdbc url. -->  
  19.                 <property name="url">jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:test</property>  
  20.                   
  21.                 <!-- url -->  
  22.                 <property name="properties">  
  23.                     <bean class="java.util.Properties">  
  24.                         <property name="user">user</property>  
  25.                         <property name="password">passwd</property>  
  26.                     </bean>  
  27.                 </property>  
  28.                   
  29.             </factoryConfig>  
  30.             <poolConfig class="com.meidusa.amoeba.net.poolable.PoolableObjectPool">  
  31.                 <property name="maxActive">200</property>  
  32.                 <property name="maxIdle">200</property>  
  33.                 <property name="minIdle">10</property>  
  34.                 <property name="minEvictableIdleTimeMillis">600000</property>  
  35.                 <property name="timeBetweenEvictionRunsMillis">600000</property>  
  36.                 <property name="testOnBorrow">true</property>  
  37.                 <property name="testWhileIdle">true</property>  
  38.             </poolConfig>  
  39.     </dbServer>  
  40.   
  41.     <dbServer name="server1"  parent="abstractServer">  
  42.         <factoryConfig>  
  43.             <property name="url">jdbc:oracle:thin:xxx.xxx.xxx.xxx:1521:test</property>  
  44.         </factoryConfig>  
  45.     </dbServer>  
  46.       
  47.     <dbServer name="server2"  parent="abstractServer">  
  48.         <factoryConfig>  
  49.             <property name="url">jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:test</property>  
  50.         </factoryConfig>  
  51.     </dbServer>  
  52. </amoeba:dbServers>  

然后,amoeba.xml的配置:

[html]  view plain copy
  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 Aladdin" class="com.meidusa.amoeba.net.ServerableConnectionManager">  
  10.             <!-- port -->  
  11.             <property name="port">8066</property>  
  12.               
  13.             <!-- bind ipAddress -->  
  14.             <!--  
  15.             <property name="ipAddress">127.0.0.1</property> 
  16.              -->  
  17.               
  18.             <property name="manager">${clientConnectioneManager}</property>  
  19.               
  20.             <property name="connectionFactory">  
  21.                 <bean class="com.meidusa.amoeba.aladdin.net.AladdinClientConnectionFactory">  
  22.                     <property name="sendBufferSize">128</property>  
  23.                     <property name="receiveBufferSize">64</property>  
  24.                 </bean>  
  25.             </property>  
  26.               
  27.             <property name="authenticator">  
  28.                 <bean class="com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator">  
  29.                       
  30.                     <property name="user">user</property>  
  31.                       
  32.                     <property name="password">passwd</property>  
  33.                       
  34.                     <property name="filter">  
  35.                         <bean class="com.meidusa.amoeba.server.IPAccessController">  
  36.                             <property name="ipFile">${amoeba.home}/conf/access_list.conf</property>  
  37.                         </bean>  
  38.                     </property>  
  39.                 </bean>  
  40.             </property>  
  41.               
  42.         </service>  
  43.           
  44.         <!-- server class must implements com.meidusa.amoeba.service.Service -->  
  45.         <service name="Amoeba Monitor Server" class="com.meidusa.amoeba.monitor.MonitorServer">  
  46.             <!-- port -->  
  47.             <!--  default value: random number  
  48.             <property name="port">9066</property>  
  49.             -->  
  50.             <!-- bind ipAddress -->  
  51.             <property name="ipAddress">127.0.0.1</property>  
  52.             <property name="daemon">true</property>  
  53.             <property name="manager">${clientConnectioneManager}</property>  
  54.             <property name="connectionFactory">  
  55.                 <bean class="com.meidusa.amoeba.monitor.net.MonitorClientConnectionFactory"></bean>  
  56.             </property>  
  57.               
  58.         </service>  
  59.           
  60.         <runtime class="com.meidusa.amoeba.mysql.context.MysqlRuntimeContext">  
  61.             <!-- proxy server net IO Read thread size -->  
  62.             <property name="readThreadPoolSize">20</property>  
  63.               
  64.             <!-- proxy server client process thread size -->  
  65.             <property name="clientSideThreadPoolSize">30</property>  
  66.               
  67.             <!-- mysql server data packet process thread size -->  
  68.             <property name="serverSideThreadPoolSize">30</property>  
  69.               
  70.             <!-- per connection cache prepared statement size  -->  
  71.             <property name="statementCacheSize">500</property>  
  72.               
  73.             <!-- query timeout( default: 60 second , TimeUnit:second) -->  
  74.             <property name="queryTimeout">60</property>  
  75.               
  76.             <property name="serverCharset">utf8</property>  
  77.         </runtime>  
  78.           
  79.     </proxy>  
  80.       
  81.     <!--   
  82.         Each ConnectionManager will start as thread  
  83.         manager responsible for the Connection IO read , Death Detection  
  84.     -->  
  85.     <connectionManagerList>  
  86.         <connectionManager name="clientConnectioneManager" class="com.meidusa.amoeba.net.MultiConnectionManagerWrapper">  
  87.             <property name="subManagerClassName">com.meidusa.amoeba.net.ConnectionManager</property>  
  88.             <!--   
  89.               default value is avaliable Processors   
  90.             <property name="processors">5</property>  
  91.              -->  
  92.         </connectionManager>  
  93.         <connectionManager name="defaultManager" class="com.meidusa.amoeba.net.MultiConnectionManagerWrapper">  
  94.             <property name="subManagerClassName">com.meidusa.amoeba.net.AuthingableConnectionManager</property>  
  95.               
  96.             <!--   
  97.               default value is avaliable Processors   
  98.             <property name="processors">5</property>  
  99.              -->  
  100.         </connectionManager>  
  101.     </connectionManagerList>  
  102.       
  103.         <!-- default using file loader -->  
  104.     <dbServerLoader class="com.meidusa.amoeba.context.DBServerConfigFileLoader">  
  105.         <property name="configFile">${amoeba.home}/conf/dbServers.xml</property>  
  106.     </dbServerLoader>  
  107.       
  108.     <queryRouter class="com.meidusa.amoeba.aladdin.parser.AladdinQueryRouter">  
  109.         <property name="ruleLoader">  
  110.             <bean class="com.meidusa.amoeba.route.TableRuleFileLoader">  
  111.                 <property name="ruleFile">${amoeba.home}/conf/rule.xml</property>  
  112.                 <property name="functionFile">${amoeba.home}/conf/ruleFunctionMap.xml</property>  
  113.             </bean>  
  114.         </property>  
  115.         <property name="sqlFunctionFile">${amoeba.home}/conf/functionMap.xml</property>  
  116.         <property name="LRUMapSize">1500</property>  
  117.         <property name="defaultPool">server1</property>  
  118.           
  119.         <!--  
  120.         <property name="writePool">server1</property>  
  121.         <property name="readPool">server1</property>  
  122.         -->  
  123.         <property name="needParse">true</property>  
  124.     </queryRouter>  
  125. </amoeba:configuration>  

最后,rule.xml的配置,和mysql是一样的:

[html]  view plain copy
  1. <?xml version="1.0" encoding="gbk"?>  
  2. <!DOCTYPE amoeba:rule SYSTEM "rule.dtd">  
  3.   
  4. <amoeba:rule xmlns:amoeba="http://amoeba.meidusa.com/">  
  5.   
  6.     <tableRule name="staff" schema="test" defaultPools="server1,server2">  
  7.           
  8.         <rule name="rule1" ruleResult="POOLNAME">  
  9.             <parameters>ID</parameters>   
  10.             <expression><![CDATA[ 
  11.             var division = ID % 2; 
  12.             case division when 0 then 'server1'; 
  13.             when 1 then 'server2'; 
  14.             end case;]]></expression>  
  15.         </rule>  
  16.           
  17.     </tableRule>  
  18.       
  19. </amoeba:rule>  

你可能感兴趣的:(使用Amoeba Aladdin连接Oracle数据库)