mysql中间件-amoeba
中间件:⼀种提供在不同技术、不同的软件之间共享资源的程序,更⼤化了利⽤了数据库的性能,可以⽆限扩展(注:真实环境中并⾮如此)
数据库的中间件:
  mysql proxy (官⽅版本)性能低,需要lua 脚本
  atlas 性能低,响应时间长
  amoeba 陈思儒研发
⼀、先搭建⼀个主从关系的服务器
在主、从服务器上安装mysql mysql-server
1. 开启⼆进制⽇志
[root@localhost ~]# vim /etc/myf
...
log-bin=mysql-bin
server-id = 132
...
[root@localhost ~]# vim /etc/myf
...l
og-bin=mysql-bin
server-id = 134
...
2. 在主服务器上授权,从服务器上保存授权信息,并开启从服务线程
mysql> grant replication slave on *.* to root@'192.168.80.134' identified by '123456';
mysql> show master status;
mysql> change master to
-> master_user='root',
-> master_password='123456',
-> master_host='192.168.80.132',
-> master_log_file='mysql-bin.000008',
-> master_log_pos=260;
Query OK, 0 rows affected (0.35 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G;
⼆、配置读写分离
1. 安装 gcc 环境
[root@localhost ~]# yum -y install gcc*
2. 安装jdk
[root@localhost ~]# tar -zxvf /amoeba/
[root@localhost /amoeba]# ln -s jdk1.8.0_231/ jdk
[root@localhost /amoeba]# vim /etc/profile
JAVA_HOME=/amoeba/jdk
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
[root@localhost /amoeba]# source /etc/profile
3. 安装amoeba
[root@localhost ~]# wget jaist.dl.sourceforge/project/amoeba/Amoeba%20for%20mysql/3.x/amoeba-mysql-3.0.5-RC-distribution.zip
[root@localhost ~]# mkdir /amoeba
[root@localhost ~]# unzip amoeba-mysql-3.0.5-RC-distribution.zip -d /amoeba
4. 配置amoeba
amoeba 的配置⽂件位于安装⽬录下的conf⽬录中,实现读写分离功能,只需修改两个配置⽂件,l和l。[root@localhost /amoeba/amoeba-mysql-3.0.5-RC/conf]# l
<?xml version="1.0" encoding="gbk"?>
<!DOCTYPE amoeba:dbServers SYSTEM "dbserver.dtd">
<amoeba:dbServers xmlns:amoeba="idusa/">
<!--
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="sql.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">123456</property>  #登录使⽤的密码
</factoryConfig>
<poolConfig class="lkitmon.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="server1"  parent="abstractServer">    #改名字可任意命名,后续有⽤
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">192.168.80.132</property>  #数据库ip
</factoryConfig>
</dbServer>
<dbServer name="server2"  parent="abstractServer">
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">192.168.80.134</property>  #数据库ip
</factoryConfig>
</dbServer>
<dbServer name="write" virtual="true">    #定义⼀个dbserver 组名
<poolConfig class="idusa.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>  #write组成员
</poolConfig>
</dbServer>
<dbServer name="read" virtual="true">
<poolConfig class="idusa.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</property>
</poolConfig>
</dbServer>
</amoeba:dbServers>
[root@localhost /amoeba/amoeba-mysql-3.0.5-RC/conf]# l
<?xml version="1.0" encoding="gbk"?>
<!DOCTYPE amoeba:configuration SYSTEM "amoeba.dtd">
<amoeba:configuration xmlns:amoeba="idusa/">
<proxy>
<!-- service class must idusa.amoeba.service.Service -->
<service name="Amoeba for Mysql" class="sql.server.MySQLService">
<!-- port -->
<property name="port">8066</property>    #amoeba监听端⼝,默认8066
<!-- bind ipAddress -->
<property name="ipAddress">192.168.80.133</property>  #amoeba安装地址
<property name="connectionFactory">
<bean class="sql.MysqlClientConnectionFactory">
<property name="sendBufferSize">128</property>
<property name="receiveBufferSize">64</property>
</bean>
</property>
<property name="authenticateProvider">
<bean class="sql.server.MysqlClientAuthenticator">
<property name="user">root</property>  #设置客户端连接amoeba所需的⽤户名和密码
<property name="password">123456</property>
<property name="filter">
<bean class="lkit.authenticate.server.IPAccessController">
<property name="ipFile">${amoeba.home}/conf/f</property>
</bean>
</property>
</bean>
</property>
</service>
<runtime class="t.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="lkit.MultiConnectionManagerWrapper">            <property name="subManagerClassName"&lkit.AuthingableConnectionManager</property>        </connectionManager>
</connectionManagerList>
<!-- default using file loader -->
<dbServerLoader class="t.DBServerConfigFileLoader">
<property name="configFile">${amoeba.home}/l</property>
</dbServerLoader>
<queryRouter class="sql.parser.MysqlQueryRouter">
<property name="ruleLoader">
<bean class="ute.TableRuleFileLoader">
<property name="ruleFile">${amoeba.home}/l</property>
<property name="functionFile">${amoeba.home}/l</property>
</bean>
</property>
<property name="sqlFunctionFile">${amoeba.home}/l</property>
<property name="LRUMapSize">1500</property>
<property name="defaultPool">write</property>  #设置amoeba默认池
<property name="writePool">write</property>  #设置amoeba 写池,默认注释
<property name="readPool">read</property>   #设置amoeba读池,默认注释
<property name="needParse">true</property>
</queryRouter>
</amoeba:configuration>
5. 在主从服务器上授权
mysql>  grant all on *.* to 'root'@'192.168.80.133' identified by '123456';Query OK, 0 rows affected (0.00 sec)
6. 修改jvm.properties
[root@localhost /amoeba/amoeba-mysql-3.0.5-RC]# vim jvm.properties
JVM_OPTIONS="-server -Xms1024m -Xmx1024m -Xss256k -XX:PermSize=16m -XX:MaxPermSize=96m"
7. 启动
[root@localhost /amoeba/amoeba-mysql-3.0.5-RC]# nohup bash +x /amoeba/amoeba-mysql-3.0.5-RC/bin/launcher &
[root@localhost /amoeba/amoeba-mysql-3.0.5-RC]# tail -f nohup.out
2019-12-2418:34:02,897 INFO  context.MysqlRuntimeContext - Amoeba for Mysql current versoin=5.1.45-mysql-amoeba-proxy-3.0.4-BETA log4j:WARN ip access config load completed from file:/amoeba/amoeba-mysql-3.0.5-RC/conf/fmysql下载starting the server
2019-12-2418:34:03,331 INFO  net.ServerableConnectionManager - Server listening on /192.168.80.133:8066.
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=16m; support was removed in8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=96m; support was removed in8.0
2019-12-2418:59:15 [INFO] Project Name=Amoeba-MySQL, PID=7607 ,
log4j:WARN log4j config load completed from file:/amoeba/amoeba-mysql-3.0.5-RC/l
2019-12-2418:59:16,333 INFO  context.MysqlRuntimeContext - Amoeba for Mysql current versoin=5.1.45-mysql-amoeba-proxy-3.0.4-BETA log4j:WARN ip access config load completed from file:/amoeba/amoeba-mysql-3.0.5-RC/conf/f
2019-12-2418:59:16,669 INFO  net.ServerableConnectionManager - Server listening on /192.168.80.133:8066.
[root@localhost ~]# netstat -antp |grep8066
tcp6      00192.168.80.133:8066    :::*                    LISTEN      7607/java
[root@localhost ~]# firewall-cmd --zone=public --add-port=8066/tcp
[root@localhost ~]# firewall-cmd --zone=public --add-port=8066/tcp --permanent
8. 测试
[root@localhost ~]# mysql -uroot -p123456 -P8066 -h192.168.80.133
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 151281375
Server version: 5.1.45-mysql-amoeba-proxy-3.0.4-BETA Source distribution
Copyright (c) 2000, 2016, 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> use test;
Database changed
mysql> select * from ceshi2;
+--------+
| name  |
+--------+
| master |
| amoeba |
+--------+
2 rows in set (0.01 sec)
mysql> select * from ceshi2;
+--------+
| name  |
+--------+
| master |
| slave  |
| amoeba |
+--------+
3 rows in set (0.01 sec)
mysql> select * from ceshi2;
+--------+
| name  |
+--------+
| master |
| amoeba |
+--------+
2 rows in set (0.01 sec)
mysql> select * from ceshi2;
+--------+
| name  |
+--------+
| master |
| slave  |
| amoeba |
+--------+
3 rows in set (0.01 sec)
mysql> select * from ceshi2;
+--------+
| name  |
+--------+
| master |
| amoeba |
+--------+
2 rows in set (0.01 sec)
mysql> select * from ceshi2;
+--------+
| name  |
+--------+
| master |
| slave  |
| amoeba |
+--------+
3 rows in set (0.02 sec)
三、amoeba配置⽂件
主配置⽂件 $AMOEBA_HOME/l,⽤来配置Amoeba服务的基本参数,如Amoeba主机地址、端⼝、认证⽅式、⽤于连接的⽤户名、密码、线程数、超时时间、其他配置⽂件的位置等。
数据库服务配置⽂件 $AMOEBA_HOME/l,⽤来存储和配置Amoeba所代理的数据库服务器的信息,如:主机IP、端⼝、⽤户名、密码等。
切分规则配置⽂件 $AMOEBA_HOME/l,⽤来配置切分规则。
数据库函数配置⽂件 $AMOEBA_HOME/l,⽤来配置数据库函数的处理⽅法,Amoeba将使⽤该配置⽂件中的⽅法解析数据库函数。
切分规则函数配置⽂件 $AMOEBA_HOME/l,⽤来配置切分规则中使⽤的⽤户⾃定义函数的处理⽅法。
访问规则配置⽂件 $AMOEBA_HOME/conf/f,⽤来授权或禁⽌某些服务器IP访问Amoeba。
⽇志规格配置⽂件 $AMOEBA_HOME/l,⽤来配置Amoeba输出⽇志的级别和⽅式。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。