赞
踩
MySQL读写分离
一、配置读写分离
1、配置hosts文件
[root@centos01 ~]# vim /etc/hosts
192.168.100.10 centoss01
192.168.100.20 centoss02
192.168.100.30 centoss03
192.168.100.40 centoss04
192.168.100.50 centoss05
[root@centos01 ~]# scp /etc/hosts root@192.168.100.20:/etc/
[root@centos01 ~]# scp /etc/hosts root@192.168.100.30:/etc/
[root@centos01 ~]# scp /etc/hosts root@192.168.100.40:/etc/
[root@centos01 ~]# scp /etc/hosts root@192.168.100.50:/etc/
2、在主机amoeba上安装java环境
[root@centos05 ~]# cp /mnt/jdk-6u14-linux-x64.bin /usr/src/
[root@centos05 ~]# cd /usr/src/
[root@centos05 src]# sh jdk-6u14-linux-x64.bin
[root@centos05 src]# mv jdk1.6.0_14/ /usr/local/jdk
[root@centos05 ~]# vim /etc/profile.d/java
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=
C
L
A
S
S
P
A
T
H
:
CLASSPATH:
CLASSPATH:JAVA_HOME/bin:
J
A
V
A
H
O
M
E
/
j
r
e
/
l
i
b
e
x
p
o
r
t
P
A
T
H
=
JAVA_HOME/jre/lib export PATH=
JAVAHOME/jre/libexportPATH=JAVA_HOME/lib:
J
A
V
A
H
O
M
E
/
j
r
e
/
b
i
n
:
JAVA_HOME/jre/bin:
JAVAHOME/jre/bin:PATH:
H
O
M
E
/
b
i
n
e
x
p
o
r
t
A
M
O
E
B
A
H
O
M
E
=
/
u
s
r
/
l
o
c
a
l
/
a
m
o
e
b
a
e
x
p
o
r
t
P
A
T
H
=
HOME/bin export AMOEBA_HOME=/usr/local/amoeba export PATH=
HOME/binexportAMOEBAHOME=/usr/local/amoebaexportPATH=PATH:$AMOEBA_HOME/bin
[root@centos05 ~]# source /etc/profile.d/java
[root@centos05 ~]# java -version
java version “1.6.0_14”
Java™ SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot™ 64-Bit Server VM (build 14.0-b16, mixed mode)
3、配置读写分离
[root@centos05 ~]# mkdir /usr/local/amoeba
[root@centos05 ~]# tar zxvf /mnt/amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba/
配置amoeba访问账户和密码
[root@centos01 ~]# mysql -uroot -ppwd@123
mysql> grant all on . to ‘tom’@‘192.168.100.%’ identified by ‘pwd@123’;
Query OK, 0 rows affected (0.00 sec)
编辑amoeba.xml配置文件
[root@centos05 ~]# vim /usr/local/amoeba/conf/amoeba.xml
编辑dbServers.xml
[root@cenetos ~]# vim /usr/local/amoeba/conf/dbServers.xml
启动amoeba软件默认端口为tcp8066
root@centos05 ~]# /usr/local/amoeba/bin/amoeba start&
[2] 1817
[root@centos05 ~]# remote application= .Amoeba:53964 response OK
amoeba server is running with port=53964
[2]+ 退出 255 /usr/local/amoeba/bin/amoeba start
4、客户端测试
安装mysql
[root@centos06 ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos06 ~]# yum -y install mysql
通过代理访问mysql
[root@centos06 ~]# mysql -u amoeba -p -h 192.168.100.50 -P 8066
Enter password:
在master上创建一个数据库和表表格写入内容
MySQL [(none)]> create database bdqn;
Query OK, 1 row affected (0.01 sec)
MySQL [(none)]> use bdqn;
Database changed
MySQL [bdqn]> create table student(姓名 char(10),性别 char(3),年龄 char(5));
Query OK, 0 rows affected (0.08 sec)
MySQL [bdqn]> insert into student value (‘战三’,‘男’,‘39’);
Query OK, 1 row affected (0.05 sec)
在主服务器上查看表格数据
从服务器查看
在客户端上查看数据
从服务器停止slave服务
Amoeba上插入数据
主服务器查看
从服务器查看
客户端查看
启动从节点
从服务器查看
客户端查看
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。