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>
<!--
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>
<!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>
<!--
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>
<!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
-->
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上有同样记录是因为从库同步了主库的数据)