资料:
name | address |
---|---|
Mycat权威指南 | http://www.mycat.io/document/mycat-definitive-guide.pdf |
GitHub | https://github.com/MyCATApache/Mycat-Server |
文档 | https://github.com/MyCATApache/Mycat-doc |
前置:
centos7、jdk-1.7以上、下载并解压Mycat-1.6.5、两台Mysql-5.7配置主从复制
配置:
wrapper.conf:
#********************************************************************
# Wrapper Properties
#********************************************************************
# Java Application
wrapper.java.command=/usr/local/jdk/bin/java
wrapper.working.dir=..
# Java Main class. This class must implement the WrapperListener interface
# or guarantee that the WrapperManager class is initialized. Helper
# classes are provided to do this for you. See the Integration section
# of the documentation for details.
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
set.default.REPO_DIR=lib
set.APP_BASE=.
# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
wrapper.java.classpath.1=lib/wrapper.jar
wrapper.java.classpath.2=conf
wrapper.java.classpath.3=%REPO_DIR%/*
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=lib
# Java Additional Parameters
#wrapper.java.additional.1=
wrapper.java.additional.1=-DMYCAT_HOME=.
wrapper.java.additional.2=-server
#wrapper.java.additional.3=-XX:MaxPermSize=64M
wrapper.java.additional.4=-XX:+AggressiveOpts
wrapper.java.additional.5=-XX:MaxDirectMemorySize=4G
wrapper.java.additional.6=-Dcom.sun.management.jmxremote
wrapper.java.additional.7=-Dcom.sun.management.jmxremote.port=1984
wrapper.java.additional.8=-Dcom.sun.management.jmxremote.authenticate=false
wrapper.java.additional.9=-Dcom.sun.management.jmxremote.ssl=false
wrapper.java.additional.10=-Xmx4G
wrapper.java.additional.11=-Xms1G
# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3
# Maximum Java Heap Size (in MB)
#wrapper.java.maxmemory=64
# Application parameters. Add parameters as needed starting from 1
wrapper.app.parameter.1=io.mycat.MycatStartup
wrapper.app.parameter.2=start
#********************************************************************
# Wrapper Logging Properties
#********************************************************************
# Format of output for the console. (See docs for formats)
wrapper.console.format=PM
# Log Level for console output. (See docs for log levels)
wrapper.console.loglevel=INFO
# Log file to use for wrapper output logging.
wrapper.logfile=logs/wrapper.log
# Format of output for the log file. (See docs for formats)
wrapper.logfile.format=LPTM
# Log Level for log file output. (See docs for log levels)
wrapper.logfile.loglevel=INFO
# Maximum size that the log file will be allowed to grow to before
# the log is rolled. Size is specified in bytes. The default value
# of 0, disables log rolling. May abbreviate with the 'k' (kb) or
# 'm' (mb) suffix. For example: 10m = 10 megabytes.
wrapper.logfile.maxsize=512m
# Maximum number of rolled log files which will be allowed before old
# files are deleted. The default value of 0 implies no limit.
wrapper.logfile.maxfiles=30
# Log Level for sys/event log output. (See docs for log levels)
wrapper.syslog.loglevel=NONE
#********************************************************************
# Wrapper Windows Properties
#********************************************************************
# Title to use when running as a console
wrapper.console.title=Mycat-server
#********************************************************************
# Wrapper Windows NT/2000/XP Service Properties
#********************************************************************
# WARNING - Do not modify any of these properties when an application
# using this configuration file has been installed as a service.
# Please uninstall the service before modifying this section. The
# service can then be reinstalled.
# Name of the service
wrapper.ntservice.name=mycat
# Display name of the service
wrapper.ntservice.displayname=Mycat-server
# Description of the service
wrapper.ntservice.description=The project of Mycat-server
# Service dependencies. Add dependencies as needed starting from 1
wrapper.ntservice.dependency.1=
# Mode in which the service is installed. AUTO_START or DEMAND_START
wrapper.ntservice.starttype=AUTO_START
# Allow the service to interact with the desktop.
wrapper.ntservice.interactive=false
wrapper.ping.timeout=120
configuration.directory.in.classpath.first=conf
schema.xml:
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="common_service" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn1">
<!-- 这里不配置,代表所有的表分片到dn1节点-->
</schema>
<schema name="oa_pri" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn2">
</schema>
<dataNode name="dn1" dataHost="mysqlM" database="common_service" />
<dataNode name="dn2" dataHost="mysqlM" database="oa_pri" />
<dataHost name="mysqlM" maxCon="1000" minCon="10" balance="1"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="hostM1" url="10.159.226.31:3306" user="root"
password="密码">
<!-- can have multi read hosts -->
<readHost host="hostS2" url="10.159.226.32:3306" user="root" password="密码" />
</writeHost>
</dataHost>
</mycat:schema>
schema:逻辑库,配置的库才会在Mycat显示出来,用户不需要关心mysql的库是什么。逻辑库和mysql的库不太一样
dataNode:定义的数据分片,也是逻辑上的。这里可以配置成同一个MySQL实例的不同数据库,也可以配置成不同MySQL实例的同名数据库或者不同名。
dataHost:定义MySQL实例,指的是物理机上的MySQL。
具体属性概念请参考官网
server.xml添加以下配置:
<user name="用户名">
<property name="password">密码</property>
<property name="schemas">oa_pri,common_service</property>
</user>
命令:
mycat { console | start | stop | restart | status | dump }