dokcer搭建mycat
- 生成mycat镜像
1、去mycat官网下载安装包,官网地址为http://www.mycat.org.cn/。
2、下载jdk安装包,以jdk1.8为例。
3、在服务器新建目录,目录名称自己定,这里以mycat目录为例,将上面两步下载的安装包放入目录当中,并解压。
4、在mycat目录中创建Dockefile文件,文件内容:
FROM centos
COPY mycat /opt/mycat1.6
COPY jdk1.8.0_231 /opt/jdk1.8
ENV JAVA_HOME /opt/jdk1.8
ENV MYCAT_HOME /opt/mycat1.6
ENV PATH /usr/bin:$JAVA_HOME/bin:$MYCAT_HOME/bin:$PATH
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
EXPOSE 8066 9066
RUN chmod -R 777 /opt/mycat1.6/bin
CMD ["./opt/mycat1.6/bin/mycat", "console"]
5、通过命令构建镜像,在mycat目录中执行命令 docker build -t mycat-server:1.6 .
mycat-server指定镜像名称,1.6为tag标签,最后有个点号(.)标识当前目录。
- docker部署mycat
将解压后的mycat安装包的conf目录复制一份至/mycat/conf目录,修改wrapper.conf、server.xml、schema.xml配置文件。
1、wrapper.conf配置
#********************************************************************
# Wrapper Properties
#********************************************************************
# Java Application
wrapper.java.command=/opt/jdk1.8/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=2G
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=0
# 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=0
# 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
2、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="useSqlStat">0</property> <!-- 1为开启实时统计、0为关闭 -->
<property name="useGlobleTableCheck">0</property> <!-- 1为开启全加班一致性检测、0为关闭 -->
<property name="sequnceHandlerType">2</property>
<!-- <property name="useCompression">1</property>--> <!--1为开启mysql压缩协议-->
<!-- <property name="fakeMySQLVersion">5.6.20</property>--> <!--设置模拟的MySQL版本号-->
<!-- <property name="processorBufferChunk">40960</property> -->
<!--
<property name="processors">1</property>
<property name="processorExecutor">32</property>
-->
<!--默认为type 0: DirectByteBufferPool | type 1 ByteBufferArena-->
<property name="processorBufferPoolType">0</property>
<!--默认是65535 64K 用于sql解析时最大文本长度 -->
<!--<property name="maxStringLiteralLength">65535</property>-->
<!--<property name="sequnceHandlerType">0</property>-->
<!--<property name="backSocketNoDelay">1</property>-->
<!--<property name="frontSocketNoDelay">1</property>-->
<!--<property name="processorExecutor">16</property>-->
<!--
<property name="serverPort">8066</property> <property name="managerPort">9066</property>
<property name="idleTimeout">300000</property> <property name="bindIp">0.0.0.0</property>
<property name="frontWriteQueueSize">4096</property> <property name="processors">32</property> -->
<!--分布式事务开关,0为不过滤分布式事务,1为过滤分布式事务(如果分布式事务内只涉及全局表,则不过滤),2为不过滤分布式事务,但是记录分布式事务日志-->
<property name="handleDistributedTransactions">0</property>
<!--
off heap for merge/order/group/limit 1开启 0关闭
-->
<property name="useOffHeapForMerge">1</property>
<!--
单位为m
-->
<property name="memoryPageSize">1m</property>
<!--
单位为k
-->
<property name="spillsFileBufferSize">1k</property>
<property name="useStreamOutput">0</property>
<!--
单位为m
-->
<property name="systemReserveMemorySize">384m</property>
<!--是否采用zookeeper协调切换 -->
<property name="useZKSwitch">true</property>
</system>
<!-- 全局SQL防火墙设置 -->
<!--
<firewall>
<whitehost>
<host host="127.0.0.1" user="mycat"/>
<host host="127.0.0.2" user="mycat"/>
</whitehost>
<blacklist check="false">
</blacklist>
</firewall>
-->
<user name="easted">
<property name="password">snkEas4532T</property>
<property name="schemas">BASE-ACTIVITI,BASE-APP-REGION,BASE-DATA-DICT,BASE-FIXED-ASSETS,BASE-GATEWAY,BASE-LOGISTICS,BASE-MANAGE,BASE-MESSAGE,BASE-OFFICE-SPACE,BASE-UAA</property>
<!-- 表级 DML 权限设置 -->
<!--
<privileges check="false">
<schema name="TESTDB" dml="0110" >
<table name="tb01" dml="0000"></table>
<table name="tb02" dml="1111"></table>
</schema>
</privileges>
-->
</user>
</mycat:server>
3、schema.xml配置
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="BASE-ACTIVITI" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn1" />
<schema name="BASE-APP-REGION" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn2" />
<schema name="BASE-DATA-DICT" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn3" />
<schema name="BASE-FIXED-ASSETS" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn4" />
<schema name="BASE-GATEWAY" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn5" />
<schema name="BASE-LOGISTICS" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn6" />
<schema name="BASE-MANAGE" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn7" />
<schema name="BASE-MESSAGE" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn8" />
<schema name="BASE-OFFICE-SPACE" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn9" />
<schema name="BASE-UAA" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn10" />
<!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743"
/> -->
<dataNode name="dn1" dataHost="host" database="base-activiti" />
<dataNode name="dn2" dataHost="host" database="base-app-region" />
<dataNode name="dn3" dataHost="host" database="base-data-dict" />
<dataNode name="dn4" dataHost="host" database="base-fixed-assets" />
<dataNode name="dn5" dataHost="host" database="base-gateway" />
<dataNode name="dn6" dataHost="host" database="base-logistics" />
<dataNode name="dn7" dataHost="host" database="base-manage" />
<dataNode name="dn8" dataHost="host" database="base-message" />
<dataNode name="dn9" dataHost="host" database="base-office-space" />
<dataNode name="dn10" dataHost="host" database="base-uaa" />
<dataHost name="host" maxCon="1000" minCon="10" balance="3"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="hostM1" url="192.168.1.249:3306" user="easted"
password="snkEas4532T,">
<!-- can have multi read hosts -->
<readHost host="hostS1" url="192.168.1.245:3306" user="root" password="123456" />
</writeHost>
</dataHost>
</mycat:schema>
执行dokcer命令,docker run --name mycat-server -v /mycat/logs:/opt/mycat1.6/logs -v /mycat/conf:/opt/mycat1.6/conf -p 8066:8066 -p 9066:9066 -d mycat-server:1.6

浙公网安备 33010602011771号