Chinaunix首页 | 论坛 | 博客
  • 博客访问: 22386
  • 博文数量: 3
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 10
  • 用 户 组: 普通用户
  • 注册时间: 2015-08-21 16:04
文章分类
文章存档

2015年(3)

我的朋友
最近访客

分类: Mysql/postgreSQL

2015-10-12 10:01:16

原文地址:Amoeba for mysq 作者:xuexiaogang

Amoeba for mysql的搭建

192.168.56.102        master1

192.168.56.103        slave1

192.168.56.104        amoeba

1.  安装java环境

[root@amoeba ~]# tar zxvf jdk-7u79-linux-x64.tar.gz -C /usr/local/java/

[root@amoeba ~]# vi /etc/profile

添加javaamoeba环境变量:

PATH=$PATH:$HOME/bin:/usr/local/amoeba/bin:/usr/local/java/jdk1.7.0_79/bin

JAVA_HOME=/usr/local/java/jdk1.7.0_79

export JAVA_HOME

export PATH

[root@amoeba ~]# source /etc/profile

[root@amoeba ~]# java -version

java version "1.7.0_79"

Java(TM) SE Runtime Environment (build 1.7.0_79-b15)

Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

2.  安装amoeba

[root@amoeba ~]# tar zxvf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/

[root@amoeba local]# mv amoeba-mysql-binary-2.2.0 amoeba

3.  amoeba配置文件

Amoeba有哪些主要的配置文件?

style="mso-spacerun:yes;">  这里比较详细。

  1. 想象Amoeba作为数据库代理层,它一定会和很多数据库保持通信,因此它必须知道由它代理的数据库如何连接,比如最基础的:主机IP、端口、Amoeba使用的用户名和密码等等。这些信息存储在$AMOEBA_HOME/conf/dbServers.xml中。

 

二.Amoeba为了完成数据切分提供了完善的切分规则配置,为了了解如何分片数据、如何将数据库返回的数据整合,它必须知道切分规则。与切分规则相关的信息存储在$AMOEBA_HOME/conf/rule.xml中。

 

三.当我们书写SQL来操作数据库的时候,常常会用到很多不同的数据库函数,比如:UNIX_TIMESTAMP()SYSDATE()等等。这些函数如何被Amoeba解析呢?$AMOEBA_HOME/conf/functionMap.xml描述了函数名和函数处理的关系。

 

四.对$AMOEBA_HOME/conf/rule.xml进行配置时,会用到一些我们自己定义的函数,比如我们需要对用户IDHASH值来切分数据,这些函数在$AMOEBA_HOME/conf/ruleFunctionMap.xml中定义。

五.Amoeba可以制定一些可访问以及拒绝访问的主机IP地址,这部分配置在$AMOEBA_HOME/conf/access_list.conf

 

六.Amoeba允许用户配置输出日志级别以及方式,配置方法使用log4j的文件格式,文件是$AMOEBA_HOME/conf/log4j.xml

 

DbServers.xml配置文件:

[root@amoeba conf]# more dbServers.xml

<?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.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">amoeba</property>

 

                        <!--  mysql password -->

                        <property name="password">111111</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="testOnReturn">true</property>

                        <property name="testWhileIdle">true</property>

                </poolConfig>

        </dbServer>

 

        <dbServer name="master1"  parent="abstractServer">

                <factoryConfig>

                        <!-- mysql ip -->

                        <property name="ipAddress">192.168.56.102</property>

                </factoryConfig>

        </dbServer>

 

        <dbServer name="slave1"  parent="abstractServer">

                <factoryConfig>

                        <!-- mysql ip -->

                        <property name="ipAddress">192.168.56.103</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">slave1</property>

                </poolConfig>

        </dbServer>

 

</amoeba:dbServers>

 

Amoeba.xml配置文件:

[root@amoeba conf]# more amoeba.xml

<?xml version="1.0" encoding="gbk"?>

 

<!DOCTYPE amoeba:configuration SYSTEM "amoeba.dtd">

<amoeba:configuration xmlns:amoeba="

 

        <proxy>

 

                <!-- service class must implements com.meidusa.amoeba.service.Service -->

                <service name="Amoeba for Mysql" class="com.meidusa.amoeba.net.ServerableConnectionManager">

                        <!-- port -->

                        <property name="port">8066</property>

 

                        <!-- bind ipAddress -->

                        <!--                -->

                        <property name="ipAddress">192.168.56.104</property>

 

                        <property name="manager">${clientConnectioneManager}</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="authenticator">

                                <bean class="com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator">

 

                                        <property name="user">amoeba</property>

 

                                        <property name="password">111111</property>

 

                                        <property name="filter">

                                                <bean class="com.meidusa.amoeba.server.IPAccessController">

                                                        <property name="ipFile">${amoeba.home}/conf/access_list.conf</property>

                                                </bean>

                                        </property>

                                </bean>

                        </property>

 

                </service>

 

                <!-- server class must implements com.meidusa.amoeba.service.Service -->

                <service name="Amoeba Monitor Server" class="com.meidusa.amoeba.monitor.MonitorServer">

                        <!-- port -->

                        <!--  default value: random number -->

                        <property name="port">9066</property>

                        <!-- bind ipAddress -->

                        <property name="ipAddress">192.168.56.104</property>

                        <property name="daemon">true</property>

                        <property name="manager">${clientConnectioneManager}</property>

                        <property name="connectionFactory">

                                <bean class="com.meidusa.amoeba.monitor.net.MonitorClientConnectionFactory"></bean>

                        </property>

 

                </service>

 

                <runtime class="com.meidusa.amoeba.mysql.context.MysqlRuntimeContext">

                        <!-- proxy server net IO Read thread size -->

                        <property name="readThreadPoolSize">20</property>

 

                        <!-- proxy server client process thread size -->

                        <property name="clientSideThreadPoolSize">30</property>

 

                        <!-- mysql server data packet process thread size -->

                        <property name="serverSideThreadPoolSize">30</property>

 

                        <!-- per connection cache prepared statement size  -->

                        <property name="statementCacheSize">500</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="clientConnectioneManager" class="com.meidusa.amoeba.net.MultiConnectionManagerWrapper">

                        <property name="subManagerClassName">com.meidusa.amoeba.net.ConnectionManager</property>

                        <!--

                          default value is avaliable Processors

                        <property name="processors">5</property>

                         -->

                </connectionManager>

                <connectionManager name="defaultManager" class="com.meidusa.amoeba.net.MultiConnectionManagerWrapper">

                        <property name="subManagerClassName">com.meidusa.amoeba.net.AuthingableConnectionManager</property>

 

                        <!--

                          default value is avaliable Processors

                        <property name="processors">5</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">master1</property>

 

                <!—  -->

                <property name="writePool">master1</property>

                <property name="readPool">slave1</property>

                <property name="needParse">true</property>

        </queryRouter>

</amoeba:configuration>

 

需要在主从节点添加用户amoeba及其权限:

Grant all on *.* to ‘amoeba’@’192.168.56.104’ identified by ‘111111’;

 

4.  启动amoeba

[root@amoeba conf]# nohup amoeba start & --后台启动

[root@amoeba conf]# amoeba start  ---前台启动

log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml

2015-06-19 03:10:38,351 INFO  context.MysqlRuntimeContext - Amoeba for Mysql current versoin=5.1.45-mysql-amoeba-proxy-2.2.0

log4j:WARN ip access config load completed from file:/usr/local/amoeba/conf/access_list.conf

2015-06-19 03:10:38,683 INFO  net.ServerableConnectionManager - Amoeba for Mysql listening on /192.168.56.104:8066.

2015-06-19 03:10:38,689 INFO  net.ServerableConnectionManager - Amoeba Monitor Server listening on /192.168.56.104:9066.

 

[root@amoeba conf]# mysql -uamoeba -p111111 -h192.168.56.104 -P8066

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 899565349

Server version: 5.1.45-mysql-amoeba-proxy-2.2.0 Source distribution

 

Copyright (c) 2000, 2013, 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              |

| test               |

| xx                 |

+--------------------+

4 rows in set (0.01 sec)

 

登录成功。

阅读(1857) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:ZooKeeper典型应用场景

给主人留下些什么吧!~~