分享

mysql-amoeba

 WindySky 2016-04-15

前面介绍了两款中间件,amoeba也属于mysql的中间件,这款产品倒没听说有啥毛病,就是不支持事务,多说无益直接贴配置(这里面主要修改两个配置文件):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# cat dbServers.xml
<?xml version="1.0" encoding="gbk"?>
<!DOCTYPE amoeba:dbServers SYSTEM "dbserver.dtd">
<amoeba:dbServers xmlns:amoeba="http://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.mysql.net.MysqlServerConnectionFactory">
   <property name="connectionManager">${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">LVS071103</property>
  </factoryConfig>
  <poolConfig class="com.meidusa.toolkit.common.poolable.PoolableObjectPool">
   <property name="maxActive">500</property>
   <property name="maxIdle">500</property>
   <property name="minIdle">1</property>
   <property name="minEvictableIdleTimeMillis">600000</property>
   <property name="timeBetweenEvictionRunsMillis">600000</property>
   <property name="testOnBorrow">true</property>
   <property name="testOnReturn">true</property>
   <property name="testWhileIdle">true</property>
  </poolConfig>
 </dbServer>
 <dbServer name="server2"  parent="abstractServer">
  <factoryConfig>
   <!-- mysql ip -->
   <property name="ipAddress">192.168.1.64</property>
  </factoryConfig>
 </dbServer>
 <dbServer name="server1"  parent="abstractServer">
  <factoryConfig>
   <!-- mysql ip -->
   <property name="ipAddress">192.168.1.66</property>
  </factoryConfig>
 </dbServer>
 <dbServer name="server3"  parent="abstractServer">
         <factoryConfig>
                 <!-- mysql ip -->
                       <property name="ipAddress">192.168.1.244</property>
                </factoryConfig>
         </dbServer>
 <dbServer name="master" 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">server2</property>
  </poolConfig>
 </dbServer>
 <dbServer name="slave" 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,server2,server3</property>
                </poolConfig>
        </dbServer>
</amoeba:dbServers>

amoeba.xml配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?xml version="1.0" encoding="gbk"?>
<!DOCTYPE amoeba:configuration SYSTEM "amoeba.dtd">
<amoeba:configuration xmlns:amoeba="http://amoeba./">
 <proxy>
  <!-- service class must implements com.meidusa.amoeba.service.Service -->
  <service name="Amoeba for Mysql" class="com.meidusa.amoeba.mysql.server.MySQLService">
   <!-- port -->
   <property name="port">8066</property>
   <!-- bind ipAddress -->
   <property name="ipAddress">192.168.1.63</property>
   <property name="connectionFactory">
    <bean class="com.meidusa.amoeba.mysql.net.MysqlClientConnectionFactory">
     <property name="sendBufferSize">128</property>
     <property name="receiveBufferSize">64</property>
    </bean>
   </property>
   <property name="authenticateProvider">
    <bean class="com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator">
     <property name="user">root</property>
     <property name="password">***********</property>
     <property name="filter">
      <bean class="com.meidusa.toolkit.net.authenticate.server.IPAccessController">
       <property name="ipFile">${amoeba.home}/conf/access_list.conf</property>
      </bean>
     </property>
    </bean>
   </property>
  </service>
  <runtime class="com.meidusa.amoeba.mysql.context.MysqlRuntimeContext">
   <!-- proxy server client process thread size -->
   <property name="executeThreadSize">128</property>
   <!-- per connection cache prepared statement size  -->
   <property name="statementCacheSize">500</property>
   <!-- default charset -->
   <property name="serverCharset">utf8</property>
   <!-- query timeout( default: 60 second , TimeUnit:second) -->
   <property name="queryTimeout">60</property>
  </runtime>
 </proxy>
 <!--
  Each ConnectionManager will start as thread
  manager responsible for the Connection IO read , Death Detection
 -->
 <connectionManagerList>
  <connectionManager name="defaultManager" class="com.meidusa.toolkit.net.MultiConnectionManagerWrapper">
   <property name="subManagerClassName">com.meidusa.toolkit.net.AuthingableConnectionManager</property>
  </connectionManager>
 </connectionManagerList>
  <!-- default using file loader -->
 <dbServerLoader class="com.meidusa.amoeba.context.DBServerConfigFileLoader">
  <property name="configFile">${amoeba.home}/conf/dbServers.xml</property>
 </dbServerLoader>
 <queryRouter class="com.meidusa.amoeba.mysql.parser.MysqlQueryRouter">
  <property name="ruleLoader">
   <bean class="com.meidusa.amoeba.route.TableRuleFileLoader">
    <property name="ruleFile">${amoeba.home}/conf/rule.xml</property>
    <property name="functionFile">${amoeba.home}/conf/ruleFunctionMap.xml</property>
   </bean>
  </property>
  <property name="sqlFunctionFile">${amoeba.home}/conf/functionMap.xml</property>
  <property name="LRUMapSize">1500</property>
  <property name="defaultPool">master</property>
  <property name="writePool">master</property>
  <property name="readPool">slave</property>
  <property name="needParse">true</property>
 </queryRouter>
</amoeba:configuration>

从别的机器上连接测试:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@YQD-intranet-salt-master ~]# mysql -uroot -p******** -h192.168.1.63 -P8066
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 1467214962
Server version: 5.1.45-mysql-amoeba-proxy-3.0.4-BETA Percona XtraDB Cluster (GPL), Release rel35.0, Revision 756, WSREP version 25.10, wsrep_25.10.r3985
Copyright (c) 2009-2014 Percona LLC and/or its affiliates
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

关闭写入DB测试:

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@YQD-Intranet-DB-NO2 ~]# /etc/init.d/mysql stop
Shutting down MySQL (Percona XtraDB Cluster)...... SUCCESS!
mysql> show databases;
ERROR 1044 (42000): poolName=master, no valid pools
mysql> select Host,User,Password from mysql.user where Host="192.168.1.63";
+--------------+------+-------------------------------------------+
| Host         | User | Password                                  |
+--------------+------+-------------------------------------------+
| 192.168.1.63 | cmon | *E8C5459B50EF1C73187CBEFB6D0FAF5C0F4E0812 |
| 192.168.1.63 | root | *72E95B62AD87ACEC6F1D064A57214A549FD4F762 |
+--------------+------+-------------------------------------------+
2 rows in set (0.01 sec)

当关闭写入DB时,select正常使用,其他则提示:

1
ERROR 1044 (42000): poolName=master, no valid pools

 

最后编辑:
作者:admin
这个作者貌似有点懒,什么都没有留下。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多