时间:2021-07-01 10:21:17 帮助过:3人阅读
2.5 修改主配置文件:
[root@lvs_172 conf]# vi amoeba.xml
<?xml version="1.0" encoding="gbk"?>
<!DOCTYPE amoeba:configuration SYSTEM "amoeba.dtd">
<amoeba:configuration xmlns:amoeba="http://amoeba.meidusa.com/">
<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">188.188.1.188</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">123456</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">200</property>
<!-- proxy server client process thread size -->
<property name="clientSideThreadPoolSize">300</property>
<!-- mysql server data packet process thread size -->
<property name="serverSideThreadPoolSize">300</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>
<!-- 修改写为server1,读为server2 -->
<property name="writePool">server1</property>
<property name="readPool">server2</property>
<property name="needParse">true</property>
</queryRouter>
</amoeba:configuration>
2.6 配置dbServers.xml 文件,增加server2
[root@lvs_172 conf]# vi dbServers.xml
<?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>
<!-- 自己密码-->
<property name="password">123456</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">188.188.1.144</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>
<!-- 这后面是server2的配置 ,复制上面的内容,server1的 -->
<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>
<!-- 自己密码-->
<property name="password">123456</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="server2" parent="abstractServer">
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">188.188.1.175</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">server2</property>
</poolConfig>
</dbServer>
2.7 启动服务:
[root@lvs_172 logs]# /usr/local/amoeba/bin/amoeba start &
查看服务状态:
[root@lvs_172 logs]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:813 0.0.0.0:* LISTEN 2751/rpc.statd
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 3070/couriertcpd
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 3064/couriertcpd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2721/portmap
tcp 0 0 0.0.0.0:16851 0.0.0.0:* LISTEN 3321/modclusterd
tcp 0 0 ::ffff:188.188.1.188:8066 :::* LISTEN 20280/java
tcp 0 0 :::22 :::* LISTEN 3031/sshd
tcp 0 0 ::ffff:127.0.0.1:38269 :::* LISTEN 20280/java
[root@lvs_172 logs]# ps -ef | grep amoe
root 20280 3411 0 16:22 pts/0 00:00:02 /usr/local/jdk/bin/java -server -Xms256m -Xmx256m -Xss128k -Damoeba.home=/usr/local/amoeba -Dclassworlds.conf=/usr/local/amoeba/bin/amoeba.classworlds -classpath /usr/local/amoeba/lib/classworlds-1.0.jar org.codehaus.classworlds.Launcher start
root 20655 3411 0 17:43 pts/0 00:00:00 grep amoe
3.测试:
为了测试成功,停掉主从服务
3.1登陆到代理主机上测试:
[root@lvs_172 logs]# mysql -uroot -p123456 -h188.188.1.188 -P8066
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 17738170
Server version: 5.1.45-mysql-amoeba-proxy-2.1.0-RC5 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> use ckl
Database changed
mysql> select * from qinglv;
+-----------+------+
| name | age |
+-----------+------+
| ckl | 26 |
| xiong | 24 |
| ckl | 26 |
| xiong | 24 |
| kangle | 0 |
| kangkang | 26 |
| xiaoxiong | 24 |
| haha | 33 |
| ceshi | 34 |
+-----------+------+
9 rows in set (0.01 sec)
mysql> insert into qinglv values(‘wukaka‘,30);
Query OK, 1 row affected (0.00 sec)
3.2 登陆到主服务器上查看:
[root@localhost tmp]# mysql -uroot -p123456 -h188.188.1.144
Logging to file ‘/tmp/mysql-op.log‘
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 38
Server version: 5.1.35-log Source distribution
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> use ckl
Database changed
mysql> select * from qinglv;
+-----------+------+
| name | age |
+-----------+------+
| ckl | 26 |
| xiong | 24 |
| ckl | 26 |
| xiong | 24 |
| kangle | 0 |
| kangkang | 26 |
| xiaoxiong | 24 |
| haha | 33 |
| ceshi | 34 |
| wukaka | 30 |
+-----------+------+
10 rows in set (0.00 sec)
已经有了新插入的数据
3.3 登陆到从上查看:
[root@ckl tmp]# mysql -uroot -p123456 -h188.188.1.175
Logging to file ‘/tmp/mysql-op.log‘
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1270
Server version: 5.1.35-log Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> use ckl
Database changed
mysql> select * from qinglv;
+-----------+------+
| name | age |
+-----------+------+
| ckl | 26 |
| xiong | 24 |
| ckl | 26 |
| xiong | 24 |
| kangle | 0 |
| kangkang | 26 |
| xiaoxiong | 24 |
| haha | 33 |
| ceshi | 34 |
+-----------+------+
9 rows in set (0.00 sec)
没有新插入的数据
3.4 启动从服务器:
[root@ckl tmp]# mysql -uroot -p123456 -h188.188.1.175
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
3.5 在amoeba上插入数据:
[root@lvs_172 logs]# mysql -uroot -p123456 -h188.188.1.188 -P8066
mysql> insert into qinglv values(‘heixiu‘,28);
Query OK, 1 row affected (0.00 sec)
3.6 在从服务器上查看:
[root@ckl tmp]# mysql -uroot -p123456 -h188.188.1.175
mysql> select * from qinglv;
+-----------+------+
| name | age |
+-----------+------+
| ckl | 26 |
| xiong | 24 |
| ckl | 26 |
| xiong | 24 |
| kangle | 0 |
| kangkang | 26 |
| xiaoxiong | 24 |
| haha | 33 |
| ceshi | 34 |
| wukaka | 30 |
| heixiu | 28 |
+-----------+------+
11 rows in set (0.00 sec)
已经看到数据。
阅读(0)| 评论(0) | 编辑 |删除 |推送 |置顶
本文出自 “运维菜鸟” 博客,请务必保留此出处http://ckl893.blog.51cto.com/8827818/1682261
mysql Amoeba 配置
标签:mysql amoeba