k8s部署mycat集群记录

临时操作后续细化补充

1.创建mycat pv

 cat mycat.pv.yaml 
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-nfs-mycat01                     #创建的pv名称可创建多个.
  namespace: mt-math                    #属于的命名空间
spec:
  capacity:
    storage: 210Mi                        #创建的pv容量为1G
  accessModes:
  - ReadWriteMany                       #pv的访问模式:可读可写可挂在多个节点
  persistentVolumeReclaimPolicy: Retain #回收策略
  nfs:                                  #创建的pv数据来源
    path: /NFS/mycat/pv01                     #数据源目录
    server: 192.168.0.14                #数据源ip
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-nfs-mycat02                     #创建的pv名称可创建多个.
  namespace: mt-math                    #属于的命名空间
spec:
  capacity:
    storage: 210Mi                        #创建的pv容量为1G
  accessModes:
  - ReadWriteMany                       #pv的访问模式:可读可写可挂在多个节点
  persistentVolumeReclaimPolicy: Retain #回收策略
  nfs:                                  #创建的pv数据来源
    path: /NFS/mycat/pv02                     #数据源目录
    server: 192.168.0.14                #数据源ip

2.创建mycat 的configmap

 cat mycat.config.yaml 
apiVersion: v1
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=\"mtmath\" checkSQLschema=\"false\"
    sqlMaxLimit=\"100\" dataNode=\"dn1\">\n    </schema>\n    <dataNode name=\"dn1\"
    dataHost=\"localhost01\" database=\"mtmath\" />\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.mt-math:3306\" user=\"root\"
    password=\"\">\n            <readHost host=\"hostS2\" url=\"mysql-read.mt-math:3306\"
    user=\"root\" password=\"\" />\n             </writeHost> \n             <writeHost
    host=\"hostS1\" url=\"mysql-0.mysql.mt-math: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\">mtmath</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\">mtmath</property>\n\t\t<property name=\"readOnly\">true</property>\n\t</user>\n\n</mycat:server>\n"
kind: ConfigMap
metadata:
  creationTimestamp: 2019-06-06T09:53:39Z
  name: mycat-config
  namespace: mt-math

3.创建mycat无头服务

cat mycat.StatefulSet.yaml 
#创建第一个无头服务mycat#################
apiVersion: v1
kind: Service
metadata:
  labels:
    app: db-proxy
  name: db-proxy
  namespace: mt-math
spec:
  ports:
  - name: db-porxy
    port: 3306
  clusterIP: None
  selector:
    app: wylpod-mycat
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  annotations:
  labels:
    app: wylpod-mycat
  name: wylpod-mycat
  namespace: mt-math
spec:
  serviceName: "db-proxy"
  replicas: 2
  selector:
    matchLabels:
      app: wylpod-mycat
  template:
    metadata:
      annotations:
      labels:
        app: wylpod-mycat
    spec:
      containers:
        - image: "harbor.bestyunyan.club:5588/library/mycat:1.6"
          imagePullPolicy: IfNotPresent
          name: wylpod-mycat
          ports:
          - containerPort: 3306
            protocol: TCP
            name: wylpod-mycat
          volumeMounts:
          - name: mycat-pvc
            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
      volumes:                       
      - name: configmap-mycat             
        configMap:                         
          name: mycat-config
          items:
          - key: server.xml
            path: server.xml
          - key: schema.xml
            path: schema.xml
  volumeClaimTemplates:
  - metadata:
      name: mycat-pvc
      namespace: mt-math
    spec:
      accessModes: [ "ReadWriteMany" ]
      resources:
        requests:
          storage: 210M

4.文件列表

afb72fb0af003914e2888bf00f7f2242aad.jpg

7dcf5865de2c099b9ff248e35f04c421578.jpg

进入一个容器测试:mycat

kubectl exec -it web-0 /bin/bash -n mt-math
mysql -uroot -p123456 -P8066 -hwylpod-mycat-1.db-proxy.mt-math -e "show databases;"
mysql -uroot -p123456 -P8066 -hwylpod-mycat-1.db-proxy.mt-math -e "show variables like 'server_id';"

6c68dc934c6b1044b8a322fcaf0f5ca3e2e.jpg

c7bf55ba0ca2780e327725b29fdf6f6206c.jpg

转载于:https://my.oschina.net/wangyunlong/blog/3059389

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值