Environment: Mariadb Main: 192.168.200.129
Mariadb From: 192.168.200.114
Mycat :192.168.200.112
(1) installation of jdk, to see if the machine has jdk, due Mycat is based on the Java language to write, so you need to install JDK, version 1.8 can be. If not, install it and configure the environment variables
[root@ns2 ~]# ls
jdk-8u191-linux-x64.tar.gz
[Root @ ns2 ~] # tar xf jdk-8u191-linux-x64.tar.gz // codecs
[Root @ ns2 ~] # mv jdk1.8.0_191 / usr / local / java // I move it to the next / usr / local named java
[Root @ ns2 ~] # vim / etc / profile // configuration environment variable
[Root @ ns2 ~] # source / etc / profile // declare what
[root@ns2 ~]# java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
(2) Installation deployment mycat
Mycat download the installation package, download address http://dl.mycat.io/ , you can select the version of linux environment.
After Mycat upload server installation package decompression, decompression after I move to the next file / usr / local
Now has mycat deployed, the next mycat modify configuration files.
(3) Configuration step Mycat
01, in the main library and the library are used to create the account Mycat connection:
Provide authority for all tables in a database and create a user name and password specified host user created:
02, the configuration Mycat schema.xml file, the file is located in the conf folder under Mycat:
The tag logic schema library definition myCat instance, there may be a plurality of logical myCat libraries, each logical bank has its own configuration. Schema tags may be used to divide the different logical bank.
dataNode tag defines data nodes MyCat in, that is, we usually say that the data fragmentation. DataNode a separate data tag is a fragment.
dataHost labels directly defines the specific database instance, separate read and write configuration and heartbeat statements.
balance property
Load balancing type, the current values of three kinds:
balance = "0", separate read and write mechanism is not enabled, all reads are sent to the currently available writeHost.
balance = "1", and all readHost stand by writeHost participate in load balancing select statement, simply, when the dual master-slave mode bis (M1-> S1, M2-> S2, and M1 and M2 mutual backup) , under normal circumstances, M2, S1, S2 are involved in the select statement to load balancing.
balance = "2", all read operations are random in writeHost, the distribution readhost.
balance = "3", all read requests to a random distribution corresponding readhost wiriterHost performed, writerHost pressure without the burden of reading
Force, pay attention to balance = 3 only in the 1.4 and later versions, not 1.3.
writeType property
writeType = "0", all write operations to the first transmission writeHost configuration, still exist after the first switch to a second hanging
writeHost, whichever is the later switched after restarting, switch record in the configuration file: dnindex.properties.
writeType = "1", all writes are sent to a random configuration writeHost
[root@ns2 ~]# vim /usr/local/mycat/conf/schema.xml
<mycat:schema xmlns:mycat="http://io.mycat/">
<!-- auto sharding by id (long) -->
<!-- < table name="users" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" /> -->
<!-- <table name="oc_call" primaryKey="ID" dataNode="dn1$0-743" rule="latest-month-calldate"
/> -->
</schema>
<!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743"
/> -->
<dataNode name="mycatnode" dataHost="mycathost" database="mycat" />
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="master" url="192.168.200.129:3306" user="mycat"
password="123.com">
<readHost host="slave" url="192.168.200.114:3306" user="mycat" password="123.com"/>
Specify the library database and table names, specify the type of load balancing, specify the primary user and password from the server and port work and created
03, the configuration server.xml, that is the main configuration of user account information connected Mycat:
Account Configuration
The first user label: created before the specified database user name and password and specify the database
The second user label: Specifies the creation of user and password, connection testing.
Then start the service
[root@ns2 mycat]# bin/mycat start
Connection Test:
View command: show @@ datasource; // viewed on the management side.
test:
mycat client: the default 8066, can be changed manually. Server.xml user is the user profile configuration.
mycat management side: the default 9066, can be changed manually, the user is the user server.xml configuration file configuration.
View:
When calling interface reads a corresponding value on the slave READ_LOAD will add a note is away from a library;
When you call a write interface WRITE_LOAD value in the master will add a description is to take the main library