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
- [root@localhost conf]# vi amoeba.xml
- <?xml version="1.0" encoding="gbk"?>
- <proxy>
- <!-- service class must implements com.meidusa.amoeba.service.Service -->
- <!-- port -->
- <property name="port">8066</property>
- <!-- bind ipAddress -->
- <!--
- <property name="ipAddress">192.168.3.70</property>
- -->
- <property name="manager">${clientConnectioneManager}</property>
- <property name="connectionFactory">
- <bean class="com.meidusa.amoeba.mysql.net.MysqlClientConnectionFactory">
- <property name="sendBufferSize">128</property>
- </property>
- <property name="authenticator">
- <bean class="com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator">
- <property name="user">zw</property>
- <property name="password">123456</property>
- <property name="filter">
- </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>
- </service>
- <!-- 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>
- <!--
- -->
- <connectionManagerList>
- <!--
- default value is avaliable Processors
- <property name="processors">5</property>
- -->
- </connectionManager>
- <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">WritePool</property>
- <property name="writePool">WritePool</property>
- <property name="readPool">ReadPool</property>
- <property name="needParse">true</property>
- </queryRouter>
- </amoeba:configuration>
- [root@localhost conf]# vi 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,
- 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">zw</property>
- <property name="password">123456</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="testWhileIdle">true</property>
- </poolConfig>
- </dbServer>
- <dbServer name="server1" parent="abstractServer">
- <factoryConfig>
- <!-- mysql ip -->
- <property name="ipAddress">192.168.3.161</property>
- </factoryConfig>
- </dbServer>
- <dbServer name="server2" parent="abstractServer">
- <factoryConfig>
- <!-- mysql ip -->
- <property name="ipAddress">192.168.3.162</property>
- </factoryConfig>
- </dbServer>
- <dbServer name="WritePool" virtual="true">
- <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">
- <!-- Load balancing strate
- gy: 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->
- <property name="loadbalance">1</property>
- <!-- Separated by commas,such as: server1,server2,server1 -->
- <property name="poolNames">server1</property>
- </poolConfig>
- </dbServer>
- <dbServer name="ReadPool" virtual="true">
- <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">
- <!-- Load balancing strate
- gy: 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->
- <property name="loadbalance">1</property>
- <!-- Separated by commas,such as: server1,server2,server1 -->
- <property name="poolNames">server2</property>
- </poolConfig>
- </dbServer>
- </amoeba:dbServers>