主頁 > 知識庫 > mysql mycat 中間件安裝與使用

mysql mycat 中間件安裝與使用

熱門標(biāo)簽:鐵路電話系統(tǒng) Linux服務(wù)器 地方門戶網(wǎng)站 服務(wù)外包 呼叫中心市場需求 網(wǎng)站排名優(yōu)化 AI電銷 百度競價(jià)排名

一,什么是mycat

一個徹底開源的,面向企業(yè)應(yīng)用開發(fā)的大數(shù)據(jù)庫集群

支持事務(wù)、ACID、可以替代MySQL的加強(qiáng)版數(shù)據(jù)庫

一個可以視為MySQL集群的企業(yè)級數(shù)據(jù)庫,用來替代昂貴的Oracle集群

一個融合內(nèi)存緩存技術(shù)、NoSQL技術(shù)、HDFS大數(shù)據(jù)的新型SQL Server

結(jié)合傳統(tǒng)數(shù)據(jù)庫和新型分布式數(shù)據(jù)倉庫的新一代企業(yè)級數(shù)據(jù)庫產(chǎn)品

一個新穎的數(shù)據(jù)庫中間件產(chǎn)品

以上是官方說明。其實(shí)就是數(shù)據(jù)庫的連接池。mysql proxy也是一種連接池,但是效率很低。

二,mycat 安裝

1,下載地址mycat

http://dl.mycat.io/

2,安裝mycat

# tar zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz -C /usr/local/

三,配置mycat

1,配置server.xml

# vim /usr/local/mycat/conf/server.xml //添加以下內(nèi)容

 user name="user">  //mycat用戶名
 property name="password">user/property> //mycat密碼
 property name="schemas">mytest/property>  //mycat虛擬數(shù)據(jù)庫名
 property name="readOnly">true/property>  //只讀
 /user>

 user name="tankzhang">
 property name="password">admin/property>
 property name="schemas">mytest/property>
 /user>

在這里要注意,默認(rèn)的虛擬數(shù)據(jù)名是TESTDB,如果schema.xml里面沒有配置testdb,那就要把testdb改成schema.xml里面有的虛擬數(shù)據(jù)名。這里定義的用戶名和密碼,虛擬數(shù)據(jù)庫名,并不是在mysql中真實(shí)存在的。

2,配置schema.xml

# cat schema.xml
?xml version="1.0"?>
!DOCTYPE mycat:schema SYSTEM "schema.dtd">
mycat:schema xmlns:mycat="http://io.mycat/">

schema name="mytest" checkSQLschema="false" sqlMaxLimit="100" dataNode="my1" />//定義虛擬數(shù)據(jù)庫名mytest
dataNode name="my1" dataHost="test1" database="test" /> //真實(shí)數(shù)據(jù)庫名test
dataHost name="test1" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" >
heartbeat>select user()/heartbeat>
writeHost host="hostM1" url="192.168.5.213:3306" user="tank" password="123456" > //真實(shí)數(shù)據(jù)庫的連接方式
 readHost host="hostS1" url="192.168.5.214:3306" user="tank" password="123456" /> //同上
 /writeHost>
 /dataHost>

/mycat:schema>

mycat的配置參數(shù),相當(dāng)?shù)亩唷V攸c(diǎn)說一下 balance="1"與writeType="0"

a. balance 屬性負(fù)載均衡類型,目前的取值有 4 種:

1. balance="0", 不開啟讀寫分離機(jī)制,所有讀操作都發(fā)送到當(dāng)前可用的 writeHost 上。

2. balance="1",全部的 readHost 與 stand by writeHost 參與 select 語句的負(fù)載均衡,簡單的說,當(dāng)雙主雙從模式(M1 ->S1 , M2->S2,并且 M1 與 M2 互為主備),正常情況下, M2,S1,S2 都參與 select 語句的負(fù)載均衡。

3. balance="2",所有讀操作都隨機(jī)的在 writeHost、 readhost 上分發(fā)。

4. balance="3", 所有讀請求隨機(jī)的分發(fā)到 wiriterHost 對應(yīng)的 readhost 執(zhí)行,writerHost 不負(fù)擔(dān)讀壓力,注意 balance=3 只在 1.4 及其以后版本有, 1.3 沒有。

b. writeType 屬性

負(fù)載均衡類型,目前的取值有 3 種:

1. writeType="0", 所有寫操作發(fā)送到配置的第一個 writeHost,第一個掛了切到還生存的第二個

writeHost,重新啟動后已切換后的為準(zhǔn),切換記錄在配置文件中:dnindex.properties .

2. writeType="1",所有寫操作都隨機(jī)的發(fā)送到配置的 writeHost。

3. writeType="2",沒實(shí)現(xiàn)。

具體參數(shù):http://mycat.io/document/Mycat_V1.6.0.pdf

3,配置主從服務(wù)器,就不在這兒說了,博客中有

4,添加真實(shí)用戶

grant all privileges on test.* to tank@"192.168.%" identified by '123456';
flush privileges

在213,214二臺機(jī)器上添加用戶。

5,測試真實(shí)用戶連接,確保schema.xml中配置的真實(shí)用戶,能連上真實(shí)的數(shù)據(jù)庫。注意防火墻。

四,啟動mycat

1,常用參數(shù)
./mycat start 啟動
./mycat stop 停止
./mycat console 前臺運(yùn)行
./mycat restart 重啟服務(wù)
./mycat pause 暫停
./mycat status 查看啟動狀態(tài)

2,啟動,并查看mycat

# ./mycat start
Starting Mycat-server...

# netstat -tpnl |grep 8066
tcp 0 0 :::8066 :::* LISTEN 31728/java 

# ./mycat status
Mycat-server is running (31726).

五,測試讀寫分離

# mysql -u tankzhang -p -P 8066 -h 127.0.0.1 //一定要帶上127.0.0.1
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (OpenCloundDB)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+----------+
| DATABASE |
+----------+
| mytest |    //虛擬數(shù)據(jù)庫
+----------+
1 row in set (0.00 sec)

mysql> use mytest;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

mysql> CREATE TABLE IF NOT EXISTS `user` (
 -> `id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'ID',
 -> `name` varchar(20) NOT NULL DEFAULT '' COMMENT '姓名',
 -> `create_time` int(10) NOT NULL DEFAULT '0' COMMENT '創(chuàng)建時間',
 -> PRIMARY KEY (`id`)
 -> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Query OK, 0 rows affected (0.08 sec)

Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| user |
+----------------+
1 row in set (0.01 sec)

mysql> INSERT INTO `user` (`id` ,`name`)VALUES ('1', 'tank');
Query OK, 1 row affected (0.00 sec)

mysql> select * from user;  //修改從數(shù)據(jù)庫的user表中的name,會發(fā)現(xiàn)讀是從從數(shù)據(jù)庫讀取的
+----+-----------+-------------+
| id | name | create_time |
+----+-----------+-------------+
| 1 | tankzhang | 0 |
+----+-----------+-------------+
1 row in set (0.01 sec)

六,小結(jié)

mycat支持 mysql的分表,分片等等,但是不建議使用。mycat支持的集群不多,如果能配合mha使用就比較牛B了。

您可能感興趣的文章:
  • 基于mysql+mycat搭建穩(wěn)定高可用集群負(fù)載均衡主備復(fù)制讀寫分離操作
  • 利用mycat實(shí)現(xiàn)mysql數(shù)據(jù)庫讀寫分離的示例
  • 數(shù)據(jù)庫中間件MyCat的介紹
  • mycat在windows環(huán)境下的安裝和啟動
  • 簡單了解mysql mycat 中間件

標(biāo)簽:衡水 銅川 仙桃 黃山 湘潭 崇左 蘭州 湖南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《mysql mycat 中間件安裝與使用》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266