• amoeba 读写分离、负载均衡


    1、amoeba配置文件

    1.1 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="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">root</property>
            </factoryConfig>
            <!-- 定义连接池 -->
            <poolConfig class="com.meidusa.toolkit.common.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>
    
        <!-- 配置数据库  parent集成上面的公共配置类-->
        <dbServer name="master"  parent="abstractServer">
            <factoryConfig>
                <!-- mysql ip -->
                <property name="ipAddress">192.168.174.139</property>
            </factoryConfig>
        </dbServer>
        
        <dbServer name="slave"  parent="abstractServer">
            <factoryConfig>
                <!-- mysql ip -->
                <property name="ipAddress">192.168.174.138</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">slave,master,slave</property>
            </poolConfig>
        </dbServer>
            
    </amoeba:dbServers>

    1.2编辑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.mysql.server.MySQLService">
                <!-- port 端口号 和项目中的properties中的端口号一致 -->
                <property name="port">8066</property>
                
                <!-- bind ipAddress 设置具体哪些ip能连接amoeba -->
                <!-- 
                <property name="ipAddress">127.0.0.1</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="authenticateProvider">
                    <bean class="com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator">
                        <!-- 定义连接amoeba的用户名和密码 -->
                        <property name="user">root</property>
                        
                        <property name="password">root</property>
                        
                        <property name="filter">
                            <bean class="com.meidusa.toolkit.net.authenticate.server.IPAccessController">
                                <property name="ipFile">${amoeba.home}/conf/access_list.conf</property>
                            </bean>
                        </property>
                    </bean>
                </property>
                
            </service>
            
            <runtime class="com.meidusa.amoeba.mysql.context.MysqlRuntimeContext">
                
                <!-- proxy server client process thread size -->
                <property name="executeThreadSize">128</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="defaultManager" class="com.meidusa.toolkit.net.MultiConnectionManagerWrapper">
                <property name="subManagerClassName">com.meidusa.toolkit.net.AuthingableConnectionManager</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">multiPool</property>
            
            <!-- writePool 写操作连接的库 对应dbservers.xml文件里面的name -->
            <!-- readPool 读操作连接的数据库 对应dbservers.xml文件里面的name-->
            <property name="writePool">master</property>
            <property name="readPool">multiPool</property>
            
            <property name="needParse">true</property>
        </queryRouter>
    </amoeba:configuration>

    1.3配置JVM

    找到JVM.properties,并找到下面的参数

    JVM_OPTIONS="-server -Xms256m -Xmx1024m -Xss256k -XX:PermSize=16m -XX:MaxPermSize=96m"
    -Xms256m  :jvm初始化内存大小
    -Xmx1024m  :jvm最大的内存空间
    -Xss    :单个线程大小,在amoeba中最小为217
  • 相关阅读:
    bootstrap-datetimepicker使用记录
    Highcharts使用====一些问题记录
    值类型 引用类型
    java 发送邮件
    包括post,get请求(http,https)的HttpClientUtils
    整理的java的日期DateUtil
    oracle随机取数据
    oracle查询表的索引
    有关dwr推送的笔记
    java 超经漂亮验证码
  • 原文地址:https://www.cnblogs.com/gxlaqj/p/11577902.html
Copyright © 2020-2023  润新知