vim dbServers.xml <!-- mysql port --> #设置amoeba连接后端mysql的端口 <property name="port">3306</property>
<!-- mysql schema --> #设置缺省的数据库,当连接amoeba时,操作表必须显式的指定数据库名,即采用dbname.tablename的方式,不支持 use dbname指定缺省库,因为操作会调度到各个后端dbserver <property name="schema">test</property>
<!-- mysql user --> #设置amoeba连接后端mysql的用户名和密码 <property name="user">amoeba</property>
<property name="password">123456</property>
<dbServer name="master" parent="abstractServer">#设置一个后端的dbServer,这里设置连接可写的master库,此名字可自定义,但要和amoeba.xml中调用的名字一致即可。 <factoryConfig> <!-- mysql ip --> #后端mysql的ip地址 <property name="ipAddress">10.0.0.176</property> </factoryConfig> </dbServer>
<dbServer name="slave" parent="abstractServer"> #设置一个后端的dbServer,这里设置连接可读的salve,此名字可自定义,但要和amoeba.xml中调用的名字一致即可。 <factoryConfig> <!-- mysql ip --> #后端mysql的ip地址 <property name="ipAddress">10.0.0.193</property> </factoryConfig> </dbServer>
<!-- Separated by commas,such as: server1,server2,server1 --> <property name="poolNames">slave</property> #组成员,当有多个时用逗号分隔 </poolConfig> </dbServer> 三 mysql授权amoeba用户登录(此处我的两台mysql服务器master和slave已经做好了主从同步,并且已经验证成功,需要做主从同步请看https://blog.51cto.com/zengzeyang/1911173) master上授权: mysql> grant select,insert,update,delete on . to 'amoeba'@'10.0.0.%' identified by '123456'; mysql> flush privileges; slave上授权: mysql> grant select on . to 'amoeba'@'10.0.0.%' identified by '123456'; mysql> flush privileges; 注意:此处授权的用户密码要和dbServers.xml中配置的一致。如果你的mysql开启所有库主从同步则你在主上授权的用户会同步到从库,解决方法是:1在从库上降权;2主从同步时不让mysql库同步
四 启动amoeba: #cd /usr/local/amoeba/bin
vim launcher 添加JAVA_HOME: JAVA_HOME=/usr/java/jdk1.7.0_80
# cd /usr/local/amoeba/ # vim jvm.properties 修改VM_OPTIONS: JVM_OPTIONS="-server -Xms1024m -Xmx1024m -Xss256k -XX:PermSize=16m -XX:MaxPermSize=96m"
# /usr/local/amoeba/bin/launcher 2018-01-02 23:34:21 [INFO] Project Name=Amoeba-MySQL, PID=48981 , starting... log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml 2018-01-02 23:34:22,152 INFO context.MysqlRuntimeContext - Amoeba for Mysql current versoin=5.1.45- mysql-amoeba-proxy-3.0.4-BETA log4j:WARN ip access config load completed from file:/usr/local/amoeba/conf/access_list.conf 2018-01-02 23:34:22,520 INFO net.ServerableConnectionManager - Server listening on /10.0.0.159:3306. #启动成功
# ss -tanlp LISTE 128 ::ffff:10.0.0.159:3306 :::* 五 测试:用另外的mysql客户端连接amoeba,测试时我暂停了主从同步,以便更直接的看出效果