amoeba 实现读写分离(借鉴)
1.准备三台服务器 我的是centos7版本的
做MySQL的主从状态 可以参考
https://www.cnblogs.com/chenxiaodou/articles/11993283.html
在MySQL的主从的服务器上给amoeba服务器授权一个可以操作读写的用户
1
2
|
grant all on *.* to 'amoeba' @ '192.168.18.%' identified by '123' ; flush privileges; |
在Amoeba的服务器上安装Amoeba
1.安装jdk版本 要安装1.6的版本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
将JDK的二进制包安装在此路径下 cd /usr/local 给予权限 chmod +x jdk-6u14-linux-x64.bin 在当前路径下开始执行 ./ jdk-6u14-linux-x64.bin 一直按回车 直到遇见让你输入 yes or no 输入 yes 即可回车 更改jdk安装目录的名字 mv jdk1.6.0_14 jdk1.6 修改环境变量 在末尾加入以下内容 vim /etc/profile ------------------------------------------------------------ export AMOEBA= /usr/local/amoeba export JAVA_HOME= /usr/local/jdk1 .6 export PATH=$PATH:$JAVA_HOME /bin :$AMOEBA /bin ------------------------------------------------------------ 使增加的变量生效 source /etc/profile |
下载Ameoba的安装包
1
2
|
cd /usr/local wget http: //nchc .dl.sourceforge.net /project/amoeba/Amoeba %20for%20mysql /2 .x /amoeba-mysql-binary-2 .1.0-RC5. tar .gz |
为Amoeba创建安装目录
1
2
3
4
5
6
|
mkdir /usr/local/amoeba cd /usr/local/amoeba 在当前路径下下载amoeba wget http: //nchc .dl.sourceforge.net /project/amoeba/Amoeba %20for%20mysql /2 .x /amoeba-mysql-binary-2 .1.0-RC5. tar .gz 解压Ameoba的安装包 tar -zxf amoeba-mysql-binary-2.1.0-RC5. tar .gz |
配置文件dbServers.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
cd /usr/local/ameoba/conf vim dbServers.xml ----------------------------------------------------------------------------------------- …… <!-- mysql port --> <property name= "port" >3306< /property > <!-- mysql schema --> <property name= "schema" > test < /property > <!-- mysql user --> <property name= "user" >amoeba< /property > //MySQL 主从中给予权限的用户 <!-- mysql password--> <property name= "password" >123< /property > //MySQL 主从中给予权限的用户的密码 …… <dbServer name= "server1" parent= "abstractServer" > <factoryConfig> <!-- mysql ip --> <property name= "ipAddress" >192.168.18.141< /property > //MySQL 主的IP地址 < /factoryConfig > < /dbServer > <dbServer name= "server2" parent= "abstractServer" > <factoryConfig> <!-- mysql ip --> <property name= "ipAddress" >192.168.18.142< /property > //MySQL 从的IP地址 < /factoryConfig > < /dbServer > <dbServer name= "slave" virtual= "true" > <poolConfig class= "com.meidusa.amoeba.server.MultipleServerPool" > <!-- Load balancing strategy: 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 > |
编辑ameoba,.xml文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
cd /usr/local/ameoba/conf vim ameoba.xml ---------------------------------------------------------------------------------- …… <property name= "authenticator" > <bean class= "com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator" > <property name= "user" >jave< /property > <property name= "password" >123< /property > <property name= "filter" > <bean class= "com.meidusa.amoeba.server.IPAccessController" > <property name= "ipFile" >${amoeba.home} /conf/access_list .conf< /property > < /bean > < /property > < /bean > < /property > …… <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" >server1< /property > <property name= "writePool" >server1< /property > <property name= "readPool" >slave< /property > <property name= "needParse" > true < /property > < /queryRouter > -------------------------------------------------------------------------------- |
启动amoeba
1
2
|
cd /usr/local/amoeba/bin . /amoeba start 出现以下字样 |
表示启动成功
把Amoeba的终端再开启一台
关闭防火墙 SELinux 安装数据库
1
2
3
|
systemctl stop firewalld setenforce 0 yum -y install mariadb mariadb-server |
登录amoeba测试读写分离效果
1
2
3
4
5
6
7
|
mysql -ujave -p123 -h192.168.189.167 -P8066 create database ceshi charset utf8; 可以在MySQL主从数据库中查看是否存在这个数据库 在从的MySQL数据库中停掉从的同步 stop slave; 在amoeba的服务器上再创建一个数据库 这时再分别去主从数据库上查看 只有主的可以看到刚刚创建的数据库 而从上看不到 这样就实现了读写分离 |