环境规划
Amoeba读写分离器 | 172.16.254.144/16 |
Mysql服务器(master) | 172.16.254.150/16 |
Mysql服务器(slave) | 172.16.254.151/16 |
一、先实现mysql主从复制,在master上使用yum安装mysql
[[email protected] mysql]# yum -y install mysql mysql-server
启用二进制日志,编辑/etc/my.cnf在[mysqld]下添加如下行:
log-bin = /var/lib/mysql/mysql-bin-log binlog_format=mixed server_id = 1
重启mysqld,连接mysql,授权远程复制账户
mysql> grant replication slave, replication client on *.* to ‘repluser‘@‘172.16.%.%‘ identified by ‘mypass‘;
查看当前正在使用的二进制日志文件及位置
在slave上启用中继日志及修改server_id,编辑/etc/my.cnf在[mysqld]下添加如下行:
relay-log = /var/lib/mysql/relay-bin server_id = 11
连接master服务器,并启动复制功能
mysql> change master to master_host=‘172.16.254.150‘, master_user=‘repluser‘,master_password=‘mypass‘,master_log_file=‘mysql-bin-log.000002‘,master_log_pos=106; mysql> start slave;
查看Slave_IO、Slave_SQL线程是否为yes
二、安装配置Amoeba
安装配置jdk
[[email protected] ~]chmod +x ./jdk-6u31-linux-x64-rpm.bin [[email protected] ~]./jdk-6u31-linux-x64-rpm.bin [[email protected] ~]# vim /etc/profile.d/java.sh 添加如下行: export JAVA_HOME=/usr/java/latest export PATH=$JAVA_HOME/bin:$PATH [[email protected] ~]# . /etc/profile.d/java.sh
安装Amoeba
[[email protected] ~]# mkdir /usr/local/amoeba [[email protected] ~]# tar xf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba/ [[email protected] ~]# cd /usr/local/amoeba/ [[email protected] ~]# bin/amoeba start
安装mysql客户端,验证是否能够连接
[[email protected] ~]# yum -y install mysql [[email protected] ~]# mysql -uroot -h172.16.254.144 -P8066 -p
编辑/usr/local/amoeba/conf/amoeba.xml主配置文件
编辑/usr/local/amoeba/conf/dbServers.xml配置文件,定义master和readservers
启动amoeba使其运行在后台,连接amoeba,使用tcpdump在master、slave服务器上抓包,创建一个数据库,并多使用几次查询语句,验证写操作是否被调度至master(172.16.254.150),而读操作会以轮叫的方式调度至master和slave,可以分摊mysql的读请求
[[email protected] mysql]# tcpdump -i eth0 -nn -XX ip dst host 172.16.254.150 and tcp dst port 3306 [[email protected] mysql]# tcpdump -i eth0 -nn -XX ip dst host 172.16.254.151 and tcp dst port 3306
Amoeba实现Mysql读写分离,布布扣,bubuko.com
时间: 2024-12-05 06:27:53