mysql读写分离
mysql读写分离基于360中间件Atlas-2.2.1
配置mysql读写分离
===============================================================
主从配置 主上
修改主配置文件
[mysqld]
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
#主从复制配置
innodb_flush_log_at_trx_commit=1
sync_binlog=1
#需要备份的数据库
binlog-do-db=test
#不需要备份的数据库
binlog-ignore-db=mysql
#启动二进制文件
log-bin=mysql-bin
#服务器ID
server-id=1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
【主意:若没有配置binlog-do-db和binlog_ignore_db,表示备份全部数据库。】
主上:
grant replaction slave on *.* to "slave1"ip"%" identified by “xxxx1234”
flush privileges;
show master status; #获取log_file和log_pos
从上:
change master to master_host='主ip',master_user='slave1',master_password='xxxx1234',master_log_file='mysql-bin.000019',master_log_pos=2565376;
start slave;
show slave status \G;
================================================================
中间件配置
安装Atlas-2.2.1
wget https://github.com/Qihoo360/Atlas/releases/download/2.2.1/Atlas-2.2.1.el6.x86_64.rpm
rpm -ivh Atlas-2.2.1.el6.x86_64.rpm
cd /usr/local/mysql-proxy/
./encrypt 123456 #生成密文密码
配置 test.cnf
#管理接口的用户名
admin-username = user
#管理接口的密码
admin-password = pwd
#Atlas后端连接的MySQL主库的IP和端口,可设置多项,用逗号分隔
proxy-backend-addresses = 127.0.0.1:3306
#Atlas后端连接的MySQL从库的IP和端口,@后面的数字代表权重,用来作负载均衡,若省略则默认为1,可设置多项,用逗号分隔
proxy-read-only-backend-addresses = 127.0.0.1:3306@1
#用户名与其对应的加密过的MySQL密码,密码使用PREFIX/bin目录下的加密程序encrypt加密,下行的user1和user2为示例,将其替换为你的MySQL的用户名和加密密码!
pwds = buck:RePBqJ+5gI4=
#Atlas监听的工作接口IP和端口
proxy-address = 0.0.0.0:1234
#Atlas监听的管理接口IP和端口
admin-address = 0.0.0.0:2345
启动Atlas
[root@localhost bin]# ./mysql-proxyd test start
OK: MySQL-Proxy of test is started
连接到管理账户
mysql -h127.0.0.1 -P2345 -uuser -ppwd
select * from help;
连接到工作账户
mysql -h127.0.0.1 -P1234 -ubuck -phello
读写分离测试
1.安装Jmeter
mysql-proxy