Amoeba实现MySQL数据库读写分离
一 环境以及软件版本:
系统:CentOS Linux release 7.2.1511 (Core)
mysql:Server version: 5.6.33
Amoeba:amoeba-mysql-3.0.5-RC-distribution
JDK:1.7.0_80-b15 (Amoeba的运行需要jdk)
二 安装Amoeba:
1 下载好所需软件:
# ls amoeba-mysql-3.0.5-RC-distribution.zip jdk-7u80-linux-x64.rpm
2 安装jdk
# yum -y install jdk-7u80-linux-x64.rpm # java -version java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
3 解压Amoeba
# unzip amoeba-mysql-3.0.5-RC-distribution.zip # mv amoeba-mysql-3.0.5-RC /usr/local/amoeba # mv amoeba-mysql-3.0.5-RC /usr/local/amoeba # cd /usr/local/amoeba/conf/ # vim amoeba.xml <property name="port">3306</property> #设置amoeba监听的端口,默认是8066 <property name="ipAddress">10.0.0.159</property> #设置amoeba监听的ip地址 <property name="user">root</property> #设置连接amoeba的用户 <property name="password">123456</property> #设置连接amoeba的密码 #(这里的账号密码和amoeba连接后端数据库服务器的密码无关) <property name="defaultPool">master</property> #设置amoeba默认的池,这里设置为matster #这两个选项默认是注销掉的,需要取消注释,这里用来指定写库和读库 <property name="writePool">master</property> <property name="readPool">multiPool</property> #这给的是一个组,如果这个组里有多个dbServers则可以负载均衡,此组在 dbServers.xml中设置
设置mysql库的信息,在当前目录下的dbServers.xml文件里
四 启动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,测试时我暂停了主从同步,以便更直接的看出效果
# mysql -uroot -p123456 -h10.0.0.159
主库上新增一条数据
从库上加入一条数据
回到mysql连接的客户端验证:
只能查看从库的数据,说明基本成功,进一步验证,在客户端插入一条数据
并且客户端在从库上没有查询到新插入的数据,回到主库确认下:
到此验证成功,开启主从同步即可实现读写分离(开始同步前,请自行清理掉有差异的数据,以便主从能正常运行)
相关推荐
IBMRational 2020-01-28
vitasfly 2016-05-22
lifeison 2019-05-08
lglovejava 2016-10-12
mysql00 2014-08-02
cnzou 2014-08-02
kuwoyinlehe 2014-07-25
小树不倒我不倒 2013-11-28
frank0 2008-10-14
wensonlee 2018-03-30
tufeiax 2017-08-13
zhangjunguo00 2016-10-17
wangshuangbao 2016-08-08
xkorey 2016-05-01
lapiggy 2015-02-16
lulujaylulu 2014-01-14