【Mysql】One-proxy简单搭建

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 简单读写分离
  1. [chenliang@hostnfsd oneproxy]$ more demo.sh
  2. #/bin/bash
  3. #
  4. export ONEPROXY_HOME=/usr/local/oneproxy

  5. # valgrind --leak-check=full \

  6. ${ONEPROXY_HOME}/bin/oneproxy --keepalive \
  7. --proxy-address=192.168.1.6:3308 \                                                 ####mysql交互端口
  8. --admin-address=192.168.1.6:4041 \                                                 ####管理端口
  9. --proxy-master-addresses=192.168.1.6:3307@group1 \                                 ####real mysql 
  10. --proxy-slave-addresses=192.168.1.56:3307@group1 \                                 ####real mysql
  11. --proxy-user-list=testuser/950434F7872CB57A600E1B2B7237766FA7E95460@testbak \      #####用户以及对应的默认数据库,该用户需提前在db中建好,密码登录管理端口passwd '密码'  生成,这一步可第二次添加
  12. --proxy-group-policy=group1:Read-balance \                                         #####组策略,很多种,具体可看文档
  13. --proxy-charset=utf8_chinese_ci \
  14. --log-file=${ONEPROXY_HOME}/oneproxy.log \
  15. --pid-file=${ONEPROXY_HOME}/oneproxy.pid

(6与56只是名义上的主从,实际没搭建呢,只是为了测试读写分别从哪个ip)


读写分离

  1. 插入数据:[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    |
    +------+------+

  2. 成功插入主库

读负载均衡测试:

  1. [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 |
    +------+
  2. 读负载均衡,均衡分发至每个库




多用户:
  1. [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 |



---待续,先做个笔记

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29096438/viewspace-2071595/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29096438/viewspace-2071595/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值