MYSQL主从+amoeba读写分离(一)

1.首先介绍下我的实验环境。

 System:     CentOS 6.0
              Master mysql: 192.168.3.161
              Slave mysql:  192.168.3.162
              Amoeba server:192.168.3.69

2.主从的配置

主服务器上添加同步用户
grant replication slave,file on *.* to 'replication'@'192.168.1.162' identified by '123456';  注:上面IP地址为从服务器的IP地址

flush privileges;

####修改master的my.cnf的配置

log-bin=mysql-bin         #打开mysql二进制日志
server-id= 1          #设置mysql_id,主从不能相同
binlog-do-db=test          #设置二进制日志记录的库
binlog-ignore-db=mysql        ##设置二进制日志不记录的库
sync_binlog=1      

####修改slave的my.cnf的配置

log-bin=mysql-bin
server-id= 2
replicate-do-db=test       #设置同步的库
replicate-ignore-db=mysql     #设置不同步的库
log-slave-updates           #同步后记录二进制日志
slave-skip-errors=all     
sync_binlog=1
slave-net-timeout=60

分别重启主从mysqld服务,登录主mysql,在主上执行flush tables with read lock;后将test数据库的数据copy到从上,并记录下主上show master status\G的结果:

如:

mysql> show master status\G;

*************************** 1. row ***************************

            File: mysql-bin.000022

            Position: 1237

           Binlog_Do_DB: test

           Binlog_Ignore_DB: mysql

然后执行unlock tables
登录从mysql,在从上执行:

stop slave;

change master to master_host='192.168.1.161',master_user='replication',master_password='123456',master_log_file='mysql-bin.000022',master_log_pos=1237;

start slave;

show slave status\G;

如果出现下面的情况,说明主从同步已经成功!
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

3.Amoeba的配置安装

1)JDK环境的安装
下载jdk1.5或者更新版本,地址 http://java.sun.com/javase/downloads/index.jsp

我用的是:jdk-6u25-linux-i586-rpm.bin

在Amoeba server上执行

chmod 755 jdk-6u25-linux-i586-rpm.bin

./ jdk-6u25-linux-i586-rpm.bin

mv jdk1.6.0_25 /usr/local/jdk

添加变量

vim /etc/profile

启动#amoeba start   (stop)

检查#ps aux | grep amoeba       # netstat -lnp | grep java

 

 

添加如下内容:
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
#. /etc/ profile
查看jdk   #java -version
 
2)安装配置amoeba
# mkdir /usr/local/amoeba
# tar zxvf amoeba-mysql-binary-2.0.1-BETA.tar.gz -C /usr/local/amoeba/
主要改2个配置文件,配置文件路径 /usr/local/amoeba/conf/
amoeba.xml 
 
   
   
   
   
  1. [root@localhost conf]# vi amoeba.xml   
  2.  
  3. <?xml version="1.0" encoding="gbk"?>  
  4.         <proxy>  
  5.  
  6.                 <!-- service class must implements com.meidusa.amoeba.service.Service -->  
  7.                         <!-- port -->  
  8.                         <property name="port">8066</property>  
  9.  
  10.                         <!-- bind ipAddress -->  
  11.                         <!--  
  12.                         <property name="ipAddress">192.168.3.70</property>  
  13.                          -->  
  14.  
  15.                         <property name="manager">${clientConnectioneManager}</property>  
  16.  
  17.                         <property name="connectionFactory">  
  18.                                 <bean class="com.meidusa.amoeba.mysql.net.MysqlClientConnectionFactory">  
  19.                                         <property name="sendBufferSize">128</property>  
  20.                         </property>  
  21.  
  22.                         <property name="authenticator">  
  23.                                 <bean class="com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator">  
  24.  
  25.                                         <property name="user">zw</property>  
  26.  
  27.                                         <property name="password">123456</property>  
  28.  
  29.                                         <property name="filter">  
  30.                                                 </bean>  
  31.                                         </property>  
  32.                                 </bean>  
  33.                         </property>  
  34.  
  35.                 </service>  
  36.  
  37.                 <!-- server class must implements com.meidusa.amoeba.service.Service -->  
  38.                 <service name="Amoeba Monitor Server" class="com.meidusa.amoeba.monitor.MonitorServer">  
  39.                         <!-- port -->  
  40.                         <!--  default value: random number  
  41.                         <property name="port">9066</property>  
  42.                         -->  
  43.                         <!-- bind ipAddress -->  
  44.                         </property>  
  45.  
  46.                 </service>  
  47.  
  48.                         <!-- proxy server client process thread size -->  
  49.                         <property name="clientSideThreadPoolSize">30</property>  
  50.  
  51.                         <!-- mysql server data packet process thread size -->  
  52.                         <property name="serverSideThreadPoolSize">30</property>  
  53.  
  54.                         <!-- per connection cache prepared statement size  -->  
  55.                         <property name="statementCacheSize">500</property>  
  56.  
  57.                         <!-- query timeout( default: 60 second , TimeUnit:second) -->  
  58.                         <property name="queryTimeout">60</property>  
  59.                 </runtime>  
  60.  
  61.         </proxy>  
  62.  
  63.         <!--  
  64.         -->  
  65.         <connectionManagerList>  
  66.                         <!--  
  67.                           default value is avaliable Processors  
  68.                         <property name="processors">5</property>  
  69.                          -->  
  70.                 </connectionManager>  
  71.                         <property name="subManagerClassName">com.meidusa.amoeba.net.AuthingableConnectionManager</property>  
  72.  
  73.                         <!--  
  74.                           default value is avaliable Processors  
  75.                         <property name="processors">5</property>  
  76.                          -->  
  77.                 </connectionManager>  
  78.         </connectionManagerList>  
  79.  
  80.                 <!-- default using file loader -->  
  81.         <dbServerLoader class="com.meidusa.amoeba.context.DBServerConfigFileLoader">  
  82.                 <property name="configFile">${amoeba.home}/conf/dbServers.xml</property>  
  83.         </dbServerLoader>  
  84.  
  85.         <queryRouter class="com.meidusa.amoeba.mysql.parser.MysqlQueryRouter">  
  86.                 <property name="ruleLoader">  
  87.                         <bean class="com.meidusa.amoeba.route.TableRuleFileLoader">  
  88.                                 <property name="ruleFile">${amoeba.home}/conf/rule.xml</property>  
  89.                                 <property name="functionFile">${amoeba.home}/conf/ruleFunctionMap.xml</property>  
  90.                         </bean>  
  91.                 </property>  
  92.                 <property name="sqlFunctionFile">${amoeba.home}/conf/functionMap.xml</property>  
  93.                 <property name="LRUMapSize">1500</property>  
  94.                 <property name="defaultPool">WritePool</property>  
  95.  
  96.  
  97.                 <property name="writePool">WritePool</property>  
  98.                 <property name="readPool">ReadPool</property>  
  99.  
  100.                 <property name="needParse">true</property>  
  101.         </queryRouter>  
  102. </amoeba:configuration> 
  dbServer.xml
 
    
    
    
    
  1. [root@localhost conf]# vi dbServers.xml   
  2.  
  3. <?xml version="1.0" encoding="gbk"?>  
  4.  
  5. <!DOCTYPE amoeba:dbServers SYSTEM "dbserver.dtd">  
  6. <amoeba:dbServers xmlns:amoeba="http://amoeba.meidusa.com/">  
  7.  
  8.                 <!--  
  9.                         Each dbServer needs to be configured into a Pool,  
  10.                          such as 'multiPool' dbServer  
  11.                 -->  
  12.  
  13.         <dbServer name="abstractServer" abstractive="true">  
  14.                 <factoryConfig class="com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory">  
  15.                         <property name="manager">${defaultManager}</property>  
  16.                         <property name="sendBufferSize">64</property>  
  17.                         <property name="receiveBufferSize">128</property>  
  18.  
  19.                         <!-- mysql port -->  
  20.                         <property name="port">3306</property>  
  21.  
  22.                         <!-- mysql schema -->  
  23.                         <property name="schema">test</property>  
  24.  
  25.                         <!-- mysql user -->  
  26.                         <property name="user">zw</property>  
  27.  
  28.  
  29.                         <property name="password">123456</property>  
  30.  
  31.                 </factoryConfig>  
  32.  
  33.                 <poolConfig class="com.meidusa.amoeba.net.poolable.PoolableObjectPool">  
  34.                         <property name="maxActive">500</property>  
  35.                         <property name="maxIdle">500</property>  
  36.                         <property name="minIdle">10</property>  
  37.                         <property name="minEvictableIdleTimeMillis">600000</property>  
  38.                         <property name="timeBetweenEvictionRunsMillis">600000</property>  
  39.                         <property name="testOnBorrow">true</property>  
  40.                         <property name="testWhileIdle">true</property>  
  41.                 </poolConfig>  
  42.         </dbServer>  
  43.  
  44.         <dbServer name="server1"  parent="abstractServer">  
  45.                 <factoryConfig>  
  46.                         <!-- mysql ip -->  
  47.                         <property name="ipAddress">192.168.3.161</property>  
  48.                 </factoryConfig>  
  49.         </dbServer>  
  50.          <dbServer name="server2"  parent="abstractServer">  
  51.                 <factoryConfig>  
  52.                         <!-- mysql ip -->  
  53.                         <property name="ipAddress">192.168.3.162</property>  
  54.                 </factoryConfig>  
  55.         </dbServer>  
  56.  
  57. <dbServer name="WritePool" virtual="true">  
  58.                 <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">  
  59.                         <!-- Load balancing strate  
  60.  
  61.  
  62. gy: 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->  
  63.                         <property name="loadbalance">1</property>  
  64.  
  65.                         <!-- Separated by commas,such as: server1,server2,server1 -->  
  66.                         <property name="poolNames">server1</property>  
  67.                 </poolConfig>  
  68.         </dbServer>  
  69.  
  70.         <dbServer name="ReadPool" virtual="true">  
  71.                 <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">  
  72.                         <!-- Load balancing strate  
  73.  
  74.  
  75. gy: 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->  
  76.                         <property name="loadbalance">1</property>  
  77.  
  78.                         <!-- Separated by commas,such as: server1,server2,server1 -->  
  79.                         <property name="poolNames">server2</property>  
  80.                 </poolConfig>  
  81.         </dbServer>  
  82.  
  83. </amoeba:dbServers> 

你可能感兴趣的:(数据库,mysql,主从,休闲,amoeba)