1 下载
官网: http://www.onexsoft.cn/software/step_into_oneproxy.pdf
2 安装
机器有限,oneproxy就安装在192.168.1.6上
192.168.1.6--主---oneproxy
192.168.1.56---从
3 简单读写分离
多用户:
---待续,先做个笔记
官网: http://www.onexsoft.cn/software/step_into_oneproxy.pdf
2 安装
机器有限,oneproxy就安装在192.168.1.6上
192.168.1.6--主---oneproxy
192.168.1.56---从
3 简单读写分离
- [chenliang@hostnfsd oneproxy]$ more demo.sh
- #/bin/bash
- #
- export ONEPROXY_HOME=/usr/local/oneproxy
-
- # valgrind --leak-check=full \
-
- ${ONEPROXY_HOME}/bin/oneproxy --keepalive \
- --proxy-address=192.168.1.6:3308 \ ####mysql交互端口
- --admin-address=192.168.1.6:4041 \ ####管理端口
- --proxy-master-addresses=192.168.1.6:3307@group1 \ ####real mysql
- --proxy-slave-addresses=192.168.1.56:3307@group1 \ ####real mysql
- --proxy-user-list=testuser/950434F7872CB57A600E1B2B7237766FA7E95460@testbak \ #####用户以及对应的默认数据库,该用户需提前在db中建好,密码登录管理端口passwd '密码' 生成,这一步可第二次添加
- --proxy-group-policy=group1:Read-balance \ #####组策略,很多种,具体可看文档
- --proxy-charset=utf8_chinese_ci \
- --log-file=${ONEPROXY_HOME}/oneproxy.log \
- --pid-file=${ONEPROXY_HOME}/oneproxy.pid
(6与56只是名义上的主从,实际没搭建呢,只是为了测试读写分别从哪个ip)
读写分离
- 插入数据:[chenliang@hostnfsd oneproxy]$ mysql -utestuser -ptestuser -h192.168.1.6 --port=3308 -e "insert into test2(id) values(4)" testbak;
Warning: Using a password on the command line interface can be insecure.
[chenliang@hostnfsd oneproxy]$ mysql -utestuser -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" testbak;
Warning: Using a password on the command line interface can be insecure.
+------+------+
| id | name |
+------+------+
| 1 | NULL |
| 2 | NULL |
| 3 | 4 |
+------+------+ - 成功插入主库
读负载均衡测试:
- [chenliang@hostnfsd oneproxy]$ mysql -utestuser -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1;
Warning: Using a password on the command line interface can be insecure.
+------+------+
| id | name |
+------+------+
| 1 | NULL |
| 2 | NULL |
| 3 | 4 |
+------+------+
[chenliang@hostnfsd oneproxy]$ mysql -utestuser -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1;
Warning: Using a password on the command line interface can be insecure.
+------+
| id |
+------+
| 1 |
| 2 |
+------+
[chenliang@hostnfsd oneproxy]$ mysql -utestuser -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1;
Warning: Using a password on the command line interface can be insecure.
+------+------+
| id | name |
+------+------+
| 1 | NULL |
| 2 | NULL |
| 3 | 4 |
+------+------+
[chenliang@hostnfsd oneproxy]$ mysql -utestuser -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1;
Warning: Using a password on the command line interface can be insecure.
+------+
| id |
+------+
| 1 |
| 2 |
+------+ - 读负载均衡,均衡分发至每个库
多用户:
- [root@hostnfsd :/usr/local/oneproxy]$ vi demo.sh
#/bin/bash
#
export ONEPROXY_HOME=/usr/local/oneproxy
# valgrind --leak-check=full \
${ONEPROXY_HOME}/bin/oneproxy --keepalive \
--proxy-address=192.168.1.6:3308 \
--admin-address=192.168.1.6:4041 \
--proxy-master-addresses=192.168.1.6:3307@group1 \
--proxy-slave-addresses=192.168.1.56:3307@group1 \
--proxy-user-list=testuser/950434F7872CB57A600E1B2B7237766FA7E95460@testbak \
--proxy-user-list=jonn/950434F7872CB57A600E1B2B7237766FA7E95460@testbak2 \ ---就这不同,用户指定默认数据库不一样罢了
--proxy-group-policy=group1:Read-balance \
--proxy-charset=utf8_chinese_ci \
--log-file=${ONEPROXY_HOME}/oneproxy.log \
--pid-file=${ONEPROXY_HOME}/oneproxy.pid
测试:
[root@hostnfsd :/root]$ mysql -ujonn -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1 ---读写分离
Warning: Using a password on the command line interface can be insecure.
+------+
| id |
+------+
| 106 |
+------+
[root@hostnfsd :/root]$ mysql -ujonn -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1
Warning: Using a password on the command line interface can be insecure.
+------+
| id |
+------+
| 56 |
+------+
[root@hostnfsd :/root]$ mysql -ujonn -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1
Warning: Using a password on the command line interface can be insecure.
+------+
| id |
+------+
| 106 |
+------+
[root@hostnfsd :/root]$ mysql -ujonn -ptestuser -h192.168.1.6 --port=3308 -e "insert into test2 values(111)" group1 ---插入主库
Warning: Using a password on the command line interface can be insecure.
[root@hostnfsd :/root]$ mysql -ujonn -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1
Warning: Using a password on the command line interface can be insecure.
+------+
| id |
+------+
| 56 |
+------+
[root@hostnfsd :/root]$ mysql -ujonn -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1
Warning: Using a password on the command line interface can be insecure.
+------+
| id |
+------+
| 106 |
| 111 |
+------+
[root@hostnfsd :/root]$ mysql -ujonn -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1
Warning: Using a password on the command line interface can be insecure.
+------+
| id |
+------+
| 56 |
+------+
[root@hostnfsd :/root]$ mysql -ujonn -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1
Warning: Using a password on the command line interface can be insecure.
+------+
| id |
+------+
| 106 |
| 111 |
[root@hostnfsd :/root]$ mysql -ujonn -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1 ---读写分离
Warning: Using a password on the command line interface can be insecure.
+------+
| id |
+------+
| 106 |
+------+
[root@hostnfsd :/root]$ mysql -ujonn -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1
Warning: Using a password on the command line interface can be insecure.
+------+
| id |
+------+
| 56 |
+------+
[root@hostnfsd :/root]$ mysql -ujonn -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1
Warning: Using a password on the command line interface can be insecure.
+------+
| id |
+------+
| 106 |
+------+
[root@hostnfsd :/root]$ mysql -ujonn -ptestuser -h192.168.1.6 --port=3308 -e "insert into test2 values(111)" group1 ---插入主库
Warning: Using a password on the command line interface can be insecure.
[root@hostnfsd :/root]$ mysql -ujonn -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1
Warning: Using a password on the command line interface can be insecure.
+------+
| id |
+------+
| 56 |
+------+
[root@hostnfsd :/root]$ mysql -ujonn -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1
Warning: Using a password on the command line interface can be insecure.
+------+
| id |
+------+
| 106 |
| 111 |
+------+
[root@hostnfsd :/root]$ mysql -ujonn -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1
Warning: Using a password on the command line interface can be insecure.
+------+
| id |
+------+
| 56 |
+------+
[root@hostnfsd :/root]$ mysql -ujonn -ptestuser -h192.168.1.6 --port=3308 -e "select * from test2" group1
Warning: Using a password on the command line interface can be insecure.
+------+
| id |
+------+
| 106 |
| 111 |
---待续,先做个笔记
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29096438/viewspace-2071595/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29096438/viewspace-2071595/