当前位置:网站首页>MYCAT middleware installation and use

MYCAT middleware installation and use

2022-07-04 07:24:00 InfoQ

One , What is? mycat

A completely open source , Large database cluster for enterprise application development

Support transactions 、ACID、 Can replace MySQL Enhanced database of

One can be regarded as MySQL Enterprise database of cluster , To replace the expensive Oracle colony

A fusion of memory cache technology 、NoSQL technology 、HDFS New big data SQL Server

A new generation of enterprise database products combining traditional database and new distributed data warehouse

A new database middleware product

These are the official instructions . In fact, it is the connection pool of the database .mysql proxy It is also a connection pool , But it's inefficient .

Two ,mycat  install

1, Download address mycat

http://dl.mycat.io/

2, install mycat

1

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

3、 ... and , To configure mycat

1, To configure server.xml

123456789101112

vim /usr/local/mycat/conf/server.xml // Add the following

<user name= &quot;user&quot; > //mycat  user name <property name= &quot;password&quot; >user< /property > //mycat  password <property name= &quot;schemas&quot; >mytest< /property > //mycat  Virtual database name <property name= &quot;readOnly&quot; > true < /property > //  read-only < /user >

<user name= &quot;tankzhang&quot; ><property name= &quot;password&quot; >admin< /property ><property name= &quot;schemas&quot; >mytest< /property >< /user > Be careful here , The default virtual data name is TESTDB, If schema.xml There is no configuration in it testdb, Then you have to testdb Change to schema.xml There are virtual data names . The user name and password defined here , Virtual database name , It's not in mysql The real existence of .

2, To configure schema.xml

123456789101112131415

cat schema.xml

<?xml version= &quot;1.0&quot; ?><!DOCTYPE mycat:schema SYSTEM &quot;schema.dtd&quot; ><mycat:schema xmlns:mycat= &quot;http://io.mycat/&quot; >

<schema name= &quot;mytest&quot; checkSQLschema= &quot;false&quot; sqlMaxLimit= &quot;100&quot; dataNode= &quot;my1&quot; /> //  Define the virtual database name mytest<dataNode name= &quot;my1&quot; dataHost= &quot;test1&quot; database= &quot;test&quot; /> //  Real database name  test<dataHost name= &quot;test1&quot; maxCon= &quot;1000&quot; minCon= &quot;10&quot; balance= &quot;1&quot; writeType= &quot;0&quot; dbType= &quot;mysql&quot; dbDriver= &quot;native&quot; ><heartbeat> select user()< /heartbeat ><writeHost host= &quot;hostM1&quot; url= &quot;192.168.5.213:3306&quot; user= &quot;tank&quot; password= &quot;123456&quot; > //  How to connect the real database <readHost host= &quot;hostS1&quot; url= &quot;192.168.5.214:3306&quot; user= &quot;tank&quot; password= &quot;123456&quot; /> //  ditto < /writeHost >< /dataHost >

< /mycat :schema>mycat Configuration parameters for , Quite a lot . The point is  balance=&quot;1&quot; And writeType=&quot;0&quot;

a. balance  Property load balancing type , The current values are  4  Kind of :

  • balance=&quot;0&quot;,  Do not turn on the read-write separation mechanism , All read operations are sent to the currently available  writeHost  On .
  • balance=&quot;1&quot;, All of the  readHost  And  stand by writeHost  Participate in  select  Statement load balancing , To put it simply , When dual master dual slave mode (M1 ->S1 , M2->S2, also  M1  And  M2  Prepare for each other ), Under normal circumstances , M2,S1,S2  All involved  select  Statement load balancing .
  • balance=&quot;2&quot;, All the reading operations are random in  writeHost、 readhost  To distribute .
  • balance=&quot;3&quot;,  All read requests are randomly distributed to  wiriterHost  Corresponding  readhost  perform ,writerHost  No pressure to read , Be careful  balance=3  Only in  1.4  And later versions have , 1.3  No, .

b. writeType  attribute

Load balancing type , The current values are  3  Kind of :

  • writeType=&quot;0&quot;,  All writes are sent to the first of the configuration  writeHost, The first one is cut to the second one that still exists

writeHost, After restart, the one that has been switched shall prevail , The switch is recorded in the configuration file :dnindex.properties .

  • writeType=&quot;1&quot;, All writes are sent randomly to the configured  writeHost.
  • writeType=&quot;2&quot;, Not realized .

Specific parameters :http://mycat.io/document/Mycat_V1.6.0.pdf

3, Configure master and slave servers , I won't say it here , In the blog

4, Add real users

?

12grant all privileges on test .* to [email protected] &quot;192.168.%&quot; identified by '123456' ;flush privileges stay 213,214 Add users on two machines .

5, Test the real user connection , Make sure schema.xml Real users configured in , Can connect to the real database . Pay attention to the firewall .

Four , start-up mycat

1, Common parameters ./mycat start  start-up ./mycat stop  stop it ./mycat console  The front desk operation ./mycat restart  Restart the service ./mycat pause  Pause ./mycat status  View startup status

2, start-up , And look at mycat

12345678

./mycat start

Starting Mycat-server...

netstat -tpnl |grep 8066

tcp 0 0 :::8066 :::* LISTEN 31728 /java

./mycat status

Mycat-server is running (31726). 5、 ... and , Test read-write separation

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253

mysql -u tankzhang -p -P 8066 -h 127.0.0.1 // You have to take it 127.0.0.1

Enter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.

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

mysql> show databases;+----------+| DATABASE |+----------+| mytest | //  Virtual database +----------+1 row in set (0.00 sec)

mysql> use mytest;Reading table information for completion of table and column namesYou 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 ' full name ' ,-> 
create_time
 int(10) NOT NULL DEFAULT '0' COMMENT ' Creation time ' ,-> PRIMARY KEY (
id
)-> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;Query OK, 0 rows affected (0.08 sec)

Database changedmysql> 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; //  Modify from the database user In the table name, You will find that the read is from the database +----+-----------+-------------+| id | name | create_time |+----+-----------+-------------+| 1 | tankzhang | 0 |+----+-----------+-------------+1 row in set (0.01 sec) 6、 ... and , Summary

mycat Support  mysql Sub table of , Slicing and so on , But not recommended .mycat Not many clusters are supported , If you can cooperate with mha It's better to use B 了 .

key word :
java train
原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141536497981.html