标签:
1. 配置环境:
服务器 |
IP |
系统 |
Amoeba |
192.168.1.99 |
Centos 6.0 X64 |
Mysql |
192.168.1.88 |
Centos 6.0 X64 |
Mysql |
192.168.1.99 |
Centos 6.0 X64 |
启动服务:特别注意:所有节点一定要关闭Iptables
2. 安装Mysql(192.168.1.99)
# yum install mysql
# yum install mysql-server
# yum install mysql-devel
# chgrp -R mysql /var/lib/mysql
# chmod -R 770 /var/lib/mysql
# service mysqld start
# mysql
>SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD(‘secret_password‘);
>flush privileges;
# chkconfig --levels 345 mysqld on
自定义解决登录问题:
# mysql –uroot –p
# grant all privileges on *.* to root@192.168.1.101 identified by ‘good’;
# flush privileges;
到192.168.1.101下客户端连接到mysql
删除所有mysql库下user表所有记录
# mysql –uroot –p
>insert into
mysql.user(host,user,password) values ("localhost","root",p
assword("good"));
>grant all privileges on *.* to root@127.0.0.1 identified by ‘good’;
>flush privileges;
>grant all privileges on *.* to root@localhost identified by ‘good’;
>flush privileges;
>quit
#mysql –uroot –pgood –h127.0.0.1 –P3306
3. 安装Java1.6.0(192.168.1.99)
当需要开发Java 相关的程序时候就会需要下载JDK 建立Java 需要的环境。
使用yum 的安装方式
#yum -y install java-1.6.0-openjdk java-1.6.0-openjdk-devel
安装完成后检查Java 版本是不是正确
#java -version
出现版本的信息
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.8) (rhel-1.22.1.9.8.el5_6-x86_64)
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
设定环境变量
#vi /etc/profile
将以下的设定复制到文件中
JAVA_HOME=/usr/lib/jvm/java-1.6.0 依当时安装路径设定
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH JAVA_HOME CLASSPATH
启用新的配置文件
#source /etc/profile
或者:直接复制amoeba目录下的profile到/etc即可
4. 安装Amoeba2.0.1(192.168.1.99)
# cd /usr/local
# mkdir amoeba
# tar –zxvf amoeba-mysql-binary-2.0.1-BETA.tar.gz –C /usr/local/amoeba
# vi /usr/local/amoeba/conf/dbServer.xml
5. 配置Amoeba(192.168.1.99)
注意:配置文件中红色部分(源码实例注释密码验证,需取消注释)
5.1 配置conf/dbServers.xml (对真实Mysql数据连接的配置)
<?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">good</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">127.0.0.1</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>
5.2、配置conf/amoeba.xml
<?xml version="1.0" encoding="gbk"?>
<!DOCTYPE amoeba:configuration SYSTEM "amoeba.dtd">
<amoeba:configuration xmlns:amoeba="http://amoeba.meidusa.com/">
<proxy>
<!-- server 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">127.0.0.1</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">root</property>
<property name="password">good</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">127.0.0.1</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">server1</property>
<!--
<property name="writePool">server1</property>
<property name="readPool">server1</property>
-->
<property name="needParse">true</property>
</queryRouter>
</amoeba:configuration>
6. 配置分片数据(192.168.1.99)
6.1 配置conf/dbServers.xml (添加如下代码)
<dbServer name="server2" parent="abstractServer">
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">192.168.0.1</property>
</factoryConfig>
</dbServer>
6.2 配置conf/rule.xml (全部替换如下代码)
<?xml version="1.0" encoding="gbk"?>
<!DOCTYPE amoeba:rule SYSTEM "rule.dtd">
<amoeba:rule xmlns:amoeba="http://amoeba.meidusa.com/">
<tableRule name="staff" schema="test" defaultPools="server1,server2">
<rule name="rule1" ruleResult="POOLNAME">
<parameters>ID</parameters>
<expression><![CDATA[
var division = ID % 2;
case division when 0 then ‘server1‘;
when 1 then ‘server2‘;
end case;
]]></expression>
</rule>
</tableRule>
</amoeba:rule>
标签:
原文地址:http://www.cnblogs.com/bluetech/p/4299759.html