//雪花飘落特效 //右上角github跳转   

k8s部署mycat及mycat-web监控

zk部署
https://www.jianshu.com/p/2633b95c244c

pv.yaml
[root@centos-svr68-54 zk]# cat pv.yaml 
apiVersion: v1
kind: PersistentVolume
metadata:
  name: k8s-pv-zk01
  namespace: middleware
  labels:
    app: zk
  annotations:
    volume.beta.kubernetes.io/storage-class: "anything"
spec:
  capacity:
    storage: 5Gi
  accessModes:
  - ReadWriteOnce
  hostPath:
    path: /home/zk/pv/zk01
  persistentVolumeReclaimPolicy: Recycle
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: k8s-pv-zk02
  namespace: middleware
  labels:
    app: zk
  annotations:
    volume.beta.kubernetes.io/storage-class: "anything"
spec:
  capacity:
    storage: 5Gi
  accessModes:
  - ReadWriteOnce
  hostPath:
    path: /home/zk/pv/zk02
  persistentVolumeReclaimPolicy: Recycle
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: k8s-pv-zk03
  namespace: middleware
  labels:
    app: zk
  annotations:
    volume.beta.kubernetes.io/storage-class: "anything"
spec:
  capacity:
    storage: 5Gi
  accessModes:
  - ReadWriteOnce
  hostPath:
    path: /home/zk/pv/zk03
  persistentVolumeReclaimPolicy: Recycle
---

zk.yaml
[root@centos-svr68-54 zk]# cat zk.yaml 
apiVersion: v1
kind: Service
metadata:
  name: zk-hs
  namespace: middleware
  labels:
    app: zk
spec:
  selector:
    app: zk
  clusterIP: None
  ports:
  - name: server
    port: 2888
  - name: leader-election
    port: 3888
--- 
apiVersion: v1
kind: Service
metadata:
  name: zk-cs
  namespace: middleware
  labels:
    app: zk
spec:
  selector:
    app: zk
  type: NodePort
  ports:
  - name: client
    port: 2181
---
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: zk-pdb
  namespace: middleware
spec:
  selector:
    matchLabels:
      app: zk
  maxUnavailable: 1
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: zk
  namespace: middleware
spec:
  selector:
    matchLabels:
      app: zk # has to match .spec.template.metadata.labels
  serviceName: "zk-hs"
  replicas: 3 # by default is 1
  updateStrategy:
    type: RollingUpdate
  podManagementPolicy: Parallel
  template:
    metadata:
      labels:
        app: zk # has to match .spec.selector.matchLabels
    spec:
      containers:
      - name: zk
        imagePullPolicy: Always
        image: leolee32/kubernetes-library:kubernetes-zookeeper1.0-3.4.10
        resources:
          requests:
            memory: "500Mi"
            cpu: "0.5"
        ports:
        - containerPort: 2181
          name: client
        - containerPort: 2888
          name: server
        - containerPort: 3888
          name: leader-election
        command:
        - sh
        - -c
        - "start-zookeeper \
        --servers=3 \
        --data_dir=/var/lib/zookeeper/data \
        --data_log_dir=/var/lib/zookeeper/data/log \
        --conf_dir=/opt/zookeeper/conf \
        --client_port=2181 \
        --election_port=3888 \
        --server_port=2888 \
        --tick_time=2000 \
        --init_limit=10 \
        --sync_limit=5 \
        --heap=512M \
        --max_client_cnxns=60 \
        --snap_retain_count=3 \
        --purge_interval=12 \
        --max_session_timeout=40000 \
        --min_session_timeout=4000 \
        --log_level=INFO"
        readinessProbe:
          exec:
            command:
            - sh
            - -c
            - "zookeeper-ready 2181"
          initialDelaySeconds: 10
          timeoutSeconds: 5
        livenessProbe:
          exec:
            command:
            - sh
            - -c
            - "zookeeper-ready 2181"
          initialDelaySeconds: 10
          timeoutSeconds: 5
        volumeMounts:
        - name: datadir
          mountPath: /var/lib/zookeeper
  volumeClaimTemplates:
  - metadata:
      name: datadir
      annotations:
        volume.beta.kubernetes.io/storage-class: "anything"
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi

mycat部署:
官网地址:http://www.mycat.org.cn/
下载地址:http://dl.mycat.org.cn/1.6.7.6/20211016233725/Mycat-server-1.6.7.6-release-20211016233725-linux.tar.gz

创建dockerfile文件

[root@BETAWS32 mycat]# ll
total 43984
-rw-r--r-- 1 root root      371 Oct 21 09:12 1
-rw-r--r-- 1 root root      333 Oct 19 13:22 Dockerfile
-rw-r--r-- 1 root root 17568537 Oct 19 13:16 Mycat-server-1.6.7.1-release-20200209222254-linux.tar.gz
-rw-r--r-- 1 root root 27456207 Oct 20 10:22 Mycat-server-1.6.7.6-release-20211016233725-linux.tar.gz
drwxr-xr-x 4 root root       96 Oct 20 17:33 test
drwxr-xr-x 3 root root       90 Oct 21 09:38 web
[root@BETAWS32 mycat]# cat 1 
FROM java:8-jre
USER root
COPY Mycat-server-1.6.7.6-release-20211016233725-linux.tar.gz /
RUN tar -zxf /Mycat-server-1.6.7.6-release-20211016233725-linux.tar.gz -C /usr/local/
ENV MYCAT_HOME=/usr/local//mycat
ENV PATH=$PATH:${MYCAT_HOME}/bin
WORKDIR $MYCAT_HOME/bin
RUN chmod u+x /usr/local/mycat
RUN mkdir /usr/local/logs/ -p
EXPOSE 8066 9066
CMD ["./mycat", "console"]
构建镜像:
docker build -t harbor.betawm.com/tools/betamycat:v2 -f 1 .
docker push  harbor.betawm.com/tools/betamycat:v2 
本地测试:
docker run --name=test-aa --rm -it harbor.betawm.com/tools/betamycat:v2 bash 

创建k8s mycat.yaml文件

ns.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: middleware      #这是命名空间的名称
---
apiVersion: v1
data:
  .dockerconfigjson: >-
    eyJhdXRocyI6eyIxNzIuMTcuMTIuNzkiOnsidXNlcm5hbWUiOiJhZG1pbiIsInBhc3N3b3JkIjoiYmV0YXdtLmNvbSIsImVtYWlsIjoiYmV0YUBiZXR3YW0uY29tIiwiYXV0aCI6IllXUnRhVzQ2WW1WMFlYZHRMbU52YlE9PSJ9fX0=
kind: Secret
metadata:
  name: betasecret
  namespace: middleware
type: kubernetes.io/dockerconfigjson
mycat.config.yaml
---
apiVersion: v1
data:
  myid.propertie: >-
    loadZk=true

    zkURL=172.17.13.47:2181

    clusterId=mycat-cluster-1

    myid=mycat_fz_01

    clusterSize=3

    clusterNodes=mycat_fz_01,mycat_fz_02,mycat_fz_03

    #server  booster  ;   booster install on db same server,will reset all
    minCon to 2

    type=server

    boosterDataHosts=dataHost1
kind: ConfigMap
metadata:
  name: mycat-config
  namespace: middleware
mycat.StatefulSet.yaml
#cat mycat.StatefulSet.yaml 
#创建第一个无头服务mycat#################
apiVersion: v1
kind: Service
metadata:
  labels:
    app: db-proxy
  name: db-proxy
  namespace: middleware
spec:
  ports:
  - name: mycat-porxy
    port: 3306
    protocol: TCP
    targetPort: 8066
  - name: mycat-manager
    port: 9066
    protocol: TCP
    targetPort: 9066
  NodePort: None
  selector:
    app: beta-mycat
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  annotations:
  labels:
    app: beta-mycat
  name: beta-mycat
  namespace: middleware
spec:
  serviceName: "db-proxy"
  replicas: 2
  selector:
    matchLabels:
      app: beta-mycat
  template:
    metadata:
      annotations:
      labels:
        app: beta-mycat
    spec:
      containers:
        - image: "harbor.betawm.com/tools/betamycat:v2"
          imagePullPolicy: IfNotPresent          
          name: beta-mycat
          # args: 
          # - /bin/sh
          # - '-c'
          # - '/usr/local/logs/mycat console'
          ports:
          - name: mycat-proxy
            containerPort: 8066
            protocol: TCP
          - name: mycat-manager
            containerPort: 9066
            protocol: TCP            
          livenessProbe:
            tcpSocket:
              port: 8066
            initialDelaySeconds: 15   #第一次健康检查的时间
            periodSeconds: 5    #检查周期
            timeoutSeconds: 5   #检查超时时间
            successThreshold: 1 #成功次数判定成功
            failureThreshold: 1 #失败次数判定失败
          resources:
            limits:
              cpu: 500m
              memory: 2Gi
            requests:
              cpu: 200m
              memory: 500Mi
          volumeMounts:
          - name: mycatlog
            mountPath: /usr/local/mycat/logs
          - name: configmap-mycat
            mountPath: /usr/local/mycat/conf/myid.propertie
            subPath: myid.propertie         
      volumes:                       
      - name: configmap-mycat             
        configMap:                         
          name: mycat-config
          items:
          - key: myid.propertie
            path: myid.propertie       
      - name: mycatlog
        hostPath: 
           path: /beta/mycat/logs
           type: DirectoryOrCreate

mycat-web监控部署

构建基础镜像:
FROM java:8-jre
USER root
COPY Mycat-web-1.0-SNAPSHOT-20170102153329-linux.tar.gz /
RUN tar -zxf Mycat-web-1.0-SNAPSHOT-20170102153329-linux.tar.gz -C /usr/local/
RUN chmod u+x /usr/local/mycat-web/start.sh
COPY start1.sh /usr/local/mycat-web/
WORKDIR /usr/local/mycat-web/
EXPOSE 8082
ENTRYPOINT ["java","-Xms1024m","-Xmx1024m","-Xmn128m","-XX:PermSize=64m", "-XX:+UseParNewGC", "-XX:+UseConcMarkSweepGC", "-XX:+UseCMSCompactAtFullCollection", "-XX:CMSFullGCsBeforeCompaction=0", "-XX:CMSInitiatingOccupancyFraction=70", "-Dcom.sun.management.jmxremote", "-Dcom.sun.management.jmxremote.port=8999", "-Dcom.sun.management.jmxremote.authenticate=false", "-Dcom.sun.management.jmxremote.ssl=false", "-jar", "start.jar"]


docker build -t harbor.betawm.com/tools/betamycat-web:v7  -f 1 .
docker push  harbor.betawm.com/tools/betamycat:v1

mycat-web.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    app: db-proxy-mycatweb
  name: db-proxy-mycatweb
  namespace: middleware
spec:
  ports:
  - name: mycat-porxy
    port: 8082
    protocol: TCP
    targetPort: 8082
    nodePort: 38082
  type: NodePort
  selector:
    app: beta-mycat-web
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  annotations:
  labels:
    app: beta-mycat-web
  name: beta-mycat-web
  namespace: middleware
spec:
  serviceName: "db-proxy-mycatweb"
  replicas: 2
  selector:
    matchLabels:
      app: beta-mycat-web
  template:
    metadata:
      annotations:
      labels:
        app: beta-mycat-web
    spec:
      containers:
        - image: "harbor.betawm.com/tools/betamycat-web:v6"
          imagePullPolicy: IfNotPresent          
          name: beta-mycat-web
          # args: 
          # - /bin/sh
          # - '-c'
          # - 'java -Xms1024m -Xmx1024m -Xmn128m -XX:PermSize=64m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=0 -XX:CMSInitiatingOccupancyFraction=70 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar /usr/local/mycat-web/start.jar'
          ports:
          - name: mycatweb-proxy
            containerPort: 8082
            protocol: TCP          
          livenessProbe:
            tcpSocket:
              port: 8082
            initialDelaySeconds: 35   #第一次健康检查的时间
            periodSeconds: 5    #检查周期
            timeoutSeconds: 5   #检查超时时间
            successThreshold: 1 #成功次数判定成功
            failureThreshold: 1 #失败次数判定失败
          resources:
            limits:
              cpu: 2000m
              memory: 4Gi
            requests:
              cpu: 200m
              memory: 2Gi
          volumeMounts:
          - name: configmap-mycat
            mountPath: /usr/local/mycat-web/mycat-web/WEB-INF/classes/mycat.properties
            subPath: mycat.properties          
      volumes:                       
      - name: configmap-mycat             
        configMap:                         
          name: mycatweb-config
          items:
          - key: mycat.properties
            path: mycat.properties
     
---
apiVersion: v1
data:
  mycat.properties: |+
    #
    #Mon Jan 16 15:37:36 CST 2012 
    show.period=3000000 
    zookeeper=172.17.13.47:2181 
    
    mycat_warn_mail=[{"cc"\:"sohudo@mycat.io","index"\:1,"mangerPort"\:"465","smtpHost"\:"smtp.139.com","smtpPassword"\:"123456","smtpProtocol"\:"smtp","smtpUser"\:"agile_louie@139.com","to"\:"9183838@qq.com"}]
    ##sql\u4E0A\u7EBF\u76F8\u5173\u914D\u7F6E
    sqlonline.server=192.168.80.128
    sqlonline.user=root
    sqlonline.passwd=123456

kind: ConfigMap
metadata:
  name: mycatweb-config
  namespace: middleware
posted @ 2021-10-21 10:36  农夫运维  阅读(558)  评论(0)    收藏  举报