设为首页 收藏本站
查看: 376|回复: 0

[经验分享] amoeba搭建及读写分离测试

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-1-16 08:19:42 | 显示全部楼层 |阅读模式
mysql主库服务器--192.168.107.16
[iyunv@master ~]# cat /etc/my.cnf
[mysqld]
server-id=1
log-bin=mysql-bin
log=/tmp/mysql.log
character-set-server=utf8

mysqladmin -u root -p 123456
mysql -uroot root -p123456
grant all on *.* to test_user@'%' identified by '1234';

mysql从库服务器--192.168.107.17
[iyunv@slave1 ~]# cat /etc/my.cnf
[mysqld]
server-id=2
log-bin=mysql-bin
log=/tmp/mysql.log
character-set-server=utf8

mysqladmin -u root -p 123456
mysql -uroot root -p123456
grant all on *.* to test_user@'%' identified by '1234';

show master status
stop slave;
change master to master_host='192.168.107.16', master_user='repl_user', master_password='copy', master_log_file='mysql-bin.000001', master_log_pos=106;#注意IP、master_log_file、master_log_pos必须跟主库一样
start slave;
show slave status\G确保Slave_IO_Running: Yes和Slave_SQL_Running: Yes方为正常。

amoeba配置--192.168.107.10
下载amoeba-mysql-binary-2.2.0.tar.gz
mkdir /usr/local/amoeba
tar zxvf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba
cd /usr/local/amoeba/conf

1、[iyunv@localhost conf]# cat 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">  
            <!-- Amoeba 端口号 -->  
            <property name="port">8066</property>  
              
            <!-- bind ipAddress -->  
            <!--  
            <property name="ipAddress">0.0.0.0</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">  
                    <!-- Amoeba 账号,密码 -->  
                    <property name="user">root</property>  
                     
                    <property name="password">root</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">master</property>  
         
        <!-- 写数据库 -->  
        <property name="writePool">master</property>  
        <!-- 读数据库,dbServer.xml 中配置的 虚拟数据库,数据库池 -->  
        <property name="readPool">slave1</property>  
         
        <property name="needParse">true</property>  
    </queryRouter>  
</amoeba:configuration>

2、[iyunv@localhost conf]# cat dbServers.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">  
            <!-- Amoeba 端口号 -->  
            <property name="port">8066</property>  
              
            <!-- bind ipAddress -->  
            <!--  
            <property name="ipAddress">0.0.0.0</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">  
                    <!-- Amoeba 账号,密码 -->  
                    <property name="user">root</property>  
                     
                    <property name="password">root</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">master</property>  
         
        <!-- 写数据库 -->  
        <property name="writePool">master</property>  
        <!-- 读数据库,dbServer.xml 中配置的 虚拟数据库,数据库池 -->  
        <property name="readPool">slave1</property>  
         
        <property name="needParse">true</property>  
    </queryRouter>  
</amoeba:configuration>  
[iyunv@localhost conf]# cat 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">test_user</property>
            
            <!--  mysql password -->
            <property name="password">1234</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="testOnReturn">true</property>
            <property name="testWhileIdle">true</property>
        </poolConfig>
    </dbServer>

    <dbServer name="master"  parent="abstractServer">
        <factoryConfig>
            <!-- mysql ip -->
            <property name="ipAddress">192.168.107.16</property>
        </factoryConfig>
    </dbServer>
   
    <dbServer name="slave1"  parent="abstractServer">
        <factoryConfig>
            <!-- mysql ip -->
            <property name="ipAddress">192.168.107.17</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">master,slave1</property>
        </poolConfig>
    </dbServer>
        
</amoeba:dbServers>

3、[iyunv@localhost conf]# cat rule.xml
<?xml version="1.0" encoding="gbk"?>  
<!DOCTYPE amoeba:rule SYSTEM "rule.dtd">  
  
<amoeba:rule xmlns:amoeba="http://amoeba.meidusa.com/">  
    <tableRule name="message" schema="test" defaultPools="master">  
    </tableRule>  
</amoeba:rule>  

4、修改/usr/local/amoeba/bin/amoeba把DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss128k"改为DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss256k"
启动/usr/local/amoeba/bin/amoeba start &
netstat -tunlp|grep amoeba查看是否有8066和另一个端口存在。

5、测试mysql -uroot -proot -h192.168.107.10 --port 8066若显示以下信息一般即为正常
[iyunv@localhost conf]# mysql -uroot -proot -h192.168.107.10 --port 8066
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 498117230
Server version: 5.1.45-mysql-amoeba-proxy-2.2.0 Source distribution

Copyright (c) 2000, 2012, 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>

6、amoeba执行创建数据库和插入、更新、删除、查询等操作,master和slave1服务器均开启日志跟踪
master上的日志:
tail -f /tmp/mysql.log
150104 23:54:36      373 Init DB    abc
          373 Query    set names latin1
          373 Query    show databases
          373 Query    show tables
150104 23:54:50      373 Query    show tables
150104 23:57:00      373 Query    describe mytable
150104 23:58:08      373 Query    insert into mytable values ('brian','male','1982-12-29')
150104 23:58:15      373 Query    describe mytable
150105  0:00:12      373 Query    delete from mytable where name='brian'
150105  0:01:55      373 Query    insert into mytable values ('brian','male','1982-12-29')
150105  0:02:08      373 Query    insert into mytable values ('bin','female','1985-12-29')
150105  0:02:43      374 Connect    test_user@192.168.107.10 on test
150105  0:02:55      374 Query    set names latin1
          374 Query    update mytable set sex='f' where name='brian'
150105  0:03:17      374 Init DB    abc
          374 Query    show databases
          374 Query    show tables
150105  0:03:22      374 Query    update mytable set sex='f' where name='brian'
150105  0:05:46      374 Query    alter mytable drop brian
150105  0:05:54      374 Query    alter table mytable drop brian
150105  0:06:44      374 Query    alter table mytable drop name

slave1上的日志:
150104 23:55:02       84 Init DB    abc
           84 Query    select * from mytable
150104 23:55:30       85 Connect    root@localhost on
           85 Query    select @@version_comment limit 1
150104 23:55:42       85 Query    grant all on *.* to test_user@'%' identified by '1234'
150104 23:55:46       85 Quit   
150104 23:56:40       84 Query    select @@version_comment limit 1
150104 23:58:08        8 Query    insert into mytable values ('brian','male','1982-12-29')
150104 23:58:26       84 Query    select * from mytable
150105  0:00:12        8 Query    delete from mytable where name='brian'
150105  0:00:14       84 Query    select * from mytable
150105  0:01:55        8 Query    insert into mytable values ('brian','male','1982-12-29')
150105  0:02:08        8 Query    insert into mytable values ('bin','female','1985-12-29')
150105  0:02:43       86 Connect    test_user@192.168.107.10 on test
150105  0:03:17       86 Query    set names latin1
           86 Query    SELECT DATABASE()
150105  0:03:22        8 Query    update mytable set sex='f' where name='brian'
150105  0:03:45       86 Init DB    abc
           86 Query    select * from mytable
150105  0:06:44        8 Query    alter table mytable drop name
可以看出所有的select查询操作均在slave1执行,而其他创建更新修改操作均在master上操作(slave1上有同样记录是因为从库同步了主库的数据)

搭建成功。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-40879-1-1.html 上篇帖子: MySQL主库复制中Slave_SQL_Running_State参数详解 下篇帖子: MySQL主从复制
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表