MYSQL-mycat database middleware parameter configuration

MYSQL-mycat database middleware parameter configuration

1. The role of mycat middleware

One master, one slave + read-write separation:

img

Dual master replication + read-write separation:

Insert picture description here

2. server.xml configuration

wabong用户可读可写,rabong只读不可写
[root@master conf]# cat server.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
	<system>
	<property name="defaultSqlParser">druidparser</property>
	</system>
	<!--以下设置为应用访问帐号权限 -->
	<!--可写账号 -->
	<user name="wabong">
	<property name="password">123456</property>
	<property name="schemas">test</property>
	</user>
	<!--只读账号 -->
	<user name="rabong">
	<property name="password">123456</property>
	<property name="schemas">test</property>
	<property name="readOnly">true</property>
	</user>
</mycat:server>
parameter effect
<mycat:server> </mycat:server> Define mycat service configuration
<system> </system> Define a system
<property name="Variable name">Variable value</property> Define tags and their corresponding values
<user name="User Name"> </user> mycat username
<property name=“password”>123456</property> The password corresponding to the mycat user
<property name=“schemas”>test</property> Can log in database name
<property name=“readOnly”>true</property> Indicates that the user can only read, not write

3. Schema.xml placement

# 主从复制+读写分离
[root@master conf]# cat schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="test" checkSQLschema="false" sqlMaxLimit="100" dataNode='dn1'>
</schema>
<dataNode name="dn1" dataHost="dthost" database="test"/>
<dataHost name="dthost" maxCon="500" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="-1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<!--后端写库(主库)信息 -->
<writeHost host="master1" url="192.168.10.10:3306" user="mycat" password="123456">
    <!--后端读库(从库)信息 -->
    <readHost host="slave1" url="192.168.10.20:3306" user="mycat" password="123456" />
</writeHost>
</dataHost>
</mycat:schema>


# 双主复制+读写分离
[root@master conf]# cat schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="test" checkSQLschema="false" sqlMaxLimit="100" dataNode='dn1'>
</schema>
<dataNode name="dn1" dataHost="dthost" database="test"/>
<dataHost name="dthost" maxCon="500" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="-1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<!--后端写库(主库1)信息 -->
<writeHost host="master1" url="192.168.10.10:3306" user="mycat" password="123456" >
</writeHost>
<!--后端写库(主库2)信息 -->
<writeHost host="master1" url="192.168.10.20:3306" user="mycat" password="123456" >
</writeHost>
</dataHost>
</mycat:schema>
parameter effect
<mycat:schema> </mycat:schema> schema tag
<schema> </schema> Define a schema tag
name=“test” schema tag name
checkSQLschema=“false” If the database name is schema and this parameter is true, the prefix database name schema of the table in the SQL statement is removed. It is not removed by default, which is false.
sqlMaxLimit=“100” When the query result is in the default limit statement, only 100 records are displayed.
dataNode=‘dn1’ Define the data nodes in mycat, also called data shards. A dataNode tag is an independent data slice.
<dataNode /> Define a dataNode data shard label
name=“dn1” dataNode tag name
dataHost=“dthost” The database instance to which the data node belongs
database=“test” The specific database on the database instance to which the data node belongs
<dataHost> </dataHost> Define database instance tags
name=“dthost” Database instance tag name
maxCon=“500” The maximum number of connections per read-write instance connection pool
minCon=“10” The minimum number of connections for each read-write instance connection pool
balance=“1” Load balancing type.
0: Do not open read-write separation, all reads are given to writeHost.
1: All readHost and stand by writeHost hosts participate in select load balancing.
2: Read operations are randomly allocated to readHost and writeHost
3: Read operations are randomly allocated to readHost corresponding to writeHost for execution, and writeHost does not perform read operations.
writeType=“0” 0: All write operations are allocated to the first writeHost. If the first writeHost is hung up, it is allocated to the second surviving writeHost. After the first recovery, you can view the switching record in the dnindex.properties file.
1: Write operations are randomly assigned to writeHost, and it is not recommended.
dbType=“mysql” Specify the database type for back-end connection, support binary mysql protocol, support JDBC connection database, such as mongodb, oracle, spark, etc.
dbDriver=“native” Specify the Driver used to connect to the back-end database. The optional values ​​are native and JDBC. Choose native to use mysql and mariadb databases, and other databases use JDBC drivers.
switchType="-1" -1: Do not switch automatically
1: Switch automatically
2: Based on show slave status; decide whether to switch
3: Determine whether to switch based on the switching mechanism of mysql galary cluster [show status like'wsrep%';]
Generally set to -1
slaveThreshold=“100” Maximum number of read-write separated slave servers
<heartbeat>select user()</heartbeat> Heartbeat detection statement for back-end database
<writeHost> </writeHost> Write examples, multiple can be defined in dataHost. The database corresponding to the write instance is down, and the read instance is unavailable. Multiple read instances can be defined in a write instance. Corresponds to the main library.
<readHost> </readHost> Read examples are defined in write examples. Corresponding to the slave library.
host=“master” Instance name
url=“192.168.10.10:3306” Back-end instance connection address
native: IP address: port number
JDBC: url of jdbc
user=“mycat” User name of the back-end storage instance
password=“Abong123.” Password of the back-end storage instance
weight=“1” Weight, configure the weight of the read node in readhost.

Through the above configuration, the separation of read and write between master and slave and dual master can be achieved.

Guess you like

Origin blog.csdn.net/weixin_36522099/article/details/108831695