k8s环境部署mycat集群

k8s环境部署mycat集群

一、通过yaml部署mycat集群
1、mycat-config.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: mycat-config
  namespace: mysql
  labels:
    app: mycat
data:
  schema.xml: "<?xml version=\"1.0\"?>\n<!DOCTYPE mycat:schema SYSTEM \"schema.dtd\">\n<mycat:schema
    xmlns:mycat=\"http://io.mycat/\">\n    <schema name=\"database\" checkSQLschema=\"false\"
    sqlMaxLimit=\"100\" dataNode=\"dn1\">\n    </schema>\n    <schema name=\"database1\" checkSQLschema=\"false\"
    sqlMaxLimit=\"100\" dataNode=\"dn2\">\n    </schema>\n    <dataNode name=\"dn1\"
    dataHost=\"localhost01\" database=\"database\" />\n    <dataNode name=\"dn2\"
    dataHost=\"localhost01\" database=\"database1\" />\n    <dataHost name=\"localhost01\"
    maxCon=\"200\" minCon=\"20\" balance=\"1\" writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\"
    switchType=\"1\"  slaveThreshold=\"100\">\n             <heartbeat>select user()</heartbeat>\n
    \           <writeHost host=\"hostM1\" url=\"mysql-0.mysql.mysql:3306\" user=\"root\"
    password=\"\">\n            <readHost host=\"hostS2\" url=\"mysql-read.mysql:3306\"
    user=\"root\" password=\"\" />\n             </writeHost> \n             <writeHost
    host=\"hostS1\" url=\"mysql-0.mysql.mysql:3306\" user=\"root\" password=\"\"
    />\n         </dataHost>\n</mycat:schema>\n"
  server.xml: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!-- - - Licensed under
    the Apache License, Version 2.0 (the \"License\"); \n\t- you may not use this
    file except in compliance with the License. - You \n\tmay obtain a copy of the
    License at - - http://www.apache.org/licenses/LICENSE-2.0 \n\t- - Unless required
    by applicable law or agreed to in writing, software - \n\tdistributed under the
    License is distributed on an \"AS IS\" BASIS, - WITHOUT \n\tWARRANTIES OR CONDITIONS
    OF ANY KIND, either express or implied. - See the \n\tLicense for the specific
    language governing permissions and - limitations \n\tunder the License. -->\n<!DOCTYPE
    mycat:server SYSTEM \"server.dtd\">\n<mycat:server xmlns:mycat=\"http://io.mycat/\">\n\t<system>\n\t<property
    name=\"nonePasswordLogin\">0</property> <!-- 0为需要密码登陆、1为不需要密码登陆 ,默认为0,设置为1则需要指定默认账户-->\n\t<property
    name=\"useHandshakeV10\">1</property>\n\t<property name=\"useSqlStat\">0</property>
    \ <!-- 1为开启实时统计、0为关闭 -->\n\t<property name=\"useGlobleTableCheck\">0</property>
    \ <!-- 1为开启全加班一致性检测、0为关闭 -->\n\n\t\t<property name=\"sequnceHandlerType\">2</property>\n\t<property
    name=\"subqueryRelationshipCheck\">false</property> <!-- 子查询中存在关联查询的情况下,检查关联字段中是否有分片字段
    .默认 false -->\n      <!--  <property name=\"useCompression\">1</property>--> <!--1为开启mysql压缩协议-->\n
    \       <!--  <property name=\"fakeMySQLVersion\">5.6.20</property>--> <!--设置模拟的MySQL版本号-->\n\t<!--
    <property name=\"processorBufferChunk\">40960</property> -->\n\t<!-- \n\t<property
    name=\"processors\">1</property> \n\t<property name=\"processorExecutor\">32</property>
    \n\t -->\n        <!--默认为type 0: DirectByteBufferPool | type 1 ByteBufferArena
    | type 2 NettyBufferPool -->\n\t\t<property name=\"processorBufferPoolType\">0</property>\n\t\t<!--默认是65535
    64K 用于sql解析时最大文本长度 -->\n\t\t<!--<property name=\"maxStringLiteralLength\">65535</property>-->\n\t\t<!--<property
    name=\"sequnceHandlerType\">0</property>-->\n\t\t<!--<property name=\"backSocketNoDelay\">1</property>-->\n\t\t<!--<property
    name=\"frontSocketNoDelay\">1</property>-->\n\t\t<!--<property name=\"processorExecutor\">16</property>-->\n\t\t<!--\n\t\t\t<property
    name=\"serverPort\">8066</property> <property name=\"managerPort\">9066</property>
    \n\t\t\t<property name=\"idleTimeout\">300000</property> <property name=\"bindIp\">0.0.0.0</property>
    \n\t\t\t<property name=\"frontWriteQueueSize\">4096</property> <property name=\"processors\">32</property>
    -->\n\t\t<!--分布式事务开关,0为不过滤分布式事务,1为过滤分布式事务(如果分布式事务内只涉及全局表,则不过滤),2为不过滤分布式事务,但是记录分布式事务日志-->\n\t\t<property
    name=\"handleDistributedTransactions\">0</property>\n\t\t\n\t\t\t<!--\n\t\t\toff
    heap for merge/order/group/limit      1开启   0关闭\n\t\t-->\n\t\t<property name=\"useOffHeapForMerge\">1</property>\n\n\t\t<!--\n\t\t\t单位为m\n\t\t-->\n
    \       <property name=\"memoryPageSize\">64k</property>\n\n\t\t<!--\n\t\t\t单位为k\n\t\t-->\n\t\t<property
    name=\"spillsFileBufferSize\">1k</property>\n\n\t\t<property name=\"useStreamOutput\">0</property>\n\n\t\t<!--\n\t\t\t单位为m\n\t\t-->\n\t\t<property
    name=\"systemReserveMemorySize\">384m</property>\n\n\n\t\t<!--是否采用zookeeper协调切换
    \ -->\n\t\t<property name=\"useZKSwitch\">false</property>\n\n\t\t<!-- XA Recovery
    Log日志路径 -->\n\t\t<!--<property name=\"XARecoveryLogBaseDir\">./</property>-->\n\n\t\t<!--
    XA Recovery Log日志名称 -->\n\t\t<!--<property name=\"XARecoveryLogBaseName\">tmlog</property>-->\n\t\t<!--如果为
    true的话 严格遵守隔离级别,不会在仅仅只有select语句的时候在事务中切换连接-->\n\t\t<property name=\"strictTxIsolation\">false</property>\n\t\t\n\t\t<property
    name=\"useZKSwitch\">true</property>\n\t\t\n\t</system>\n\t\n\t<!-- 全局SQL防火墙设置
    -->\n\t<!--白名单可以使用通配符%或着*-->\n\t<!--例如<host host=\"127.0.0.*\" user=\"root\"/>-->\n\t<!--例如<host
    host=\"127.0.*\" user=\"root\"/>-->\n\t<!--例如<host host=\"127.*\" user=\"root\"/>-->\n\t<!--例如<host
    host=\"1*7.*\" user=\"root\"/>-->\n\t<!--这些配置情况下对于127.0.0.1都能以root账户登录-->\n\t<!--\n\t<firewall>\n\t
    \  <whitehost>\n\t      <host host=\"1*7.0.0.*\" user=\"root\"/>\n\t   </whitehost>\n
    \      <blacklist check=\"false\">\n       </blacklist>\n\t</firewall>\n\t-->\n\n\t<user
    name=\"root\" defaultAccount=\"true\">\n\t\t<property name=\"password\">123456</property>\n\t\t<property
    name=\"schemas\">database,database1</property>\n\t\t\n\t\t<!-- 表级 DML 权限设置 -->\n\t\t<!-- \t\t\n\t\t<privileges
    check=\"false\">\n\t\t\t<schema name=\"TESTDB\" dml=\"0110\" >\n\t\t\t\t<table
    name=\"tb01\" dml=\"0000\"></table>\n\t\t\t\t<table name=\"tb02\" dml=\"1111\"></table>\n\t\t\t</schema>\n\t\t</privileges>\t\t\n\t\t
    -->\n\t</user>\n\n\t<user name=\"user\">\n\t\t<property name=\"password\">123456</property>\n\t\t<property
    name=\"schemas\">database,database1</property>\n\t\t<property name=\"readOnly\">true</property>\n\t</user>\n\n</mycat:server>\n"
  wrapper.conf: |
    #********************************************************************
    # Wrapper Properties
    #********************************************************************
    # Java Application
    wrapper.java.command=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:+AggressiveOpts
    wrapper.java.additional.4=-XX:MaxDirectMemorySize=4G
    wrapper.java.additional.5=-Dcom.sun.management.jmxremote
    wrapper.java.additional.6=-Dcom.sun.management.jmxremote.port=1984
    wrapper.java.additional.7=-Dcom.sun.management.jmxremote.authenticate=false
    wrapper.java.additional.8=-Dcom.sun.management.jmxremote.ssl=false
    wrapper.java.additional.9=-Xmx4G
    wrapper.java.additional.10=-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

2、mycat-serivce.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: mycat
  name: mycat
  namespace: mysql
spec:
  ports:
  - name: mycat
    port: 8066
  clusterIP: None
  selector:
    app: mycat

3、mycat-stateFulSet.yaml

apiVersion: apps/v1
kind: StatefulSet
metadata:
  annotations:
  labels:
    app: mycat
  name: mycat
  namespace: mysql
spec:
  serviceName: mycat
  replicas: 2
  selector:
    matchLabels:
      app: mycat
  template:
    metadata:
      annotations:
      labels:
        app: mycat
    spec:
      containers:
        - image: "manondidi/mycat:1.6.7.5"
          imagePullPolicy: IfNotPresent
          name: mycat
          ports:
          - containerPort: 8066
            protocol: TCP
            name: mycat
          volumeMounts:
          - name: data
            mountPath: /usr/local/mycat/logs
          - name: configmap-mycat
            mountPath: /usr/local/mycat/conf/server.xml
            subPath: server.xml
          - name: configmap-mycat
            mountPath: /usr/local/mycat/conf/schema.xml
            subPath: schema.xml
          - name: configmap-mycat
            mountPath: /usr/local/mycat/conf/wrapper.conf
            subPath: wrapper.conf
      volumes:
      - name: configmap-mycat
        configMap:
          name: mycat-config
          items:
          - key: server.xml
            path: server.xml
          - key: schema.xml
            path: schema.xml
          - key: wrapper.conf
            path: wrapper.conf  
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 5Gi

二、测试mycat可用性
1、进入mysql容器验证mycat

root@mysql-0:/# mysql -hmycat.mysql -P8066 -uroot -p -e "show databases;"
Enter password: 
+----------+
| DATABASE |
+----------+
| database |
| database1 |
+----------+
root@mysql-0:/# mysql -hmycat.mysql -P8066 -uroot -p -e "show variables like 'server_id';"
Enter password: 
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id     | 100   |
+---------------+-------+
root@mysql-0:/# mysql -hmycat.mysql -P8066 -uroot -p -e "show variables like 'server_id';"
Enter password: 
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id     | 101   |
+---------------+-------+
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值