Use mycat to deploy horizontal sub-table global table on centos7 of MyCat-06

1. Goal

Install mycat deployment on Centos7.6, and set the mysql horizontal sub-table global table. Understand what is called mysql horizontal sub-table global table. (No pit version)

Horizontal sub-table: That is, it was originally a separate database, and the table is also separate. The performance is affected because the table is too large. Just get another server, build the same database, and then split some tables into two and put them on two servers, which can reduce the pressure on the server. However, join cannot be used after the horizontal sub-table.

Horizontal sub-table ER table: on the basis of the horizontal sub-table, add sub-tables (sub-tables are called ER tables), so that the main table can join sub-tables.

Mycat horizontal sub-table global table: that is, a table has the same data on all mysql servers. This type of table is generally used for small data, and each mysql server will use the obtained table

Second, the platform

[[email protected] ~]# uname -a
Linux client 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[[email protected] ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
Mycat-server-1.6.7.5-test-20200303154735-linux.tar.gz

Three, experimental topology

Host name ip Required software installed Role
mycat31 192.168.73.31 java1.8 and above, mycat1.6.7.5, mysql5.7 mycat server, partial table storage of
mysql library xkahn mycat32 192.168.73.32 mysql5.7 mysql library xkahn Part of the table storage

Four, preparations

1. Turn off the firewall on both hosts and disable the firewall to start automatically.
2. The mycat server must be installed with java1.8 and above.
3. Both hosts have installed mysql5.7. Here is a tutorial " Mysql5 of Centos7 Notes .7 Installation "
4. Test the interoperability of the two mysqls, and both mysqls can remotely log in to each other’s mysql database. The method is as follows: mysql -uroot -p123123 -h 192.168.73.31 -P 3306 (this is to connect to the 32 host to connect 31 The mysql on the host, the root password of the mysql on 31 is 123123, and the mysql port on 31 is 3306), and then, it is necessary for the two to do mysql intercommunication with each other.
5. If you have done mysql master-slave replication, it is best to stop the master-slave replication (unnecessary settings in my.cnf are commented out)

V. Long-winded preface

1.mycat official website http://www.mycat.io/
2.mycat download address http://dl.mycat.io/
3.schema.xml----->define logic libraries, tables, sharding nodes, etc. Content
4.rule.xml----->define fragmentation rules
5.server.xml----->define users and system related variables, ports, etc.
6. Go to the mycat/bin directory and do the console startup mycat-------> ./mycat console
7. Go to the mycat/bin directory and do the background startup mycat----------->. /mycat start
8. The operation of mycat depends on java, so you need to install jdk on the host in advance, and the jdk installation is skipped. Use the command java -version to check whether the java environment is installed on the machine. At least version 1.8 and above is required for jdk.

Six, download and install mycat_for_linux

(executed on mycat31) download and install mycat

mkdir -p /opt/software/mycat
cd /opt/software/mycat
wget -P /opt/software/mycat/ http://dl.mycat.io/1.6.7.5/2020-3-3/Mycat-server-1.6.7.5-test-20200303154735-linux.tar.gz
tar -zxvf Mycat-server-1.6.7.5-test-20200303154735-linux.tar.gz
cp -r mycat/ /usr/local/

7. Set the mycat configuration file to support the global table of the mycat level table for this experiment

1. (Executed on mycat31) Modify the default startup account in the configuration file /usr/local/mycat/conf/server.xml from root to mycat
(the account mycat here is the management account of mycat, not the linux system account number.)

cp /usr/local/mycat/conf/server.xml{,.bak}
sed -i 's/name="root"/name="mycat"/g' /usr/local/mycat/conf/server.xml

Note:
<user name="mycat" ----->Define the management account of mycat as mycat (that is, the account to log in to the mycat management program, not the linux system account)
<property name="password">123456 ---- ->Define the password of the management account of mycat
<property name="schemas">TESTDB ----->Define the name of the logical database of mycat, which needs to be consistent with the <schema name="TESTDB" in the schema.xml.

2. (executed on mycat31) modify the configuration file /usr/local/mycat/conf/schema.xml

cat > /usr/local/mycat/conf/schema.xml <<EOF
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">

        <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1">
           <table name="teacher" dataNode="dn2"></table>
           <table name="student" dataNode="dn1,dn2" rule="mod_rule">
               <childTable name="student_record" primaryKey="xid" joinKey="student_id" parentKey="xid" />
           </table>
           <table name="xuser" dataNode="dn1,dn2" type="global"></table>
        </schema>
        <dataNode name="dn1" dataHost="host1" database="xkahn" />
        <dataNode name="dn2" dataHost="host2" database="xkahn" />
        <dataHost name="host1" maxCon="1000" minCon="10" balance="0"
                          writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
                <heartbeat>select user()</heartbeat>
                <writeHost host="hostM1" url="10.100.100.31:3306" user="root"
                                   password="123123">
                </writeHost>
        </dataHost>
        <dataHost name="host2" maxCon="1000" minCon="10" balance="0"
                          writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
                <heartbeat>select user()</heartbeat>
                <writeHost host="hostM1" url="10.100.100.32:3306" user="root"
                                   password="123123">
                </writeHost>
        </dataHost>
</mycat:schema>
EOF

Note:
Most of the parameters were introduced in the previous blog " Using mycat to deploy vertical sub-libraries on centos7 of MyCat-03 ".
Based on the previous post " Use mycat to deploy horizontal sub-table ER table on centos7 of MyCat-05 ", the difference this time is that
#Compared with the previous mycat horizontal sub-table ER table, this time there is one more global table. Configuration:
<table name="xuser" dataNode="dn1,dn2" type="global"></table>, xuser refers to the table name of the global table, the branch is on two mysql, the type is global . ( The ip address in the screenshot here is made by another computer, you only care about the last paragraph of the ip address )

3.(executed on mycat31) modify the configuration file rule.xml

cp /usr/local/mycat/conf/rule.xml{,.bak}
vim /usr/local/mycat/conf/rule.xml

3-1. (executed on mycat31) Adding a custom rule
sid represents the name of the column column in the table student in the database xkahn defined in schema.xml called sid. (Mycat uses our custom column sid to split a table into two
mysqls with a certain algorithm) Add 7 lines of content below <mycat:rule xmlns:mycat="http://io.mycat/"> (Including the last blank line)

        <tableRule name="mod_rule">
                <rule>
                        <columns>xid</columns>
                        <algorithm>mod-long</algorithm>
                </rule>
        </tableRule>

Note: The xid in <columns>xid</columns> here was written as sid last time, but this time it is changed to xid. Why do you want to change it? Because I am afraid of ambiguity, what ambiguity? Because for the er level scoring table, the main table and the sub-table (the joined table) use an algorithm in rule.xml to make the level scoring table, and the algorithm of the scoring table uses xid to do mod-long to do the level scoring. Therefore, the primary key id of the main table and the sub-table must be consistent, and both are called xid. (The original sid means the id of the student, now that it must be the same, let's make it xid)

3-2. (Executed on mycat31) Modify the number of mysql hosts for
mod-long, which is a predefined algorithm of the system. Originally, mod-long defaulted to 3 mysql hosts. Because we tested only two, it was written as 2.
The
        <function name = "Long-MOD" class = "io.mycat.route.function.PartitionByMod">
                <-! How MANY Data Nodes ->
                <Property name = "COUNT">. 3 </ Property>
        </ function>
to

        <function name="mod-long" class="io.mycat.route.function.PartitionByMod">
                <!-- how many data nodes -->
                <property name="count">2</property>
        </function>

3-3. If the test is done according to the previous article, then delete the databases on the previous two servers

mysql -uroot -p123123
drop database xkahn;

4-1. Re-create the xkahn database and table student on both servers

CREATE DATABASE IF NOT EXISTS xkahn DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
use xkahn;
create table student(xid int(10) not null unique primary key,name varchar(20) not null);

4-2. Create the sub-table ER table on the two servers first

create table student_record(xid int(10) not null unique primary key,student_id int(10),record varchar(500));

4-3. Build the global table xuser on both servers

mysql -uroot -p123123
use xkahn;
create table xuser(xid int(10) not null unique primary key,name varchar(20) not null,createtime datetime,note varchar(500));

5. Start the mycat service on mycat31 (open a new mycat31 terminal)

cd /usr/local/mycat/bin
./mycat console

6. Open another mycat31 terminal to log in to the mycat data management platform

mysql -umycat -p123456 -h 10.100.100.31 -P 8066

And insert the data in the student table

insert into student(xid,name) values (1,'serena');
insert into student(xid,name) values (2,'xishi');
insert into student(xid,name) values (3,'kahn');
insert into student(xid,name) values (4,'songsuer');
insert into student(xid,name) values (5,'liuduoyan');
insert into student(xid,name) values (6,'cuiseqi');
insert into student(xid,name) values (7,'yiwanka');
insert into student(xid,name) values (8,'linzhiling');
insert into student(xid,name) values (9,'xiaozemaria');
insert into student(xid,name) values (10,'jizemingbu');

7. Go to the two physical database servers to check whether the student table is allocated

mysql -uroot -p123123
use xkahn;
select * from student;

#It must be ensured that all the data are allocated, otherwise the level score table is a failure

8-1. Then insert data into the student_record table in mycat8066 of mycat31

mysql -umycat -p123456 -h 10.100.100.31 -P 8066
use TESTDB;
 
insert into student_record(xid,student_id,record) values (1,1,'serena record, form shanghai,175cm');
insert into student_record(xid,student_id,record) values (2,2,'xishi,aaaaaaaaaa,171cm');
insert into student_record(xid,student_id,record) values (3,3,'kahn666666,180cm');
insert into student_record(xid,student_id,record) values (4,4,'songsuer,model,korea,171cm');
insert into student_record(xid,student_id,record) values (5,5,'liuduoyan,meinvchemo.com,172cm');
insert into student_record(xid,student_id,record) values (6,6,'cuiseqi,korea south,170cm');
insert into student_record(xid,student_id,record) values (7,7,'yiwanka,dadaoUSAhuozhuo10000ka,170cm');
insert into student_record(xid,student_id,record) values (8,8,'linzhiling,laonvrenxiaoriben,173cm');
insert into student_record(xid,student_id,record) values (9,9,'xiaozemaria,fromjp,166cm');
insert into student_record(xid,student_id,record) values (10,10,'jizelaoshi66666,163cm');

8-2. Check the data just inserted select * from student_record;

9. Go to the two mysql physical servers to check whether the data of the sub-table is also split on the two servers. select * from student_record;
(The student_record data on the two servers must be split, otherwise the horizontal split ER table is a failure of)


10.Check whether the join function of the ER table can be realized. On the 8066 of mycat, join query
SELECT s.*,r.record FROM student AS s INNER JOIN student_record AS r ON s.xid=r.student_id;
(must be able to find out Data, otherwise it means that the level score table ER table is a failure)

11. Insert the data of the global table into the mycat data management platform on mycat31

mysql -umycat -p123456 -h 10.100.100.31 -P 8066
use TESTDB;
show tables;
insert into xuser (xid,name,createtime,note) VALUES (1,'admin001','2020-03-01','the first administrator');
insert into xuser (xid,name,createtime,note) VALUES (2,'admin002','2020-03-02','the second administrator');
insert into xuser (xid,name,createtime,note) VALUES (3,'admin003','2020-03-03','the thirdly administrator');
insert into xuser (xid,name,createtime,note) VALUES (4,'admin004','2020-03-04','the fourthly administrator');
insert into xuser (xid,name,createtime,note) VALUES (5,'admin005','2020-03-05','the fifth administrator');

 

12. Go to the two physical machines to check whether there is any data? If there are both, it means success.

It is found that the data of the mycat global table xuser on the two physical servers is exactly the same. This effect is right, this is the Mycat global table.

----------------------END---------------------March 23, 2020 23:07:36----------------------------

The experiment is 5 minutes, and the screenshot is 50 minutes for blogging, which really takes time.

Lao Tie, double click 666 to like

Guess you like

Origin blog.csdn.net/xoofly/article/details/105059793