实验系统:CentOS 6.6_x86_64
实验前提:防火墙和selinux都关闭
实验说明:本实验共有4台主机,IP分配如拓扑
实验软件:mariadb-10.0.20 oneproxy-rhel5-linux64-v5.6-ga
下载地址:http://pan.baidu.com/s/1jGpL2o2
实验拓扑:
注意:本实验是之前mysql-proxy实验的拓展,因此大部分环境及设定是相同的,其中一、二步这里不再重复,具体请参考:利用mysql-proxy进行mysql数据库的读写分离
一、准备工作
二、配置主从复制
三、安装oneproxy
1.此实验中19.79为onproxy服务器,所以软件安装在此主机上:
tar xf oneproxy-rhel5-linux64-v5.6-ga.tar.gz -C /usr/local/ cd /usr/local/oneproxy vim demo.sh ----------------------------------------------------------------> #/bin/bash # export ONEPROXY_HOME=/usr/local/oneproxy # valgrind --leak-check=full --show-reachable=yes ${ONEPROXY_HOME}/oneproxy --keepalive //自动检查和重起OneProxy服务 --proxy-address=192.168.19.79:3306 //Proxy Server第一个监听地址
--admin-address=192.168.19.79:4041 //管理端口地址
--proxy-master-addresses=192.168.19.66:3306@server1 //Master节点地址(可写入节点),其中@后面是“Server Group”的名字,如果不指定,则默认为“default” --proxy-slave-addresses=192.168.19.74:3306@server1 //Slave节点地址(可读取节点) --proxy-slave-addresses=192.168.19.76:3306@server1 --proxy-user-list=test/14B1772BA9874974E6ECEA0745EE774930E2EFA3 //Proxy用户列表(用户名/口令),进行完第2步之后回来配置 --proxy-part-tables=${ONEPROXY_HOME}/part.txt
--proxy-found-rows --event-threads=4 //OneProxy的工作线程数
--proxy-group-policy=server1:2 //定义MySQL集群的路由访问策略,这里配置的是从Slave读取,如果Slave端不可用,则从Master端读取
--proxy-group-security=server1:0 //定义MySQL集群的安全访问策略 --proxy-memory-db=root/@::test
--proxy-memory-engine --proxy-sql-autosave=${ONEPROXY_HOME}/sql_firewall.sql --log-file=${ONEPROXY_HOME}/oneproxy.log --pid-file=${ONEPROXY_HOME}/oneproxy.pid
2.查看密码字符并配置:
chmod +x demo.sh ./demo.sh mysql -uadmin -pOneProxy -h192.168.19.79 --port=4041 //进入管理接口 --------------------------------------------------------------------> passwd 'redhat'; //查看密码字符,并写入demo.sh中 +--------+------------------------------------------+ | TEXT | PASSWORD | +--------+------------------------------------------+ | redhat | 14B1772BA9874974E6ECEA0745EE774930E2EFA3 | +--------+------------------------------------------+
3.在master上创建测试用户:
/usr/local/mysql/bin/mysql -----------------------------------------------> GRANT ALL ON *.* TO 'test'@'192.168.19.%' IDENTIFIED BY 'redhat'; //这里要和demo.sh中的Proxy用户列表信息保持一致 FLUSH PRIVILEGES;
4.回到oneproxy服务器启动进程:
killall -9 oneproxy //先清理掉之前的进程 ./demo.sh tail -f oneproxy.log //查看日志
mysql -uadmin -pOneProxy -h192.168.19.79 --port=4041 -----------------------------------------------------------------> LIST BACKEND; +------+--------------------+-----------+--------+--------+----------+--------+---------+------+------+-------+---------+-------+---------+-------+---------+------+------+---------+ | INDX | ADDRESS | TYPE | STATUS | MARKUP | REQUESTS | DEGREE | GROUP | IS_M | IS_S | MFile | MOffset | DFile | DOffset | RFile | ROffset | IO | SQL | Seconds | +------+--------------------+-----------+--------+--------+----------+--------+---------+------+------+-------+---------+-------+---------+-------+---------+------+------+---------+ | 1 | 127.0.0.1:3306 | RW/Master | UP | 0 | 0 | 0 | | No | No | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | | 2 | 192.168.19.66:3306 | RW/Master | UP | 1 | 0 | 0 | server1 | No | No | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | | 3 | 192.168.19.74:3306 | RO/Slave | UP | 1 | 0 | 0 | server1 | No | No | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | | 4 | 192.168.19.76:3306 | RO/Slave | UP | 1 | 0 | 0 | server1 | No | No | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | +------+--------------------+-----------+--------+--------+----------+--------+---------+------+------+-------+---------+-------+---------+-------+---------+------+------+---------+
5.分别在三台mariadb服务器上抓包:
master:
tcpdump -i eth0 -nn -XX ip dst 192.168.19.66 and tcp dst port 3306
slave1:
tcpdump -i eth0 -nn -XX ip dst 192.168.19.74 and tcp dst port 3306
slave2:
tcpdump -i eth0 -nn -XX ip dst 192.168.19.76 and tcp dst port 3306
6.在oneproxy上进行数据库创建及读取:
mysql -utest -predhat -h192.168.19.79 //连接到oneproxy
数据库命令这里不再写出,大家可以从图片可以看出,所有写操作都在master上进行,读操作被负载均衡至slave上。