怎样实现Mycat读写分离与负载均衡,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。我们来学习读写分离与负载均衡
先看一下balance 属性
负载均衡类型,目前的取值有3种:
1. balance=”0″,不开启读写分离机制,所有读操作都发送到当前可用的writeHost上。
2. balance=”1″,全部的readHost与stand by writeHost参与select语句的负载均衡,简单的说,当双主双从模式(M1->S1,M2->S2,并且M1与M2互为主备),正常情况下,M2,S1,S2都参与select语句的负载均衡。
3. balance=”2″,所有读操作都随机的在writeHost、readhost上分发。
4. balance=”3″,所有读请求随机的分发到wiriterHost对应的readhost执行,writerHost不负担读压力,注意balance=3只在1.4及其以后版本有,1.3没有。
writeType属性
-
负载均衡类型,目前的取值有3种:
-
1.writeType=”0″,所有写操作发送到配置的第一个writeHost,第一个挂了切到还生存的第二个writeHost,重新启动后已切换后的为准,切换记录在配置文件中:dnindex.properties.
-
2.writeType=”1″,所有写操作都随机的发送到配置的writeHost。
-
3.writeType=”2″,没实现。
所以我们根据第二种方式做负载均衡
-
-
-
-
-
writeType=”0″ dbType=”mysql” dbDriver=”native” switchType=”1″ slaveThreshold=”100″>
-
select user() -
-
-
password=”ESBecs00″>
-
-
-
-
-
password=”ESBecs00″>
-
-
-
-
-
-
writeType=”0″ dbType=”mysql” dbDriver=”native” switchType=”1″ slaveThreshold=”100″>
-
select user() -
-
-
password=”ESBecs00″>
-
-
-
-
-
password=”ESBecs00″>
-
-
-
-
-
writeType=”0″ dbType=”mysql” dbDriver=”native” switchType=”1开发云主机域名” slaveThreshold=”100″>
-
select user() -
-
-
password=”ESBecs00″>
-
-
-
-
-
password=”ESBecs00″>
-
-
-
#!/usr/bin/bash
for((i=1;ido
mysql -uroot -p123456 -P8066 -h227.0.0.1 -e “select name from company” TESTDB;
done -
root@localhost logs]# sort test-blance.log |more |uniq -c
-
30 this is 119
17 this is 119:3307
28 this is 120
23 this is 120:3307
36 this is 121
26 this is 121:3307
如上:6台机器全部都有读到,读负载均衡成功
负载均衡类型,目前的取值有3种:
1.writeType=”0″,所有写操作发送到配置的第一个writeHost,第一个挂了切到还生存的第二个writeHost,重新启动后已切换后的为准,切换记录在配置文件中:dnindex.properties.
2.writeType=”1″,所有写操作都随机的发送到配置的writeHost。
3.writeType=”2″,没实现。
writeType=”0″ dbType=”mysql” dbDriver=”native” switchType=”1″ slaveThreshold=”100″>
password=”ESBecs00″>
password=”ESBecs00″>
writeType=”0″ dbType=”mysql” dbDriver=”native” switchType=”1″ slaveThreshold=”100″>
password=”ESBecs00″>
password=”ESBecs00″>
writeType=”0″ dbType=”mysql” dbDriver=”native” switchType=”1″ slaveThreshold=”100″>
password=”ESBecs00″>
password=”ESBecs00″>
#!/usr/bin/bash
for((i=1;ido
mysql -uroot -p123456 -P8066 -h227.0.0.1 -e “select name from company” TESTDB;
done
root@localhost logs]# sort test-blance.log |more |uniq -c
30 this is 119
17 this is 119:3307
28 this is 120
23 this is 120:3307
36 this is 121
26 this is 121:3307看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注开发云行业资讯频道,感谢您对开发云的支持。
这篇文章主要介绍了OpenBSD WEB应用案例,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。 1、升级系统#cd /usr/src#cvs -d anoncvs@anoncvs.ca.ope…
免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。