Amoeba实现MySQL主从读写分离(2)

继续上面的操作
 
        <dbServer>
 
             <!-- PoolableObjectFactory实现类 -->
               <factoryConfighttps://www.linuxidc.com/topicnews.aspx?tid=21" target="_blank" title="MySQL">MySQL.net.MysqlServerConnectionFactory">
                   <property>defaultManager</property>
 
                     <!-- 真实mysql数据库端口 -->
                       <property>3306</property>
 
                      <!-- 真实mysql数据库IP -->
                        <property>10.10.0.77</property>
                         <property>test</property>
 
                         <!-- 用于登陆mysql的用户名 -->
                          <property>test</property>
 
                         <!-- 用于登陆mysql的密码 -->
 
                           <property>123456</property>
 
             </factoryConfig>
 
            <!-- ObjectPool实现类 -->
              <poolConfig>
                   <property>200</property>
                   <property>200</property>
                    <property>10</property>
                     <property>600000</property>
                          <property>600000</property>
                             <property>true</property>
                             <property>true</property>
                        </poolConfig>
            </dbServer>
 
     <dbServer virtual="true">
             <poolConfig>
                      <!-- 负载均衡参数 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->
                         <property>1</property>
 
                       <!-- 参与该pool负载均衡的poolName列表以逗号分割 -->
                          <property>server1</property>
              </poolConfig>
       </dbServer>
       <dbServer virtual="true">
            <poolConfig>
                 <!-- 负载均衡参数 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->
                       <property>1</property>
 
                  <!-- 参与该pool负载均衡的poolName列表以逗号分割 -->
                        property>server1,server2</property>
               </poolConfig>
        </dbServer>
 
 
        </dbServerList>
 
<queryRouter>
             <property>${amoeba.home}/conf/rule.xml</property>
              <property>${amoeba.home}/conf/functionMap.xml</property>
      <property>${amoeba.home}/conf/ruleFunctionMap.xml</property>
               <property>1500</property>
               <property>master</property>
                <property>master</property>
                <property>slave</property>
                <property>true</property>
        </queryRouter>
</amoeba:configuration>
 
 # /usr/local/amoeba/bin/amoeba &   //启动amoeba服务
 
# ps aux |grep  /usr/local/amoeba
root      9116  0.0  1.0 460460 43028 pts/0    Sl   12:50   0:00 /usr/Java/jdk1.5.0_16/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
 
# netstat -lntpu |grep 8066
tcp        0      0 10.10.0.87:8066         :::*      
看到进程以及端口说明amoeba服务启动正常
测试mysql的读写分离
测试之前先要保证amoeba-server有访问两个主从服务器test库的权限,在主从mysql上都执行:
mysql>  grant all on test.* to test@'10.10.0.%' identified by '123456';
mysql>  flush privileges;
 
登录amoeba服务器使用如下命令(用户名密码和上面配置的要一致):
#  mysql -u root -psxit -h10.10.0.87  -P8066  //如果可以登陆并且没有任何错误就说
                                               明是OK的.
 
登录上去后,为了测试读和写必须先把mysql的主从复制停掉,才能更清楚地看出读写的服务器是哪台,在从上使用stop slave;登录到amoeba-mysql上,使用命令mysql -uroot -psxit -h10.10.0.87  -P8066,然后执行写和读操作,查看写的是哪台服务器,读的是哪台服务器,实验结果显示:写只在主上进行,读在主和从都进行,比率是1:1
 
在没有停止同步之前先在master服务器上创建一个表
mysql>  create table sxit (id int(10) ,name varchar(10));

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wywzps.html