In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to configure MyCat fragments". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to configure MyCat fragments"!
MyCat Architecture MyCat Core Concepts Schema
Schema: it specifies the logical database (equivalent to MySQL's database database)
Table
Table: logical table (equivalent to MySQL's table table)
DataNode
DataNode: the physical node that actually stores the data
DataHost
DataHost: the database host where the storage node resides (specify the connection information for the MySQL database)
User
Users of User:MyCat (similar to MySQL users, supporting multiple users)
MyCat mainly solves the problem of mass data preservation II. Query Optimization MyCat support for multiple databases
MyCat fragmentation strategy
MyCAT supports horizontal and vertical sharding: horizontal sharding: data from a table is divided into multiple nodes, separated by rows. Vertical fragmentation: multiple tables in a database are stored on node 1, B on node 2, and C on node 3.
MyCAT implements slicing by defining the sharding rules of the table. Each table can be bundled with a sharding rule, and each slicing rule specifies a shard field and binds a function to realize the dynamic slicing algorithm.
Schema
Schema: logical library, corresponding to the Database (database) in MySQL. A logical library defines the included Table.
Table
Table: a table, that is, a table stored in a physical database, unlike a traditional database, where the table needs to declare its stored logical data node DataNode. Here you can specify the sharding rules for the table.
DataNode
The logical data node of the DataNode:MyCAT is the specific physical node where the table is stored, also known as the sharding node, which is associated to a specific database at the back end through DataHost.
DataHost
DataHost: defines the access address of a physical library, which is used to bind to Datanode
MyCat installation and download MyCatwget http://dl.mycat.io/1.6-RELEASE/Mycat-server-1.6-RELEASE-20161028204710-
Linux.tar.gz decompress tar-zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz into mycat/bin, launch MyCat- startup command:. / mycat start
-stop command:. / mycat stop
-restart command:. / mycat restart
-View status:. / mycat status
Clients accessing MyCat use mysql to connect directly to the mycat service. The default service port is [8066]
Mysql-uroot-p123456-h227.0.0.1-P8066 MyCat shard configuration schema.xml what is schema.xml
As one of the important configuration files in Mycat, schema.xml manages the mapping relationship between Mycat logic library, table, slicing rules, DataNode and DataHost. Understanding these configurations is a prerequisite for the correct use of Mycat. The schema tag is used to define the logical library in the MyCat instance. The Table tag defines the logical table in MyCat. The dataNode tag defines the data node in MyCat, which is what we usually call data fragmentation. The dataHost tag also exists as the lowest tag in the mycat logic library, directly defining the specific database instance, read-write separation configuration and heartbeat statements.
Schema.xml configuration
Configure Server.xml
Server.xml introduction
Server.xml saves almost all the system configuration information needed by mycat. The most common is to configure user names, passwords, and permissions here.
Server.xml configuration
Configure rule.xml
Rule.xml defines the rules involved in splitting the table. We can flexibly use different slicing calculations on the table.
Method, or use the same algorithm for the table but with different specific parameters. There are mainly two marks tableRule and function in this document.
Sign it. In the specific use process, you can add tableRule and function as needed.
This configuration file does not need to be modified and can be used by default.
Select user ()
Introduction to configuring server.xmlserver.xml
Server.xml saves almost all the system configuration information needed by mycat. The most common is to configure user names, passwords, and permissions here.
Server.xml configuration
Druidparser
Mycat
TESTDB
Configure rule.xml
Rule.xml defines the rules involved in splitting the table. We can flexibly use different slicing algorithms for the table, or use the same algorithm for the table but with different specific parameters. There are mainly two tags tableRule and function in this document. In the specific use process, you can add tableRule and function as needed. This configuration file can be modified without modification and can be used by default.
Sharding_id
Hash-int
Partition-hash-int.txt
TableRule tag configuration instructions:
The name attribute specifies a unique name, and the rule tag, which identifies different table rules, specifies which column in the physical table to split and which routing algorithm to use. Specify the name of the column to split within the columns. Algorithm uses the name attribute in the function tag. Connection table rules and specific routing algorithms. Of course, multiple table rules can be connected to the same routing algorithm. Used within the table tag. Let logical tables use this rule for slicing.
Function tag configuration instructions:
Name specifies the name of the algorithm. Class defines the specific class name of the routing algorithm. Property is some of the attributes that the specific algorithm needs to use.
Several commonly used slicing rules continuous slicing date column partitioning method
Create_time
Sharding-by-date
Yyyy-MM-dd
2014-01-01
ten
Configuration instructions:
TableRule tag:
Columns: identifies the table field to be sliced
Algorithm: specify sharding function
Function tag:
DateFormat: date format
SBeginDate: start date
SPartionDay: partition days, that is, by default, one partition is separated for 10 days from the start date.
II. Scope agreement
Configuration instructions:
TableRule tag:
Create_time
Sharding-by-month
Yyyy-MM-dd
2014-01-01
Create_time
Sharding-by-hour
twenty-four
Configuration description tableRule tag: columns: identify the table field to be sharded algorithm: specify sharding function function tag: dateFormat: date format sBeginDate: start date sPartionDay: partition days, that is, 10 days separated by default from the start date
Scope convention
User_id
Rang-long
Autopartition-long.txt
Configuration description tableRule tag: columns: identify the table field to be sharded algorithm: specify sharding function function tag: mapFile: specify the name of the configuration file required by the sharding function
Autopartition-long.txt file content: all node configurations start with 0, and 0 represents node 1. This configuration is very simple, that is, a possible id range is defined in advance corresponding to a certain shard.
# range start-end, data node index
# Knights 1000, Manners 10000.
0-500M=0 0-1000
500M-1000M=1 101-200 1
201-300 2
1000M-1500M=2
Default=0
# or the following
# 0-10000000000000
# 10000001-20000000 / 1
Advantages: expansion does not need to migrate data disadvantages: hot data, concurrency restrictions
Discrete piecewise enumeration
User_id
Hash-int
Partition-hash-int.txt
0
0
Configuration description tableRule tag: columns: identify the table field to be sharded algorithm: specify sharding function function tag: mapFile: specify the name of the configuration file required by the sharding function type: the default value is 0, 0 means Integer, non-zero means String defaultNode: specify the default node, less than 0 means no default node, 0 or greater than 0 means setting the default node, 0 represents node 1.
The role of the default node: when enumerating fragments, if you encounter an unrecognized enumeration value, let it route to the default node. If the default node is not configured (a defaultNode value less than 0 means that the default node is not configured), an error will be reported when an unrecognized enumeration value is encountered:
Partition-hash-int.txt configuration:
Column 10, 000'0 equals 10000 to put the first shard.
10010 # 1
Male = 0
Female = 1
Beijing=0
Tianjin=1
Zhanghai=2
Modeling method
User_id
Mod-long
three
TableRule tag: columns: identify the table field to be sharded algorithm: specify the sharding function function tag: count: number of nodes
Consistent hash
User_id
Murmur
0
two
one hundred and sixty
Wait, there are some other fragments, here, do not explain for the time being
Test shard
Store the merchandise table in pieces on three data nodes.
Create a tabl
After the configuration is complete, restart mycat. Use the mysql client to connect to the mycat to create the table.
CREATE TABLE item (
Id int (11) NOT NULL
Name varchar (20) DEFAULT NULL
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 fragmentation test
Sharding policy specified as "auto-sharding-long" sharding rule specified as "mod-long"
At this point, I believe you have a deeper understanding of "how to configure MyCat fragments". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 222
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.