In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces you how to get started Mycat quickly. The content is very detailed. Interested friends can refer to it for reference. I hope it can help you.
What is Mycat?
As for what Mycat is, there may be different understandings under different roles. Anyone who knows MySQL architecture knows that MySQL is actually composed of a Server layer and a storage engine layer. So for DBAs, Mycat is MySQL's Server layer. MySQL Server, which is connected behind Mycat, is like MySQL's storage engine. Therefore, Mycat itself does not store data, the data is stored on MySQL at the back end, so the reliability of the data
And transactions are still guaranteed by MySQL.
For developers, Mycat is basically equivalent to MySQL. Because you can use MySQL to connect to Mycat, there is no difference in connection mode except for the default port. So Mycat is transparent to developers, but there are some restrictions on the use of SQL.
For architects, Mycat is a database middleware that can be used for read-write separation, table partitioning, and disaster recovery backup. For applications that use Mycat, it hides the storage logic of the database. Let us not control the storage logic such as read-write separation in code, so as to extend the database architecture without modifying the application code.
Mycat is an open source project in China and has very complete and rich Chinese documents. Therefore, this article will not repeat the basic concepts. It is recommended to refer to the online version of Mycat authoritative guide or to Mycat official website to learn more about Mycat.
What is Database Middleware?
Database middleware is an intermediate service between database and application for data processing and interaction. Because the data is fragmented, the original database is divided into multiple fragmented databases, and all fragmented database clusters constitute the entire database storage.
As shown in the figure above, after the data is divided into multiple sharded databases, the application needs to process data from multiple data sources if it needs to read data.
Without database middleware, the application will face sharded clusters directly. Then data source switching, transaction processing, and data aggregation issues need to be handled directly by the application. This will result in applications that are meant to be business-focused, spending a lot of work dealing with fragmentation problems, and most importantly, each application process will be completely repetitive.
So with database middleware, applications only need to focus on business processes. A large number of common data aggregation, transactions, data source switching are handled by middleware, middleware performance and processing capacity will directly determine the application read and write performance, so a good database middleware is essential.
Mycat's main role
1. Use as distributed database middleware:
Mycat can not only connect to mysql but also to other databases such as oracle and sql server, because Mycat is written in Java, theoretically Mycat can connect to any database that Java can connect to. This allows the application to connect to Mycat without having to connect directly to the database, in which case the backend database is transparent to the application. This shields the application from the complexity of the backend database and maintains consistency in connection patterns.
2. Realize read-write separation and Load Balancer of database cluster:
As the system evolves to a later stage and the volume of data increases, the database architecture typically evolves toward clustering. In the Replication cluster scheme, nodes have master-slave roles, which is often referred to as master-slave architecture. In this cluster, the master node is usually responsible for writing and the slave node is responsible for reading. Mycat can be used as a middle layer to achieve read-write separation, without writing a set of read-write separation logic for each application. And when there are multiple slaves, Mycat can also Load Balancer read requests to each slave.
3. Achieve high availability of database:
When the database architecture is one master and one slave, Mycat can be used to achieve high availability of the database. When the master node goes down, Mycat can switch to the slave node for reading and writing. However, it is not applicable to the case of one master and multiple slaves, because after the master node is suspended, Mycat can only switch to one of the slave nodes, and cannot change the role of the node. This will cause the remaining slave nodes to fail to synchronize their data. Therefore, one master and many slaves need to adopt MMM or MHA to achieve high availability.
4. Vertical segmentation of the business database:
When the write load in the system increases, a single master node begins to be unable to withstand the pressure of write requests, and additional master nodes are needed to share the load. Having multiple master nodes usually results in splitting tables in a library that have no dependencies into different libraries, or splitting large tables into smaller tables to spread the load. This is the vertical partition of the database.
Having multiple master nodes means that an application may need to operate on multiple databases, and Mycat abstracts multiple databases into a logical library. This way, for applications, there is no need to change the code to manipulate multiple data sources, only the logic library in Mycat can be manipulated.
5. Split the business database horizontally:
When the database is vertically split, there may still be some libraries with high write loads or data volumes reaching the single-table limit. Then you need to consider horizontal segmentation, the so-called horizontal segmentation is sub-library sub-table. The difference between vertical segmentation and horizontal segmentation is that after horizontal segmentation, the table structure of each library is the same, and the segmentation is data. Vertical segmentation is different library table structure is not the same, segmentation is the table.
When the database is horizontally partitioned, the application needs to consider which database it should write to when writing data. Mycat, on the other hand, can distribute write requests to a database through specific policies, so that applications only need to send write requests to Mycat, regardless of which library they should write to.
Control the number of database connections:
There are many applications in the system, and each application has its own connection pool, so when the number of visits increases, it is possible to exceed the maximum number of connections in the database. At this point, a common connection pool can be established through Mycat, and all applications use this connection pool to obtain database connections. Therefore, the number of applications connected to the database at the same time is controlled, and a current limiting effect is played, which can ensure that the system is more stable.
Mycat Basic Elements
Logic Library:
Usually for practical applications, it is not necessary to know the existence of Mycat, business developers only need to know the concept of database, so database middleware can be regarded as a logical library composed of one or more database clusters, it should be noted that the logical library does not store data. So no matter what kind of database architecture is behind the middleware, for the application, it is operating a database, and this database is the logic library abstracted by Mycat.
Logic table:
Since there is a logical library, there will be logical tables. In a distributed database, for applications, the tables that read and write data are logical tables. A logical table, which can be distributed in one or more fragmentation libraries after data segmentation. You can also do no data segmentation, no fragmentation, only a table composition. Similarly, logical tables do not store data.
Logical table classification:
Fragmented tables: tables in which data is split into multiple databases
A table whose data has not been split.
Global table: A table that is structured like a dictionary and exists in all shards to solve cross-shard data joins.
ER table: A table that is fragmented according to ER relationship. The purpose is to store the records of the child table and the associated parent table records in the same data fragment, so as to ensure that the data join will not cross the database.
Mycat installation
Environment:
System: CentOS 7
JDK:11
Mycat:1.6.7.4
First go to the official download address to get the download link, then go to linux and use the following command to download and extract:
[root@txy-server ~]# cd /usr/local/src[root@txy-server /usr/local/src]# wget http://dl.mycat.io/1.6.7.4/Mycat-server-1.6.7.4-release/Mycat-server-1.6.7.4-release-20200105164103-linux.tar.gz[root@txy-server /usr/local/src]# tar -zxvf Mycat-server-1.6.7.4-release-20200105164103-linux.tar.gz -C /usr/local/
After decompression, Mycat directory structure is as follows:
[root@txy-server /usr/local/mycat]# ll -rhtotal 24 K-rwxrwx 1 root root 227 Jan 5 16:41 version. txtdrwxrwx 2 root 4.0K Jan 5 16:40 logs #log file directory drwxr-xr-x 2 root 4.0K Jan 6 20:40 lib #library file directory drwxrwxrwx 4 root 4.0K Jan 6 20:40 conf #Configuration file directory drwxrwxrwx 2 root 4.0K Oct 22 21:26 catletdrwxr-xr-x 2 root 4.0K Jan 6 20:40 bin #executable directory [root@txy-server /usr/local/mycat]#
Create a system account for Mycat and change the user of the mycat directory, since it is impossible for a program to have root privileges in a real environment. The order reads as follows:
[root@txy-server /usr/local]# useradd mycat -s /sbin/nologin[root@txy-server /usr/local]# chown -R mycat:mycat mycat/
Configure environment variables:
[root@txy-server ~]# vim /etc/profileexport MYCAT_HOME=/usr/local/mycatexport PATH=$PATH:$MYCAT_HOME/bin[root@txy-server ~]# source /etc/profile
Since my machine memory here is only 2G, so I need to modify the Mycat startup parameter, change the maximum memory to 1G, the parameter defaults to 2G. Of course, if your machine has enough memory, you don't need to change it:
[root@txy-server /usr/local]# vim mycat/conf/wrapper.confwrapper.java.additional.4=-XX:MaxDirectMemorySize=1G
Start Mycat service:
[root@txy-server ~]# mycat start
Check the log and output successfully to indicate successful startup:
[root@txy-server ~]# more /usr/local/mycat/logs/wrapper.log |grep successfullyINFO | jvm 1 | 2020/01/06 21:16:51 | MyCAT Server startup successfully. see logs in logs/mycat.log[root@txy-server ~]#
Mycat will listen to ports 8066 and 9066 by default after startup. If the firewall is turned on, ports need to be released. The commands for opening ports are as follows:
[root@txy-server ~]# firewall-cmd --zone=public --add-port=${port number}/tcp --permanent[root@txy-server ~]# firewall-cmd --reload
So far, we have successfully set up Mycat service.
About how to get started Mycat quickly shared here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
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: 0
*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.