RHEL6 MySQL5.7 Amoeba部署

Posted okchy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RHEL6 MySQL5.7 Amoeba部署相关的知识,希望对你有一定的参考价值。

Amoeba部署文档

一、环境说明

系统:Red Hat Enterprise Linux Server release 6.3

192.168.24.90 Amoeba

192.168.24.91 mysql5.7.25 主库

192.168.24.92 MySQL5.7.25 从库

主从replication配置完成

 技术图片

 

 

二、安装

3.1 配置授权用户

在主库中添加授权用户,通过mycat代理到主库服务器只能使用DML语句

grant select,insert,update,delete on *.* to ‘amoeba‘@‘%‘ identified by ‘password‘;

flush privileges;

 

从库中收回授权用户权限

Revoke insert,update,delete on *.* from ‘amoeba’@’%’;

flush privileges;

 

3.2 Amoeba服务器配置JDK

3.2.1 安装JDK1.7,JDK版本必须高于1.7

查看当前JDK版本:java -version

低于1.7查看当前安装RPM包详细信息:rpm -qa | grep java

rpm -e –-nodeps RPM包 #卸载目前javaRPM包

rpm -ivh jdk-1.7版本.rpm #安装jdk1.7版本RPM包

mkdir /usr/local/java

解压后的jdk文件夹移动到/usr/local/java

/etc/profile追加变量

export PATH=/usr/local/mysql/bin:$PATH

export JAVA_HOME=/usr/local/java/jdk1.7版本

export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH

检查java版本 java –version

 

3.2.2 配置amoeba

mkdir /usr/local/amoeba

将解压后的amoeba文件复制到/usr/local/amoeba中

/usr/local/amoeba/conf/amoeba.xml配置

注意:真实数据库中schema的库名必须存在

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

 

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

<amoeba:configuration xmlns:amoeba="http://amoeba.meidusa.com/">

 

         <server>

                   <!-- proxy server绑定的端口 -->

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

                  

                   <!-- proxy server绑定的IP -->

                    

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

                  

                   <!-- 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>

                  

                   <!-- socket Send and receive BufferSize(unit:K)  -->

                   <property name="netBufferSize">128</property>

                  

                   <!-- Enable/disable TCP_NODELAY (disable/enable Nagle‘s algorithm). -->

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

                  

                   <!-- 对外验证的用户名 -->

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

                  

                   <!-- 对外验证的密码 -->

                  

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

                  

                  

                   <!-- query timeout( default: 60 second , TimeUnit:second) -->

                   <property name="queryTimeout">60</property>

         </server>

        

         <!--

                   每个ConnectionManager都将作为一个线程启动。

                   manager负责Connection IO读写/死亡检测

         -->

         <connectionManagerList>

                   <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>

        

         <dbServerList>

                   <!--

                            一台mysqlServer 需要配置一个pool,

                            如果多台 平等的mysql需要进行loadBalance,

                            平台已经提供一个具有负载均衡能力的objectPool:com.meidusa.amoeba.mysql.server.MultipleServerPool

                            简单的配置是属性加上 virtual="true",该Pool 不允许配置factoryConfig

                            或者自己写一个ObjectPool。

                   -->

                   <dbServer name="server1">

                           

                            <!-- PoolableObjectFactory实现类 -->

                            <factoryConfig class="com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory">

                                     <property name="manager">defaultManager</property>

                                    

                                     <!-- 真实mysql数据库端口 -->

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

                                    

                                     <!-- 真实mysql数据库IP -->

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

                                     <property name="schema">test</property>

                                    

                                     <!-- 用于登陆mysql的用户名 -->

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

                                    

                                     <!-- 用于登陆mysql的密码 -->

                                    

                                    

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

                           

                                    

                            </factoryConfig>

                           

                            <!-- ObjectPool实现类 -->

                            <poolConfig class="com.meidusa.amoeba.net.poolable.PoolableObjectPool">

                                     <property name="maxActive">200</property>

                                     <property name="maxIdle">200</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">

                           

                            <!-- PoolableObjectFactory实现类 -->

                            <factoryConfig class="com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory">

                                     <property name="manager">defaultManager</property>

                                    

                                     <!-- 真实mysql数据库端口 -->

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

                                    

                                     <!-- 真实mysql数据库IP -->

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

                                     <property name="schema">test</property>

                                    

                                     <!-- 用于登陆mysql的用户名 -->

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

                                    

                                     <!-- 用于登陆mysql的密码 -->

                                    

                                    

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

                           

                                    

                            </factoryConfig>

                           

                            <!-- ObjectPool实现类 -->

                            <poolConfig class="com.meidusa.amoeba.net.poolable.PoolableObjectPool">

                                     <property name="maxActive">200</property>

                                     <property name="maxIdle">200</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="master" virtual="true">

                            <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">

                                     <!-- 负载均衡参数 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->

                                     <property name="loadbalance">1</property>

                                    

                                     <!-- 参与该pool负载均衡的poolName列表以逗号分割 -->

                                     <property name="poolNames">server1</property>

                            </poolConfig>

                   </dbServer>

                   <dbServer name="slave" virtual="true">

                            <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">

                                     <!-- 负载均衡参数 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->

                                     <property name="loadbalance">1</property>

                                    

                                     <!-- 参与该pool负载均衡的poolName列表以逗号分割 -->

                                     <property name="poolNames">server2</property>

                            </poolConfig>

                   </dbServer>

         </dbServerList>

        

         <queryRouter class="com.meidusa.amoeba.mysql.parser.MysqlQueryRouter">

                   <property name="ruleConfig">${amoeba.home}/conf/rule.xml</property>

                   <property name="functionConfig">${amoeba.home}/conf/functionMap.xml</property>

                   <property name="ruleFunctionConfig">${amoeba.home}/conf/ruleFunctionMap.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>

 

3.2.3启动前准备

编辑usr/local/amoeba/bin/amoeba修改DEFAULT_OPTS行

DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss256k"

chmod 700 -R /usr/local/amoeba/bin/

 

3.3 启动Amoeba

/usr/local/amoeba/bin/amoeba&

 

三、验证

从库运行

mysql -uroot -ppassword -h192.168.24.90 -P8066 进入Amoeba代理服务器

select sleep(10);

分别在主库和从库执行show processlist查看线程

192.168.24.91 没有select线程

192.168.24.92 有select线程

实现主从读写分离功能

以上是关于RHEL6 MySQL5.7 Amoeba部署的主要内容,如果未能解决你的问题,请参考以下文章

一分钟完成MySQL5.7安装部署

二进制部署MySQL5.7

MySql5.7绿色版服务端安装部署教程

利用ansible的playbook在centos7上批量部署Mysql5.7或8.0

centos7环境下使用percona工具对mysql5.7进行多实例从库部署

MySql5.7 配置文件 my.cnf 设置