GitHub-Mycat板块最佳实践-亲试ok
-
逻辑库配置:
1.1 配置server.xml
|
创建一个mycat逻辑库:imooc_db
system 参数是所有的mycat参数配置,比如 添加解析器:defaultSqlParser,其他类推
user 是用户参数。
<user name="app_imooc" defaultAccount="true">
<property name="password">123456</property>
<property name="schemas">imooc_db</property>
</user>
注意此处:
app_imooc 用户名
123456 用户密码
imooc_db 逻辑库
|
1.2 编辑schema.xml
修改dataHost和schema对应的连接信息
dataNode是逻辑库对应的分片,如果配置多个分片需要多个dataNode即可。
dataHost是实际的物理库配置地址。
下面的writeHost、readHost代表该分片是否配置多写,主从,读写分离等高级特性。
<schema name="imooc_db" checkSQLschema="false" sqlMaxLimit="100" dataNode="user" />
<table name="order_master" primaryKey="order_id" dataNode="ordb_dn"/>
</schema>
<dataNode name="ord_dn" dataHost="192.168.124.158" database="order_db" />
<dataNode name="prod_dn" dataHost="192.168.124.159" database="product_db" />
<dataNode name="cust_dn" dataHost="192.168.124.160" database="custer_db" />
<dataHost name="192.168.124.159" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native">
<heartbeat>select 1</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="192.168.124.159" url="192.168.124.159:3306" user="root" password="123456" />
#<writeHost host="hostM2" url="192.168.0.3:3306" user="root" password="root" />
</dataHost>
<dataHost name="192.168.124.160" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native">
<heartbeat>select 1</heartbeat>
<!-- can have multi write hosts -->
<writeHost host=192.168.124.160" url="192.168.124.160:3306" user="root" password="123456" />
</dataHost>
测试连接:
[root@m-157 ~]# mysql -uapp_imooc -p123456 -h127.0.0.1 -P8066
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.29-mycat-1.6.5-release-20180122220033 MyCat Server (OpenCloundDB)
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+----------+
| DATABASE |
+----------+
| imooc_db |
+----------+
1 row in set (0.00 sec)
对MyCAT的用户密码做加密
[root@m-157 lib]# java -cp Mycat-server-1.6.5-release.jar io.mycat.util.DecryptUtil 0:zpp_imooc:123456
PdvreoR7rtZepoGBQem6nTggPY8cmx8lts7itp7/bOiTj+s1OTSk5kpyo/FZl8z/jwqQT5qKaEsSAXM/OXwX7w==
再次修改server.xml文件
添加如下 :
<user name="app_imooc" defaultAccount="true">
<property name="password">PdvreoR7rtZepoGBQem6nTggPY8cmx8lts7itp7/bOiTj+s1OTSk5kpyo/FZl8z/jwqQT5qKaEsSAXM/OXwX7w==</property>
<property name="schemas">imooc_db</property>
</user>
配置文件如下:
[root@m-157 conf]# cat schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="imooc_db" checkSQLschema="false" sqlMaxLimit="100" >
<table name="order_master" primaryKey="order_id" dataNode="ord_dn"/>
<table name="order_cart" primaryKey="cart_id" dataNode="ord_dn"/>
<table name="order_customer_addr" primaryKey="customer_addr_id" dataNode="ord_dn"/>
<table name="region_info" primaryKey="region_id" dataNode="ord_dn"/>
<table name="shipping_info" primaryKey="ship_id" dataNode="ord_dn"/>
<table name="warehouse_info" primaryKey="w_id" dataNode="ord_dn"/>
<table name="warehouse_proudct" primaryKey="wp_id" dataNode="ord_dn"/>
<table name="product_brand_info" primaryKey="brand_id" dataNode="prod_dn"/>
<table name="product_category" primaryKey="category_id" dataNode="prod_dn"/>
<table name="product_comment" primaryKey="comment_id" dataNode="prod_dn"/>
<table name="product_info" primaryKey="product_id" dataNode="prod_dn"/>
<table name="product_supplier_info" primaryKey="supplier_id" dataNode="prod_dn"/>
<table name="product_pic_info" primaryKey="product_pic_id" dataNode="prod_dn"/>
<table name="customer_balance_log" primaryKey="balance_id" dataNode="cust_dn"/>
<table name="customer_inf" primaryKey="customer_inf_id" dataNode="cust_dn"/>
<table name="customer_level_inf" primaryKey="customer_level" dataNode="cust_dn"/>
<table name="customer_login" primaryKey="customer_id" dataNode="cust_dn"/>
<table name="customer_login_log" primaryKey="login_id" dataNode="cust_dn"/>
<table name="customer_point_log" primaryKey="point_id" dataNode="cust_dn"/>
</schema>
<dataNode name="ord_dn" dataHost="192.168.124.158" database="order_db" />
<dataNode name="prod_dn" dataHost="192.168.124.159" database="product_db" />
<dataNode name="cust_dn" dataHost="192.168.124.160" database="custer_db" />
<dataHost name="192.168.124.158" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native">
<heartbeat>select 1</heartbeat>
<writeHost host="192.168.124.158" url="192.168.124.158:3306" user="root" password="123456" />
</dataHost>
<dataHost name="192.168.124.159" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native">
<heartbeat>select 1</heartbeat>
<writeHost host="192.168.124.159" url="192.168.124.159:3306" user="root" password="123456" />
</dataHost>
<dataHost name="192.168.124.160" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native">
<heartbeat>select 1</heartbeat>
<writeHost host="192.168.124.160" url="192.168.124.160:3306" user="root" password="123456" />
</dataHost>
</mycat:schema >
[root@m-157 conf]# cat server.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- - - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License. - You
may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0
- - Unless required by applicable law or agreed to in writing, software -
distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the
License for the specific language governing permissions and - limitations
under the License. -->
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
<system>
<property name="serverPort">8066</property>
<property name="managerPort">9066</property>
<property name="nonePasswordLogin">0</property>
<property name="bindIp">0.0.0.0</property>
<property name="frontWritQueueSize">2048</property>
<property name="charset">utf-8</property>
<property name="txIsolation">2</property>
<property name="processors">8</property>
<property name="idleTimeout">18000000</property>
<property name="sqlExecuteTimeout">300</property>
<property name="useSqlstat">0</property>
<property name="useGlobleTableCheck">0</property>
<property name="sequnceHandlerType">2</property>
<property name="defaultmaxLimit">100</property>
<property name="maxPacketSize">104857600</property>
</system>
<user name="app_imooc" defaultAccount="true">
<property name="password">PdvreoR7rtZepoGBQem6nTggPY8cmx8lts7itp7/bOiTj+s1OTSk5kpyo/FZl8z/jwqQT5qKaEsSAXM/OXwX7w==</property>
<property name="schemas">imooc_db</property>
</user>
</mycat:server>
创建时间:2021-09-26 17:21
넶浏览量:0