Mycat安装启动及主从读写分离简介

Mycat安装启动

Mycat使用Java编写,所以需要优先安装jdk,此处略过,本文使用版本如下:

如果未安装jdk,请提前下载:

https://www.oracle.com/cn/java/technologies/javase/javase8-archive-downloads.html

安装步骤我的Linux专栏有安装说明

成功如图所示:

切换到/opt目录,使用wget 下载压缩包

[root@mycat ~]# cd /opt/

[root@mycat opt]# wget http://dl.mycat.org.cn/1.6-RELEASE/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
--2021-06-14 21:54:21--  http://dl.mycat.org.cn/1.6-RELEASE/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
正在解析主机 dl.mycat.org.cn (dl.mycat.org.cn)... 210.51.26.184
正在连接 dl.mycat.org.cn (dl.mycat.org.cn)|210.51.26.184|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:15662280 (15M) [application/octet-stream]
正在保存至: “Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz”

100%[=====================================================================================================================================================>] 15,662,280  4.18MB/s 用时 4.5s   

2021-06-14 21:54:26 (3.32 MB/s) - 已保存 “Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz” [15662280/15662280])

[root@mycat opt]# ll |grep My
-rw-r--r--. 1 root root  15662280 10月 28 2016 Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
[root@mycat opt]# tar -zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz 
mycat/bin/wrapper-linux-ppc-64
mycat/bin/wrapper-linux-x86-64
mycat/bin/wrapper-linux-x86-32
mycat/bin/mycat
mycat/lib/zookeeper-3.4.6.jar
mycat/lib/jline-0.9.94.jar
mycat/lib/ehcache-core-2.6.11.jar
mycat/lib/log4j-1.2.17.jar
mycat/lib/fastjson-1.2.12.jar
mycat/lib/curator-client-2.11.0.jar
mycat/lib/joda-time-2.9.3.jar
mycat/lib/log4j-slf4j-impl-2.5.jar
mycat/lib/libwrapper-linux-x86-32.so
mycat/lib/netty-3.7.0.Final.jar
mycat/lib/druid-1.0.26.jar
mycat/lib/log4j-api-2.5.jar
mycat/lib/mapdb-1.0.7.jar
mycat/lib/slf4j-api-1.6.1.jar
mycat/lib/univocity-parsers-2.2.1.jar
mycat/lib/hamcrest-core-1.3.jar
mycat/lib/Mycat-server-1.6-RELEASE.jar
mycat/lib/objenesis-1.2.jar
mycat/lib/leveldb-api-0.7.jar
mycat/lib/hamcrest-library-1.3.jar
mycat/lib/wrapper.jar
mycat/lib/commons-lang-2.6.jar
mycat/lib/reflectasm-1.03.jar
mycat/lib/mongo-java-driver-2.11.4.jar
mycat/lib/guava-19.0.jar
mycat/lib/curator-recipes-2.11.0.jar
mycat/lib/curator-framework-2.11.0.jar
mycat/lib/libwrapper-linux-ppc-64.so
mycat/lib/log4j-core-2.5.jar
mycat/lib/leveldb-0.7.jar
mycat/lib/sequoiadb-driver-1.12.jar
mycat/lib/mysql-binlog-connector-java-0.4.1.jar
mycat/lib/kryo-2.10.jar
mycat/lib/jsr305-2.0.3.jar
mycat/lib/commons-collections-3.2.1.jar
mycat/lib/disruptor-3.3.4.jar
mycat/lib/log4j-1.2-api-2.5.jar
mycat/lib/velocity-1.7.jar
mycat/lib/libwrapper-linux-x86-64.so
mycat/lib/dom4j-1.6.1.jar
mycat/lib/minlog-1.2.jar
mycat/lib/asm-4.0.jar
mycat/conf/wrapper.conf
mycat/conf/
mycat/conf/zkconf/
mycat/conf/zkdownload/
mycat/conf/sequence_time_conf.properties
mycat/conf/sharding-by-enum.txt
mycat/conf/migrateTables.properties
mycat/conf/zkconf/sequence_time_conf.properties
mycat/conf/zkconf/sharding-by-enum.txt
mycat/conf/zkconf/ehcache.xml
mycat/conf/zkconf/index_to_charset.properties
mycat/conf/zkconf/partition-range-mod.txt
mycat/conf/zkconf/sequence_db_conf.properties
mycat/conf/zkconf/sequence_time_conf-mycat_fz_01.properties
mycat/conf/zkconf/cacheservice.properties
mycat/conf/zkconf/partition-hash-int.txt
mycat/conf/zkconf/autopartition-long.txt
mycat/conf/zkconf/server-mycat_fz_01.xml
mycat/conf/zkconf/auto-sharding-long.txt
mycat/conf/zkconf/rule.xml
mycat/conf/zkconf/auto-sharding-rang-mod.txt
mycat/conf/zkconf/sequence_distributed_conf.properties
mycat/conf/zkconf/sequence_distributed_conf-mycat_fz_01.properties
mycat/conf/zkconf/sequence_conf.properties
mycat/conf/zkconf/schema.xml
mycat/conf/zkconf/server.xml
mycat/conf/ehcache.xml
mycat/conf/index_to_charset.properties
mycat/conf/partition-range-mod.txt
mycat/conf/sequence_db_conf.properties
mycat/conf/cacheservice.properties
mycat/conf/partition-hash-int.txt
mycat/conf/autopartition-long.txt
mycat/conf/auto-sharding-long.txt
mycat/conf/rule.xml
mycat/conf/auto-sharding-rang-mod.txt
mycat/conf/sequence_distributed_conf.properties
mycat/conf/sequence_conf.properties
mycat/conf/myid.properties
mycat/conf/schema.xml
mycat/conf/zkdownload/auto-sharding-long.txt
mycat/conf/server.xml
mycat/version.txt
mycat/conf/log4j2.xml
mycat/bin/init_zk_data.sh
mycat/bin/startup_nowrap.sh
mycat/bin/dataMigrate.sh
mycat/bin/rehash.sh
mycat/logs/
mycat/catlet/

[root@mycat opt]# ll
总用量 30352
drwx--x--x. 4 root  root        28 6月   6 10:02 containerd
drwxr-xr-x. 5 10143 10143      129 4月   8 03:26 jdk1.8.0_291
-rw-r--r--. 1 root  root   2641920 5月  26 09:19 jdk-8u291-linux-x64.tar.gz
drwxr-xr-x. 7 root  root        85 6月  14 17:04 mycat
-rw-r--r--. 1 root  root  26030477 3月   3 08:54 Mycat-server-1.6.7.6-release-20210303094759-linux.tar.gz
-rwxrwxrwx. 2 root  root    397618 5月  26 13:40 nmon_x86_64_centos7
drwxrwxr-x. 6 root  root      4096 3月   2 14:11 redis-5.0.12
-rw-r--r--. 1 root  root   1995069 3月   2 14:22 redis-5.0.12.tar.gz
drwxr-xr-x. 2 root  root         6 10月 31 2018 rh
[root@mycat opt]# 

文件复制

将解压后的目录copy到 /usr/local目录中

[root@mycat opt]# cp -r mycat/ /usr/local/

[root@mycat opt]# ls /usr/local/
bin  etc  games  include  lib  lib64  libexec  mycat  sbin  share  src
[root@mycat opt]# 

查看mycat目录及mycat的配置文件目录

[root@mycat opt]# cd /usr/local/mycat/
[root@mycat mycat]# ls
bin  catlet  conf  lib  logs  version.txt
[root@mycat mycat]# cd conf/
[root@mycat conf]# ls
autopartition-long.txt       rule.xml
auto-sharding-long.txt       schema.xml
auto-sharding-rang-mod.txt   schema.xml.bak
cacheservice.properties      sequence_conf.properties
dbseq.sql                    sequence_db_conf.properties
dbseq - utf8mb4.sql          sequence_distributed_conf.properties
dnindex.properties           sequence_http_conf.properties
ehcache.xml                  sequence_time_conf.properties
index_to_charset.properties  server.xml
log4j2.xml                   server.xml.bak
migrateTables.properties     sharding-by-enum.txt
myid.properties              wrapper.conf
partition-hash-int.txt       zkconf
partition-range-mod.txt      zkdownload
[root@mycat conf]# 

Mycat安装启动及主从读写分离简介_第1张图片

其中主要的几个配置文件如下:

  • server.xml:是Mycat服务器参数调整和用户授权的配置文件。
  • schema.xml:是逻辑库定义和表以及分片定义的配置文件。
  • rule.xml: 是分片规则的配置文件,分片规则的具体一些参数信息单独存放为文件,也在这个目录下,配置文件修改需要重启MyCAT。
  • log4j.xml: 日志存放在logs/log中,每天一个文件,日志的配置是在conf/log4j.xml中,根据自己的需要可以调整输出级别为debug
  • debug级别下,会输出更多的信息,方便排查问题。
  • autopartition-long.txt,partition-hash-int.txt,sequence_conf.properties, sequence_db_conf.properties 分片相关的id分片规则配置文件
  • lib MyCAT自身的jar包或依赖的jar包的存放目录。
  • logs MyCAT日志的存放目录。日志存放在logs/log中,每天一个文件

 

修改server.xml

Mycat安装启动及主从读写分离简介_第2张图片

 

修改schema.xml

修改dataNode、dataHost





         
    

    

    
        select user()
        

        

            
        

    

 

启动

完整的启动过程如下

[root@mycat bin]# pwd
/usr/local/mycat/bin
[root@mycat bin]# ls
dataMigrate.sh  init_zk_data.sh  mycat  rehash.sh  startup_nowrap.sh  wrapper-linux-ppc-64  wrapper-linux-x86-32  wrapper-linux-x86-64
[root@mycat bin]# ./mycat 
Usage: ./mycat { console | start | stop | restart | status | dump }
[root@mycat bin]# ./mycat console
Running Mycat-server...
wrapper  | --> Wrapper Started as Console
wrapper  | Launching a JVM...
jvm 1    | Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=64M; support was removed in 8.0
jvm 1    | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
jvm 1    |   Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.
jvm 1    | 
jvm 1    | 2021-06-14 21:44:34,395 [INFO ][WrapperSimpleAppMain] total resouces of dataHost host1 is :2  (io.mycat.backend.datasource.PhysicalDBPool:PhysicalDBPool.java:100) 
jvm 1    | 2021-06-14 21:44:34,417 [INFO ][WrapperSimpleAppMain] create layer cache pool TableID2DataNodeCache of type encache ,default cache size 10000 ,default expire seconds18000  (io.mycat.cache.CacheService:CacheService.java:125) 
jvm 1    | 2021-06-14 21:44:34,419 [INFO ][WrapperSimpleAppMain] create child Cache: TESTDB_ORDERS for layered cache TableID2DataNodeCache, size 50000, expire seconds 18000  (io.mycat.cache.DefaultLayedCachePool:DefaultLayedCachePool.java:80) 
jvm 1    | 2021-06-14 21:44:40,604 [INFO ][WrapperSimpleAppMain] dyna class load from ./catlet,and auto check for class file modified every 60 seconds  (io.mycat.config.classloader.DynaClassLoader:DynaClassLoader.java:34) 
jvm 1    | 2021-06-14 21:44:40,605 [INFO ][WrapperSimpleAppMain] ===============================================  (io.mycat.MycatServer:MycatServer.java:266) 
jvm 1    | 2021-06-14 21:44:40,605 [INFO ][WrapperSimpleAppMain] MyCat is ready to startup ...  (io.mycat.MycatServer:MycatServer.java:267) 
jvm 1    | 2021-06-14 21:44:40,606 [INFO ][WrapperSimpleAppMain] Startup processors ...,total processors:4,aio thread pool size:8    
jvm 1    |  each process allocated socket buffer pool  bytes ,a page size:2097152  a page's chunk number(PageSize/ChunkSize) is:512  buffer page's number is:80  (io.mycat.MycatServer:MycatServer.java:279) 
jvm 1    | 2021-06-14 21:44:40,606 [INFO ][WrapperSimpleAppMain] sysconfig params:SystemConfig [processorBufferLocalPercent=100, frontSocketSoRcvbuf=1048576, frontSocketSoSndbuf=4194304, backSocketSoRcvbuf=4194304, backSocketSoSndbuf=1048576, frontSocketNoDelay=1, backSocketNoDelay=1, maxStringLiteralLength=65535, frontWriteQueueSize=2048, bindIp=0.0.0.0, serverPort=8066, managerPort=9066, charset=utf8, processors=4, processorExecutor=8, timerExecutor=2, managerExecutor=2, idleTimeout=1800000, catletClassCheckSeconds=60, sqlExecuteTimeout=300, processorCheckPeriod=1000, dataNodeIdleCheckPeriod=300000, dataNodeHeartbeatPeriod=10000, clusterHeartbeatUser=_HEARTBEAT_USER_, clusterHeartbeatPass=_HEARTBEAT_PASS_, clusterHeartbeatPeriod=5000, clusterHeartbeatTimeout=10000, clusterHeartbeatRetry=10, txIsolation=3, parserCommentVersion=50148, sqlRecordCount=10, bufferPoolPageSize=2097152, bufferPoolChunkSize=4096, bufferPoolPageNumber=80, maxResultSet=524288, bigResultSizeSqlCount=10, bufferUsagePercent=80, flowControlRejectStrategy=0, clearBigSqLResultSetMapMs=600000, defaultMaxLimit=100, sequnceHandlerType=2, sqlInterceptor=io.mycat.server.interceptor.impl.DefaultSqlInterceptor, sqlInterceptorType=select, sqlInterceptorFile=/usr/local/mycat/logs/sql.txt, mutiNodeLimitType=0, mutiNodePatchSize=100, defaultSqlParser=druidparser, usingAIO=0, packetHeaderSize=4, maxPacketSize=16777216, mycatNodeId=1]  (io.mycat.MycatServer:MycatServer.java:280) 
jvm 1    | log4j:WARN No appenders could be found for logger (io.mycat.memory.MyCatMemory).
jvm 1    | log4j:WARN Please initialize the log4j system properly.
jvm 1    | log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
jvm 1    | 2021-06-14 21:44:41,495 [INFO ][WrapperSimpleAppMain] using nio network handler   (io.mycat.MycatServer:MycatServer.java:381) 
jvm 1    | 2021-06-14 21:44:41,541 [INFO ][WrapperSimpleAppMain] $_MyCatManager is started and listening on 9066  (io.mycat.MycatServer:MycatServer.java:397) 
jvm 1    | 2021-06-14 21:44:41,543 [INFO ][WrapperSimpleAppMain] $_MyCatServer is started and listening on 8066  (io.mycat.MycatServer:MycatServer.java:401) 
jvm 1    | 2021-06-14 21:44:41,544 [INFO ][WrapperSimpleAppMain] ===============================================  (io.mycat.MycatServer:MycatServer.java:403) 
jvm 1    | 2021-06-14 21:44:41,544 [INFO ][WrapperSimpleAppMain] Initialize dataHost ...  (io.mycat.MycatServer:MycatServer.java:407) 
jvm 1    | 2021-06-14 21:44:41,544 [INFO ][WrapperSimpleAppMain] init backend myqsl source ,create connections total 10 for hostM1 index :0  (io.mycat.backend.datasource.PhysicalDBPool:PhysicalDBPool.java:294) 
jvm 1    | 2021-06-14 21:44:41,551 [INFO ][WrapperSimpleAppMain] no ilde connection in pool,create new connection for hostM1 of schema testdb  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413) 
jvm 1    | 2021-06-14 21:44:41,555 [INFO ][WrapperSimpleAppMain] no ilde connection in pool,create new connection for hostM1 of schema testdb  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413) 
jvm 1    | 2021-06-14 21:44:41,560 [INFO ][WrapperSimpleAppMain] no ilde connection in pool,create new connection for hostM1 of schema testdb  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413) 
jvm 1    | 2021-06-14 21:44:41,564 [INFO ][WrapperSimpleAppMain] no ilde connection in pool,create new connection for hostM1 of schema testdb  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413) 
jvm 1    | 2021-06-14 21:44:41,633 [INFO ][WrapperSimpleAppMain] no ilde connection in pool,create new connection for hostM1 of schema testdb  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413) 
jvm 1    | 2021-06-14 21:44:41,650 [INFO ][WrapperSimpleAppMain] no ilde connection in pool,create new connection for hostM1 of schema testdb  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413) 
jvm 1    | 2021-06-14 21:44:41,653 [INFO ][WrapperSimpleAppMain] no ilde connection in pool,create new connection for hostM1 of schema testdb  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413) 
jvm 1    | 2021-06-14 21:44:41,677 [INFO ][WrapperSimpleAppMain] no ilde connection in pool,create new connection for hostM1 of schema testdb  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413) 
jvm 1    | 2021-06-14 21:44:41,680 [INFO ][WrapperSimpleAppMain] no ilde connection in pool,create new connection for hostM1 of schema testdb  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413) 
jvm 1    | 2021-06-14 21:44:41,681 [INFO ][WrapperSimpleAppMain] no ilde connection in pool,create new connection for hostM1 of schema testdb  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413) 
jvm 1    | 2021-06-14 21:44:41,905 [INFO ][$_NIOREACTOR-3-RW] connected successfuly MySQLConnection [id=3, lastTime=1623678281905, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=false, threadId=12, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=172.17.0.2, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67) 
jvm 1    | 2021-06-14 21:44:41,905 [INFO ][$_NIOREACTOR-1-RW] connected successfuly MySQLConnection [id=1, lastTime=1623678281904, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=false, threadId=21, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=172.17.0.2, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67) 
jvm 1    | 2021-06-14 21:44:41,905 [INFO ][$_NIOREACTOR-2-RW] connected successfuly MySQLConnection [id=6, lastTime=1623678281905, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=false, threadId=20, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=172.17.0.2, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67) 
jvm 1    | 2021-06-14 21:44:41,906 [INFO ][$_NIOREACTOR-3-RW] connected successfuly MySQLConnection [id=7, lastTime=1623678281905, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=false, threadId=17, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=172.17.0.2, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67) 
jvm 1    | 2021-06-14 21:44:41,906 [INFO ][$_NIOREACTOR-0-RW] connected successfuly MySQLConnection [id=4, lastTime=1623678281905, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=false, threadId=15, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=172.17.0.2, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67) 
jvm 1    | 2021-06-14 21:44:41,906 [INFO ][$_NIOREACTOR-2-RW] connected successfuly MySQLConnection [id=2, lastTime=1623678281906, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=false, threadId=14, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=172.17.0.2, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67) 
jvm 1    | 2021-06-14 21:44:41,906 [INFO ][$_NIOREACTOR-1-RW] connected successfuly MySQLConnection [id=9, lastTime=1623678281906, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=false, threadId=13, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=172.17.0.2, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67) 
jvm 1    | 2021-06-14 21:44:41,906 [INFO ][$_NIOREACTOR-1-RW] connected successfuly MySQLConnection [id=5, lastTime=1623678281906, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=false, threadId=19, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=172.17.0.2, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67) 
jvm 1    | 2021-06-14 21:44:41,907 [INFO ][$_NIOREACTOR-0-RW] connected successfuly MySQLConnection [id=8, lastTime=1623678281907, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=false, threadId=18, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=172.17.0.2, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67) 
jvm 1    | 2021-06-14 21:44:41,909 [INFO ][$_NIOREACTOR-2-RW] connected successfuly MySQLConnection [id=10, lastTime=1623678281909, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=false, threadId=16, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=172.17.0.2, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67) 
jvm 1    | 2021-06-14 21:44:41,985 [INFO ][WrapperSimpleAppMain] init result :finished 10 success 10 target count:10  (io.mycat.backend.datasource.PhysicalDBPool:PhysicalDBPool.java:319) 
jvm 1    | 2021-06-14 21:44:41,986 [INFO ][WrapperSimpleAppMain] host1 index:0 init success  (io.mycat.backend.datasource.PhysicalDBPool:PhysicalDBPool.java:265) 
jvm 1    | 2021-06-14 21:44:41,986 [INFO ][WrapperSimpleAppMain] save DataHost index  host1 cur index 0  (io.mycat.MycatServer:MycatServer.java:604) 
jvm 1    | 2021-06-14 21:44:42,056 [INFO ][Timer0] create connections ,because idle connection not enough ,cur is 0, minCon is 10 for hostS1  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:299) 
jvm 1    | 2021-06-14 21:44:42,127 [INFO ][$_NIOREACTOR-3-RW] connectionAcquired MySQLConnection [id=11, lastTime=1623678282126, user=root, schema=testdb, old shema=testdb, borrowed=false, fromSlaveDB=true, threadId=15, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=172.17.0.3, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.handler.NewConnectionRespHandler:NewConnectionRespHandler.java:45) 
jvm 1    | 2021-06-14 21:44:42,149 [INFO ][$_NIOREACTOR-0-RW] connectionAcquired MySQLConnection [id=12, lastTime=1623678282149, user=root, schema=testdb, old shema=testdb, borrowed=false, fromSlaveDB=true, threadId=16, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=172.17.0.3, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.handler.NewConnectionRespHandler:NewConnectionRespHandler.java:45) 
jvm 1    | 2021-06-14 21:44:42,149 [INFO ][$_NIOREACTOR-1-RW] connectionAcquired MySQLConnection [id=13, lastTime=1623678282149, user=root, schema=testdb, old shema=testdb, borrowed=false, fromSlaveDB=true, threadId=17, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=172.17.0.3, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.handler.NewConnectionRespHandler:NewConnectionRespHandler.java:45) 
jvm 1    | MyCAT Server startup successfully. see logs in logs/mycat.log
jvm 1    | 2021-06-14 21:49:42,022 [INFO ][Timer1] create connections ,because idle connection not enough ,cur is 3, minCon is 10 for hostS1  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:299) 
jvm 1    | 2021-06-14 21:49:42,040 [INFO ][$_NIOREACTOR-3-RW] connectionAcquired MySQLConnection [id=15, lastTime=1623678582039, user=root, schema=testdb, old shema=testdb, borrowed=false, fromSlaveDB=true, threadId=18, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=172.17.0.3, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.handler.NewConnectionRespHandler:NewConnectionRespHandler.java:45) 
jvm 1    | 2021-06-14 21:49:42,040 [INFO ][$_NIOREACTOR-2-RW] connectionAcquired MySQLConnection [id=14, lastTime=1623678582039, user=root, schema=testdb, old shema=testdb, borrowed=false, fromSlaveDB=true, threadId=19, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=172.17.0.3, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.handler.NewConnectionRespHandler:NewConnectionRespHandler.java:45) 
jvm 1    | 2021-06-14 21:49:52,518 [INFO ][$_NIOREACTOR-0-RW] [thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=1,host=127.0.0.1,port=9066,schema=null]'mycat' login success  (io.mycat.net.handler.FrontendAuthenticator:FrontendAuthenticator.java:194) 
jvm 1    | 2021-06-14 21:52:56,495 [INFO ][$_NIOREACTOR-0-RW] close connection,reason:quit cmd ,[thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=1,host=127.0.0.1,port=9066,schema=null]  (io.mycat.net.AbstractConnection:AbstractConnection.java:508) 
jvm 1    | 2021-06-14 21:54:42,022 [INFO ][Timer1] create connections ,because idle connection not enough ,cur is 5, minCon is 10 for hostS1  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:299) 
jvm 1    | 2021-06-14 21:54:42,049 [INFO ][$_NIOREACTOR-1-RW] connectionAcquired MySQLConnection [id=16, lastTime=1623678882039, user=root, schema=testdb, old shema=testdb, borrowed=false, fromSlaveDB=true, threadId=20, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=172.17.0.3, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.handler.NewConnectionRespHandler:NewConnectionRespHandler.java:45) 

Mycat登录

使用9066端口登录后台管理窗口,此登录方式用于管理维护Mycat(管理员本机机器)

[root@mycat opt]# mysql -umycat -p123456 -h 127.0.0.1 -P 9066
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (monitor)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> 

主从读写分离

分别向主数据库 和从数据库 插入不一样的数据

在mycat客户端查询数据,发现都是写数据库的内容

修改Mycat的配置文件schema.xml的节点的balance属性

  1. 当balance=0 时,不开启读写分离,所有读操作都发生在当前的writeHost上
  2. 当balance=1 ,所有读操作都随机发送到当前的writeHost对应的readHost和备用的writeHos都参与select语句的负载均衡,简单的说当双主双从模式(M1->S1 ,M2-S2 M2和M2互为主备)
  3. 当balance=2,所有的读操作都随机发送到所有的writeHost,readHost上
  4. 当balance=3 ,所有的读操作都只发送到writeHost(db1)的readHost(db2)上

生产当中应该使用 1或者3,此处为了演示设置balance="2"





    
    

    



    
        select user()

        
        
            
            
        
    

 

 

双主双从读写分离请看下节!!!!!

双主双从读写分离请看下节!!!!!

双主双从读写分离请看下节!!!!!

双主双从读写分离请看下节!!!!!

双主双从读写分离请看下节!!!!!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(Mycat,mycat,mysql,linux)