加入收藏 | 设为首页 | 会员中心 | 我要投稿 51站长网 (https://www.51zhanzhang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
站内搜索:
当前位置: 首页 > 站长学院 > MySql教程 > 正文

Mysql中如何创建oneproxy

发布时间:2021-12-18 13:53:58 所属栏目:MySql教程 来源:互联网
导读:小编给大家分享一下Mysql中如何搭建oneproxy,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧! 1 下载 2 安装 机器有限,oneproxy就安装在192.168.1.6上 192.168.1.6--主---on
小编给大家分享一下Mysql中如何搭建oneproxy,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
 
1 下载
 
2 安装
机器有限,oneproxy就安装在192.168.1.6上
192.168.1.6--主---oneproxy
192.168.1.56---从
 
3 简单读写分离
 
插入数据:[chenliang@hostnfsd oneproxy]$ mysql -utestuser -ptestuser -h292.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 -h292.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 -h292.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 -h292.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 -h292.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 -h292.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 -h292.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 -h292.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 -h292.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 -h292.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 -h292.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 -h292.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 -h292.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 -h292.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 |
以上是“Mysql中如何搭建oneproxy”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

(编辑:ASP站长)

【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

    相关内容
    未处理完善
      无相关信息
    未处理完善