您好,登錄后才能下訂單哦!
怎樣實(shí)現(xiàn)Mycat讀寫(xiě)分離與負(fù)載均衡,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。
我們來(lái)學(xué)習(xí)讀寫(xiě)分離與負(fù)載均衡
先看一下balance 屬性
負(fù)載均衡類(lèi)型,目前的取值有3種:
1. balance="0", 不開(kāi)啟讀寫(xiě)分離機(jī)制,所有讀操作都發(fā)送到當(dāng)前可用的writeHost上。
2. balance="1",全部的readHost與stand by writeHost參與select語(yǔ)句的負(fù)載均衡,簡(jiǎn)單的說(shuō),當(dāng)雙主雙從模式(M1->S1,M2->S2,并且M1與 M2互為主備),正常情況下,M2,S1,S2都參與select語(yǔ)句的負(fù)載均衡。
3. balance="2",所有讀操作都隨機(jī)的在writeHost、readhost上分發(fā)。
4. balance="3",所有讀請(qǐng)求隨機(jī)的分發(fā)到wiriterHost對(duì)應(yīng)的readhost執(zhí)行,writerHost不負(fù)擔(dān)讀壓力,注意balance=3只在1.4及其以后版本有,1.3沒(méi)有。
負(fù)載均衡類(lèi)型,目前的取值有3種:
1. writeType="0", 所有寫(xiě)操作發(fā)送到配置的第一個(gè)writeHost,第一個(gè)掛了切到還生存的第二個(gè)writeHost,重新啟動(dòng)后已切換后的為準(zhǔn),切換記錄在配置文件中:dnindex.properties .
2. writeType="1",所有寫(xiě)操作都隨機(jī)的發(fā)送到配置的writeHost。
3. writeType="2",沒(méi)實(shí)現(xiàn)。 <dataNode name="dn1" dataHost="localhost1" database="examdb" />
<dataNode name="dn2" dataHost="localhost2" database="examdb" />
<dataNode name="dn3" dataHost="localhost3" database="examdb" />
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="2"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="hostM1" url="192.168.6.121:3306" user="root"
password="ESBecs00">
<!-- can have multi read hosts -->
</writeHost>
<writeHost host="hostS1" url="192.168.6.121:3307" user="root"
password="ESBecs00">
<!-- can have multi read hosts -->
</writeHost>
</dataHost>
<dataHost name="localhost2" maxCon="1000" minCon="10" balance="2"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="hostM1" url="192.168.6.120:3306" user="root"
password="ESBecs00">
<!-- can have multi read hosts -->
</writeHost>
<writeHost host="hostS1" url="192.168.6.120:3307" user="root"
password="ESBecs00">
<!-- can have multi read hosts -->
</writeHost>
</dataHost>
<dataHost name="localhost3" maxCon="1000" minCon="10" balance="2"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="hostM1" url="192.168.6.119:3306" user="root"
password="ESBecs00">
<!-- can have multi read hosts -->
</writeHost>
<writeHost host="hostM1" url="192.168.6.119:3307" user="root"
password="ESBecs00">
<!-- can have multi read hosts -->
</writeHost>
</dataHost>
#!/usr/bin/bash
root@localhost logs]# sort test-blance.log |more |uniq -c
30 this is 119
writeType屬性
所以我們根據(jù)第二種方式做負(fù)載均衡
測(cè)試
如上:6臺(tái)機(jī)器全部都有讀到,讀負(fù)載均衡成功
for((i=1;i<=1000;i++))
do
mysql -uroot -p123456 -P8066 -h227.0.0.1 -e "select name from company" TESTDB;
done
17 this is 119:3307
28 this is 120
23 this is 120:3307
36 this is 121
26 this is 121:3307
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝您對(duì)億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。