MyCat瀹炵幇鏁版嵁搴撲笌鏁版嵁搴撲箣闂寸殑璇诲啓鍒嗙

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MyCat瀹炵幇鏁版嵁搴撲笌鏁版嵁搴撲箣闂寸殑璇诲啓鍒嗙相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%e5%88%b7%e6%96%b0' title='鍒锋柊'>鍒锋柊   har   杩涘埗   error   涓讳粠澶嶅埗   璇诲啓   names   鍚姩   .gz   

涓€銆丮ycat鐨勫畨瑁呭噯澶囷細

銆€銆€1銆乯dk锛氳姹?/span>jdk蹇呴』鏄?/span>1.7鍙婁互涓婄増鏈?/span>

銆€銆€2銆丮ysql锛氭帹鑽?/span>mysql鏄?/span>5.5浠ヤ笂鐗堟湰

銆€銆€3銆丮ycat锛?/span>

銆€銆€Mycat鐨勫畼鏂圭綉绔欙細

銆€銆€http://www.mycat.org.cn/

銆€銆€涓嬭浇鍦板潃锛?/p>

銆€銆€https://github.com/MyCATApache/Mycat-download

銆€銆€Mycat鐨勫畨瑁?/p>

銆€銆€Mycat鏈?/span>windows銆?/span>linux澶氱鐗堟湰銆傛湰鏁欑▼涓?/span>linux瀹夎姝ラ锛?/span>windows鍩烘湰鐩稿悓銆?/span>

銆€銆€绗竴姝ワ細涓嬭浇Mycat-server-xxxx-linux.tar.gz

銆€銆€绗簩姝ワ細灏嗗帇缂╁寘瑙e帇缂┿€傚缓璁皢mycat鏀惧埌/usr/local/mycat鐩綍涓嬨€?/span>

銆€銆€绗笁姝ワ細杩涘叆mycat鐩綍锛屽惎鍔?/span>mycat

銆€銆€銆€銆€銆€銆€./mycat start

銆€銆€銆€銆€銆€銆€鍋滄锛?/p>

銆€銆€銆€銆€銆€銆€./mycat stop

銆€銆€銆€銆€銆€銆€mycat 鏀寔鐨勫懡浠?/span>{ console | start | stop | restart | status | dump }

銆€銆€銆€銆€銆€銆€Mycat鐨勯粯璁ょ鍙e彿涓猴細8066

浜屻€丮ycat鐨勫垎鐗?/span>

銆€銆€涓ゅ彴mysql鏁版嵁搴撴湇鍔″櫒

銆€銆€Host1:192.168.37.101

銆€銆€Host2:192.168.37.102

銆€銆€host1鐜锛?/span>

銆€銆€鎿嶄綔绯荤粺鐗堟湰锛歝entos6.4

銆€銆€鏁版嵁搴撶増鏈細mysql-5.6

銆€銆€mycat鐗堟湰锛氾細1.4release锛堝彂琛岀増锛?/span>

銆€銆€鏁版嵁搴撳悕锛歞b1銆乨b3

 

銆€銆€mysql鑺傜偣2鐜锛?/span>銆€銆€

銆€銆€鎿嶄綔绯荤粺鐗堟湰 : centos6.4

 

銆€銆€鏁版嵁搴撶増鏈?/span> : mysql-5.6

 

銆€銆€mycat鐗堟湰 锛?/span>1.4 release

 

銆€銆€鏁版嵁搴撳悕 : db2

 

 

銆€銆€閰嶇疆閲嶈鏂囦欢Schema.xml

 銆€銆€ <schema name="mycatName" checkSQLschema="false" sqlMaxLimit="100">

                <!-- auto sharding by id (long) -->  id鑷姩鍒嗙墖鐨勮鍒?/p>

                <table name="tb_item" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" />

        </schema>

銆€銆€銆€缁檓ycat鍒涘缓涓櫄鎷熺殑鏁版嵁搴撳悕mycatName锛岀粰mycatName鍒涘缓鎸囧畾琛ㄥ悕锛屽拰db1銆乨b2銆乨b3琛ㄥ悕鐩稿悓鎵嶈兘杩涜鍒嗙墖銆€銆€

 

MyCat瀹夎鍒拌妭鐐?/span>1涓婏紙闇€瑕佸畨瑁?/span>jdk锛?/span>

 

 銆€銆€<dataNode name="dn1" dataHost="localhost1" database="db1" />

 

        <dataNode name="dn2" dataHost="localhost2" database="db2" />

 

        <dataNode name="dn3" dataHost="localhost1" database="db3" />

 

        <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"

 

                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.37.101:3306" user="root"

 

                        password="root">

 

                        <!-- can have multi read hosts -->

 

                </writeHost>

 

        </dataHost>

 

        <dataHost name="localhost2" maxCon="1000" minCon="10" balance="0"

 

                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.37.102:3306" user="root"

 

                        password="root">

 

                        <!-- can have multi read hosts -->

 

                </writeHost>

 

        </dataHost>

 

</mycat:schema>

 

schema.xml涓垹闄?lt;!--type="global"-->,涓嶅垹闄ょ殑璇濆垎鑺傜殑璇濅笁寮犺〃閮戒細鏈夌浉3鍚屾暟鎹?/p>

銆€銆€銆€閰嶇疆閲嶈鏂囦欢Server.xml

<user name="gaoxiansheng">

    <property name="password">123456</property>

    <property name="schemas">mycatName</property>

    <property name="readOnly">false</property>

</user>

銆€銆€銆€閰嶇疆閲嶈鏂囦欢rule.xml

涓夈€乵ycat璇诲啓鍒嗙锛?/span>

銆€銆€銆€銆€涓讳粠閰嶇疆闇€瑕佹敞鎰忕殑鍦版柟

銆€銆€銆€銆€1銆佷富DB server鍜屼粠DB server鏁版嵁搴撶殑鐗堟湰涓€鑷?/span>

銆€銆€銆€銆€2銆佷富DB server鍜屼粠DB server鏁版嵁搴撴暟鎹悕绉颁竴鑷?/span>

銆€銆€銆€銆€3銆佷富DB server寮€鍚簩杩涘埗鏃ュ織,涓?/span>DB server鍜屼粠DB server鐨?/span>server_id閮藉繀椤诲敮涓€


銆€銆€1.鎷疯礉my.cnf cp /usr/share/mysql/my-default.cnf /etc/
銆€銆€銆€鏀瑰悕 mv my-default.cnf my.cnf
銆€銆€銆€缂栬緫 vim my.cnf 鍔犲叆 lower_case_table_names=1 涓嶅尯鍒嗗ぇ灏忓啓
銆€銆€銆€閲嶅惎mysql service mysql restart
銆€銆€2.涓讳粠澶嶅埗锛氳鍐欙紝鍒犻櫎澧炲姞涓€鑷存€?br> 銆€銆€ 涓绘湇鍔″櫒閰嶇疆锛氾紙鍦?92.168.37.101涓婇厤缃級
銆€銆€绗竴姝ワ細鏇存敼/etc/my.cnf 鏂囦欢
銆€銆€銆€銆€銆€

binlog-do-db=db1

binlog-ignore-db=mysql

#鍚敤浜岃繘鍒舵棩蹇?/span>

log-bin=mysql-bin

#鏈嶅姟鍣ㄥ敮涓€ID锛屼竴鑸彇IP鏈€鍚庝竴娈?/span>

server-id=134

銆€
銆€銆€绗簩姝ワ細閲嶅惎mysql鏈嶅姟
銆€銆€銆€銆€銆€銆€service mysql restart
銆€銆€绗笁姝ワ細寤虹珛涓€涓敤鎴?br> 銆€銆€銆€銆€銆€銆€mysql>GRANT FILE ON *.* TO 鈥榖ackup鈥楡鈥?鈥?IDENTIFIED BY 鈥?23456鈥?
銆€銆€銆€銆€銆€銆€mysql>GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* to 鈥榖ackup鈥楡鈥?鈥?identified by 鈥?23456鈥?
銆€銆€鍒锋柊鏉冮檺
銆€銆€銆€銆€銆€銆€mysql> FLUSH PRIVILEGES;
銆€銆€鏌ョ湅mysql鐜板湪鏈夊摢浜涚敤鎴?br> 銆€銆€銆€銆€銆€銆€mysql>select user,host from mysql.user;

銆€銆€绗洓姝ワ細鏌ヨmaster鐨勭姸鎬?br> 銆€銆€銆€銆€銆€銆€mysql> show master status;
銆€銆€銆€銆€+------------------+----------+--------------+------------------+-------------------+
銆€銆€銆€銆€| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
銆€銆€銆€銆€+------------------+----------+--------------+------------------+-------------------+
銆€銆€銆€銆€| mysql-bin.000001 | 517| db1 | mysql | |
銆€銆€銆€銆€+------------------+----------+--------------+------------------+-------------------+
銆€銆€銆€銆€1 row in set
銆€銆€浠庢湇鍔″櫒閰嶇疆锛氾紙鍦?92.168.37.102涓婇厤缃級
銆€銆€绗竴姝ワ細
銆€銆€銆€銆€鍦ㄤ粠鏈嶅姟鍣℉adoop02涓婂鍒舵枃浠?br> 銆€銆€銆€銆€cp /usr/share/mysql/my-default.cnf /etc/
銆€銆€銆€銆€鏀瑰悕
銆€銆€銆€銆€mv my-default.cnf my.cnf
銆€銆€銆€銆€鏇存敼閰嶇疆vim /etc/my.cnf
銆€銆€銆€銆€server-id=106
銆€銆€绗簩姝ワ細閲嶅惎mysql鏈嶅姟
銆€銆€銆€銆€service mysql restart
銆€銆€绗笁姝ワ細閰嶇疆浠庢湇鍔″櫒
銆€銆€銆€銆€change master to master_host=鈥?92.168.37.101鈥?master_port=3306,master_user=鈥榖ackup鈥?master_password=鈥?23456鈥?master_log_file=鈥榤ysql-bin.000001鈥?master_log_pos=517
銆€銆€銆€銆€娉ㄦ剰璇彞涓棿涓嶈鏂紑锛宮aster_port涓簃ysql鏈嶅姟鍣ㄧ鍙e彿(鏃犲紩鍙?锛宮aster_user涓烘墽琛屽悓姝ユ搷浣滅殑鏁版嵁搴撹处鎴凤紝鈥?20鈥濇棤鍗曞紩鍙?姝ゅ鐨?20灏辨槸show master status 涓湅鍒扮殑position鐨勫€硷紝杩欓噷鐨勩€€mysql-bin.000001灏辨槸file瀵瑰簲鐨勫€?銆?/p>

銆€銆€绗洓姝ワ細鍚姩浠庢湇鍔″櫒澶嶅埗鍔熻兘
銆€銆€銆€銆€Mysql>start slave;

銆€銆€绗簲姝ワ細妫€鏌ヤ粠鏈嶅姟鍣ㄥ鍒跺姛鑳界姸鎬侊細
銆€銆€銆€銆€mysql> show slave status

銆€銆€銆€銆€鈥︹€︹€︹€︹€︹€︹€︹€?鐪佺暐閮ㄥ垎)
銆€銆€銆€銆€Slave_IO_Running: Yes //姝ょ姸鎬佸繀椤籝ES
銆€銆€銆€銆€Slave_SQL_Running: Yes //姝ょ姸鎬佸繀椤籝ES
銆€銆€銆€銆€鈥︹€︹€︹€︹€︹€︹€︹€?鐪佺暐閮ㄥ垎)

銆€銆€銆€銆€娉細Slave_IO鍙奡lave_SQL杩涚▼蹇呴』姝e父杩愯锛屽嵆YES鐘舵€侊紝鍚﹀垯閮芥槸閿欒鐨勭姸鎬?濡傦細鍏朵腑涓€涓狽O鍧囧睘閿欒)銆?/p>

銆€銆€銆€銆€閿欒澶勭悊锛?br> 銆€銆€銆€銆€濡傛灉鍑虹幇姝ら敊璇細
銆€銆€銆€銆€Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.
銆€銆€銆€銆€鍥犱负鏄痬ysql鏄厠闅嗙殑绯荤粺鎵€浠ysql鐨剈uid鏄竴鏍风殑锛屾墍浠ラ渶瑕佷慨鏀广€?br> 銆€銆€閰嶇疆mycat瀹炵幇璇诲啓鍒嗙锛?/span>

<dataNode name="dn1" dataHost="localhost1" database="db1" />

<dataNode name="dn2" dataHost="localhost1" database="db2" />

<dataNode name="dn3" dataHost="localhost1" database="db3" />

<dataHost name="localhost1" maxCon="1000" minCon="10" balance="1"

writeType="0" dbType="mysql" dbDriver="native" switchType="2"  slaveThreshold="100">

<heartbeat>show slave status</heartbeat>

<writeHost host="hostM" url="192.168.25.101:3306" user="root"password="root">

<readHost host="hostS" url="192.168.25.102:3306" user="root"password="root" />

</writeHost>

</dataHost>








































以上是关于MyCat瀹炵幇鏁版嵁搴撲笌鏁版嵁搴撲箣闂寸殑璇诲啓鍒嗙的主要内容,如果未能解决你的问题,请参考以下文章

鏁版嵁搴撲紭鍖栫殑鎬濊矾

涓€鏉℃洿鏂癝QL鍦∕ySQL鏁版嵁搴撲腑鏄浣曟墽琛岀殑

Greenplum鏁版嵁搴撲腑绯荤粺琛╬g_class璇﹁В

浜戞爾骞茶揣鍥為 | 琛屼笟椤剁骇NoSQL鎴愬憳鍧愰晣锛孨oSQL鏁版嵁搴撲笓鍦洪噸鐐硅В鏋愶紒

澶氫釜git椤圭洰搴撲箣闂寸殑git cherry-pick浠g爜鍚屾

Go 姣忔棩涓€搴撲箣 termtables