【云原生 | Kubernetes 系列】—K8S部署RocketMQ集群(双主双从+同步模式)

这篇具有很好参考价值的文章主要介绍了【云原生 | Kubernetes 系列】—K8S部署RocketMQ集群(双主双从+同步模式)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

【云原生 | Kubernetes 系列】—K8S部署RocketMQ集群(双主双从+同步模式)

版权 本文为云录原创文章,转载无需和我联系,但请注明来自云录 https://www.yunzhuan.site

rocketMQ高可用有很多种方式,比如:单机部署,多主集群,双主双从同步部署,双主双从异步部署,以及多主多从部署。部署集群可按照自己公司的实际情况进行部署。

单机部署:只启动一个rocketMQ实例就可以了,一般常用来本机测试使用。原因:一旦rocketMQ因某些原因挂掉,导致mq无法使用,则我们服务器无法接受信息与消费信息等。

多主集群:只部署mq主节点,无部署从节点。优点:配置简单,单个Master宕机或重启维护对应用无影响,即使机器宕机不可恢复情况下,也有其他主节点进行写入操作,

消息也不会丢(异步刷盘丢失少量消息,同步刷盘一条不丢),性能最高;

双主双从同步:部署四个节点,每个主节点都有一个从节点,主与从节点的信息通过同步的方式进行保存。优点:消息不会丢失,即:主节点挂了后,从节点的消息也不会造成丢失,只不过没法接受新消息,只能消费,但是能保证我消费的消息一定是准确的。缺点:客户端接受服务器响应时间长。可用于消息安全高的场景。

双主双从异步:与双主双从一致,只不过在主从数据传输是通过异步的方式,优点:客户端能快速的接收到服务器的消息,缺点:主节点挂的情况,从节点会丢失一部分消息。可用于允许消息丢失,吞吐量高的情景。

🍇 创建存储

这里我用ceph,需要自己准备存储

🍇 需要准备的材料 自行下载

apache-maven-3.6.3-bin.tar.gz

rocketmq-all-4.9.4-bin-release.zip

rocketmq-dashboard-master.zip

yarn-v1.22.10.tar.gz https://github.com/yarnpkg/yarn/releases/download/v1.22.10/yarn-v1.22.10.tar.gz

🍋 创建RocketMQ集群(双主双从同步模式)

制作rocketmq镜像

[root rocketmqimage]# ll
total 32200
-rw-r--r--. 1 root   root        319 May 15 13:38 Dockerfile
drwxr-xr-x. 6 root   root        103 May 15 13:37 rocketmq-all-4.9.4-bin-release
-rw-rw-r--. 1 root root 32967749 May 15 13:31 rocketmq-all-4.9.4-bin-release.zip

1:解压rocketmq-all-4.9.4-bin-release.zip 将runbroker.sh脚本文件里的内存设置调整小点

unzip  rocketmq-all-4.9.4-bin-release.zip
vim rocketmq-all-4.9.4-bin-release/bin/runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g"

2:准备dockerfile

FROM openjdk:8
RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
ENV LANG en_US.UTF-8
COPY rocketmq-all-4.9.4-bin-release  /usr/local/rocketmq-all-4.9.4-bin-release
RUN  mkdir -p /data/rocketmq/store
CMD ["/bin/bash"]

3:制作镜像并上传到Harbor仓库

docker build -t 127.0.0.1/rocketmq/rocketmq-4.9.3:1.0 .
docker push  127.0.0.1/rocketmq/rocketmq-4.9.3:1.0

制作nameserver的image镜像

将上面rocketmq_image目录下的包rocketmq-all-4.9.4-bin-release 拷贝过来

[root nameserver_image]# ll
total 8
-rw-r--r-- 1 root root 525 Aug 23  2022 Dockerfile
-rw-r--r-- 1 root root  17 Aug 23  2022 namesrv.properties
drwxr-xr-x 6 root root 103 May 15 13:56 rocketmq-all-4.9.4-bin-release

1:准备 namesrv.properties 自定义nameserver的端口号

[root nameserver_image]# cat namesrv.properties 
listenPort=20801

2:准备dockerfile

[root nameserver_image]# cat Dockerfile 
FROM openjdk:8
RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
ENV LANG en_US.UTF-8
COPY rocketmq-all-4.9.4-bin-release  /usr/local/rocketmq-all-4.9.4-bin-release
COPY namesrv.properties /usr/local/rocketmq-all-4.9.4-bin-release/conf/
WORKDIR /usr/local/rocketmq-all-4.9.4-bin-release
CMD ["/usr/local/rocketmq-all-4.9.4-bin-release/bin/mqnamesrv","-c","/usr/local/rocketmq-all-4.9.4-bin-release/conf/namesrv.properties"]

3: 制作镜像并上传到Harbor仓库

docker build -t 127.0.0.1/rocketmq/rocketmq_namesrv:4.9.3.1 .
docker push  127.0.0.1/rocketmq/rocketmq_namesrv:4.9.3.1

制作rocketmq的web可视化界面的image镜像

[root rockermq_web]# ll
total 14320
drwxr-xr-x 6 root   root        99 Aug 23  2022 apache-maven-3.6.3
-rw-rw-r-- 1 dotnet dotnet 9506321 Aug 23  2022 apache-maven-3.6.3-bin.tar.gz
-rw-r--r-- 1 root   root       674 May 15 15:26 Dockerfile
drwxr-xr-x 7 root   root       213 Apr 11  2022 rocketmq-dashboard-master
-rw-rw-r-- 1 dotnet dotnet 3906355 Aug 23  2022 rocketmq-dashboard-master.zip
-rw-rw-r-- 1 dotnet dotnet 1244965 May 15 15:21 yarn-v1.22.10.tar.gz

1:下载rocketmq-dashboard-master.zip和apache-maven-3.6.3-bin.tar.gz 并解压 2:修改 dashboard配置

vim rocketmq-dashboard-master/src/main/resources/application.yml
修改内容:
namesrvAddrs:
      - mq-namesrv.romq.svc.cluster.local:20801
loginRequired: true 
accessKey: rocketmq2  
secretKey: 12345678   
server:
  port: 8080
  servlet:
    encoding:
      charset: UTF-8
      enabled: true
      force: true
## SSL setting
#  ssl:
#    key-store: classpath:rmqcngkeystore.jks
#    key-store-password: rocketmq
#    key-store-type: PKCS12
#    key-alias: rmqcngkey

spring:
  application:
    name: rocketmq-dashboard

logging:
  config: classpath:logback.xml

rocketmq:
  config:
    # if this value is empty,use env value rocketmq.config.namesrvAddr  NAMESRV_ADDR | now, default localhost:9876
    # configure multiple namesrv addresses to manage multiple different clusters
    namesrvAddrs:
      - mq-namesrv.romq.svc.cluster.local:20801
    # if you use rocketmq version < 3.5.8, rocketmq.config.isVIPChannel should be false.default true
    isVIPChannel: false
    # timeout for mqadminExt, default 5000ms
    timeoutMillis:
    # rocketmq-console's data path:dashboard/monitor
    dataPath: /tmp/rocketmq-console/data
    # set it false if you don't want use dashboard.default true
    enableDashBoardCollect: true
    # set the message track trace topic if you don't want use the default one
    msgTrackTopicName:
    ticketKey: ticket
    # must create userInfo file: ${rocketmq.config.dataPath}/users.properties if the login is required
    loginRequired: true
    useTLS: false
    # set the accessKey and secretKey if you used acl设置acl权限
    accessKey: rocketmq2  # if version > 4.4.0 
    secretKey: 12345678   # if version > 4.4.0

threadpool:
  config:
    coreSize: 10
    maxSize: 10
    keepAliveTime: 3000
    queueSize: 5000

3:准备dockerfile

[root rockermq_web]# cat Dockerfile 
FROM openjdk:8
RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
ENV LANG en_US.UTF-8
ENV MAVEN_HOME /usr/local/maven
ENV PATH $PATH:$MAVEN_HOME/bin
COPY rocketmq-dashboard-master   /usr/local/rocketmq-dashboard-master
COPY yarn-v1.22.10.tar.gz       /root/.m2/repository/com/github/eirslett/yarn/1.22.10/
COPY apache-maven-3.6.3 /usr/local/maven
WORKDIR /usr/local/rocketmq-dashboard-master
RUN mvn clean package -Dmaven.test.skip=true
WORKDIR /usr/local/rocketmq-dashboard-master/target
EXPOSE 8080
CMD ["nohup","java","-jar","rocketmq-dashboard-1.0.1-SNAPSHOT.jar","&"]

4:制作镜像并上传到Harbor仓库

docker build -t 127.0.0.1/rocketmq/rocketmq-dashboard:v4.9.3.1 .
docker push     127.0.0.1/rocketmq/rocketmq-dashboard:v4.9.3.1

准备配置文件 configmap

1:我的broker配置文件

[root config]# ll
total 16
-rw-rw-r--. 1 dotnet dotnet 638 May 15 15:53 broker-a.properties
-rw-rw-r--. 1 dotnet dotnet 630 May 15 15:53 broker-a-s.properties
-rw-rw-r--. 1 dotnet dotnet 636 May 15 15:53 broker-b.properties
-rw-rw-r--. 1 dotnet dotnet 632 May 15 15:53 broker-b-s.properties
[root config]# cat broker-a.properties 
brokerClusterName=rocketmq-cluster
brokerName=broker-a
brokerId=0
namesrvAddr=mq-namesrv.romq.svc.cluster.local:20801
defaultTopicQueueNums=4
autoCreateTopicEnable=false
autoCreateSubscriptionGroup=true
brokerIP1=公网ip或是负载ip
listenPort=30811
deleteWhen=04
fileReservedTime=48
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
storePathRootDir=/data/rocketmq/store
maxMessageSize=65536
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=SYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=SYNC_FLUSH
aclEnable=true
[root config]# cat broker-a-s.properties 
brokerClusterName=rocketmq-cluster
brokerName=broker-a
brokerId=1
namesrvAddr=mq-namesrv.romq.svc.cluster.local:20801
defaultTopicQueueNums=4
autoCreateTopicEnable=false
autoCreateSubscriptionGroup=true
brokerIP1=公网ip或是负载ip
listenPort=30812
deleteWhen=04
fileReservedTime=48
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
storePathRootDir=/data/rocketmq/store
maxMessageSize=65536
brokerRole=SLAVE
flushDiskType=SYNC_FLUSH
aclEnable=true
[root config]# cat broker-b.properties 
brokerClusterName=rocketmq-cluster
brokerName=broker-b
brokerId=0
namesrvAddr=mq-namesrv.romq.svc.cluster.local:20801
defaultTopicQueueNums=4
autoCreateTopicEnable=false
autoCreateSubscriptionGroup=true
brokerIP1=公网ip或是负载ip
listenPort=30813
deleteWhen=04
fileReservedTime=48
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
storePathRootDir=/data/rocketmq/store
maxMessageSize=65536
brokerRole=SYNC_MASTER
flushDiskType=SYNC_FLUSH
aclEnable=true
[root config]# cat broker-b-s.properties 
brokerClusterName = rocketmq-cluster
brokerName=broker-b
brokerId=1
namesrvAddr=mq-namesrv.romq.svc.cluster.local:20801
defaultTopicQueueNums=4
autoCreateTopicEnable=false
autoCreateSubscriptionGroup=true
brokerIP1=公网ip或是负载ip
listenPort=30814
deleteWhen=04
fileReservedTime=48
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
storePathRootDir=/data/rocketmq/store
maxMessageSize=65536
brokerRole=SLAVE
flushDiskType=SYNC_FLUSH
aclEnable=true

2:创建CM

kubectl create configmap rocketmq-config --from-file=broker-a.properties --from-file=broker-b.properties --from-file=broker-a-s.properties --from-file=broker-b-s.properties -n romq

准备Deploy

1:我的deploy

[root rocketmqDeploy]# ll
total 24
-rw-rw-r--. 1 dotnet dotnet 2908 May 15 16:50 broker-a-deployment.yaml
-rw-rw-r--. 1 dotnet dotnet 3041 May 15 16:50 broker-a-s-deployment.yaml
-rw-rw-r--. 1 dotnet dotnet 2908 May 15 16:50 broker-b-deployment.yaml
-rw-rw-r--. 1 dotnet dotnet 3041 May 15 16:50 broker-b-s-deployment.yaml
-rw-rw-r--. 1 dotnet dotnet 1811 May 15 15:50 namesrv-deployment.yaml
-rw-rw-r--. 1 dotnet dotnet 1735 May 15 17:27 rocketmq-externals-deployment.yaml
[root rocketmqDeploy]# cat broker-a-deployment.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app: broker-a
  name: broker-a
spec:
  type: NodePort
  ports:
    - port: 30811
      targetPort: 30811
      name: broker-port
      nodePort: 30811
  selector:
    app: broker-a
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: broker-a
spec:
  serviceName: broker-a
  replicas: 1
  selector:
    matchLabels:
      app: broker-a
  template:
    metadata:
      labels:
        app: broker-a
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - broker-a
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: broker-a
          image: 127.0.0.1/rocketmq/rocketmq-4.9.3:1.0
          imagePullPolicy: Always
          command: ["sh","-c","/usr/local/rocketmq-all-4.9.4-bin-release/bin/mqbroker  -c /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-a.properties"]
          volumeMounts:
            - mountPath: /root/logs
              name: rocketmq-data-cluster
              subPath: mq-brokeroptlogs
            - mountPath: /data/rocketmq
              name: rocketmq-data-cluster
              subPath: mq-brokeroptstore
            - name: broker-config
              mountPath: /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-a.properties
              subPath: broker-a.properties
            - name: time
              mountPath: /etc/localtime
          env:
            - name: JAVA_OPT_EXT
              value: '-Xmx4096m -Xms4096m -Xmn1048m'
          resources:
            requests:
              memory: 2024Mi
              cpu: 1024m
            limits:
              memory: 6024Mi
              cpu: 6000m
          lifecycle:
            postStart:
              exec:
                command: ["/bin/sh","-c","touch /tmp/health"]
          livenessProbe:
            exec:
              command: ["test","-e","/tmp/health"]
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
          readinessProbe:
            tcpSocket:
              port: 30811
            initialDelaySeconds: 15
            timeoutSeconds: 5
            periodSeconds: 20
      volumes:
        - name: broker-config
          configMap:
            name: rocketmq-config
        - name: time
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
  volumeClaimTemplates:
    - metadata:
        name: rocketmq-data-cluster
      spec:
        storageClassName: rook-ceph-block
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 20Gi
[root rocketmqDeploy]# cat broker-a-s-deployment.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app: broker-a-s
  name: broker-a-s
spec:
  type: NodePort
  ports:
    - port: 30812
      targetPort: 30812
      name: broker-port
      nodePort: 30812
  selector:
    app: broker-a-s
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: broker-a-s
spec:
  serviceName: broker-a-s
  replicas: 1
  selector:
    matchLabels:
      app: broker-a-s
  template:
    metadata:
      labels:
        app: broker-a-s
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - broker-a-s
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: broker-a-s
          image: 127.0.0.1/rocketmq/rocketmq-4.9.3:1.0
          imagePullPolicy: Always
          command: ["sh","-c","/usr/local/rocketmq-all-4.9.4-bin-release/bin/mqbroker  -c /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-a-s.properties"]
          volumeMounts:
            - mountPath: /root/logs
              name: rocketmq-data-cluster
              subPath: mq-brokeroptlogs
            - mountPath: /data/rocketmq
              name: rocketmq-data-cluster
              subPath: mq-brokeroptstore
            - name: broker-config
              mountPath: /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-a-s.properties
              subPath: broker-a-s.properties
            - name: time
              mountPath: /etc/localtime
          env:
            - name: JAVA_OPT_EXT
              value: '-Xmx4096m -Xms4096m -Xmn1048m'
          resources:
            requests:
              memory: 2024Mi
              cpu: 1024m
            limits:
              memory: 6024Mi
              cpu: 6000m
          lifecycle:
            postStart:
              exec:
                command: ["/bin/sh","-c","touch /tmp/health"]
          livenessProbe:
            exec:
              command: ["test","-e","/tmp/health"]
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
          readinessProbe:
            tcpSocket:
              port: 30812
            initialDelaySeconds: 15
            timeoutSeconds: 5
            periodSeconds: 20
      volumes:
        - name: broker-config
          configMap:
            name: rocketmq-config
            items:
              - key: broker-a-s.properties
                path: broker-a-s.properties
        - name: time
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
  volumeClaimTemplates:
    - metadata:
        name: rocketmq-data-cluster
      spec:
        storageClassName: rook-ceph-block
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 20Gi
[root rocketmqDeploy]# cat broker-b-deployment.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app: broker-b
  name: broker-b
spec:
  type: NodePort
  ports:
    - port: 30813
      targetPort: 30813
      name: broker-port
      nodePort: 30813
  selector:
    app: broker-b
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: broker-b
spec:
  serviceName: broker-b
  replicas: 1
  selector:
    matchLabels:
      app: broker-b
  template:
    metadata:
      labels:
        app: broker-b
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - broker-b
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: broker-b
          image: 127.0.0.1/rocketmq/rocketmq-4.9.3:1.0
          imagePullPolicy: Always
          command: ["sh","-c","/usr/local/rocketmq-all-4.9.4-bin-release/bin/mqbroker  -c /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-b.properties"]
          volumeMounts:
            - mountPath: /root/logs
              name: rocketmq-data-cluster
              subPath: mq-brokeroptlogs
            - mountPath: /data/rocketmq
              name: rocketmq-data-cluster
              subPath: mq-brokeroptstore
            - name: broker-config
              mountPath: /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-b.properties
              subPath: broker-b.properties
            - name: time
              mountPath: /etc/localtime
          lifecycle:
            postStart:
              exec:
                command: ["/bin/sh","-c","touch /tmp/health"]
          livenessProbe:
            exec:
              command: ["test","-e","/tmp/health"]
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
          readinessProbe:
            tcpSocket:
              port: 30813
            initialDelaySeconds: 15
            timeoutSeconds: 5
            periodSeconds: 20
          env:
            - name: JAVA_OPT_EXT
              value: '-Xmx4096m -Xms4096m -Xmn1048m'
          resources:
            requests:
              memory: 2024Mi
              cpu: 1024m
            limits:
              memory: 6024Mi
              cpu: 6000m
      volumes:
        - name: broker-config
          configMap:
            name: rocketmq-config
        - name: time
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
  volumeClaimTemplates:
    - metadata:
        name: rocketmq-data-cluster
      spec:
        storageClassName: rook-ceph-block
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 20Gi
[root rocketmqDeploy]# cat broker-b-s-deployment.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app: broker-b-s
  name: broker-b-s
spec:
  type: NodePort
  ports:
    - port: 30814
      targetPort: 30814
      name: broker-port
      nodePort: 30814
  selector:
    app: broker-b-s
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: broker-b-s
spec:
  serviceName: broker-b-s
  replicas: 1
  selector:
    matchLabels:
      app: broker-b-s
  template:
    metadata:
      labels:
        app: broker-b-s
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - broker-b-s
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: broker-b-s
          image: 127.0.0.1/rocketmq/rocketmq-4.9.3:1.0
          imagePullPolicy: Always
          command: ["sh","-c","/usr/local/rocketmq-all-4.9.4-bin-release/bin/mqbroker  -c /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-b-s.properties"]
          volumeMounts:
            - mountPath: /root/logs
              name: rocketmq-data-cluster
              subPath: mq-brokeroptlogs
            - mountPath: /data/rocketmq
              name: rocketmq-data-cluster
              subPath: mq-brokeroptstore
            - name: broker-config
              mountPath: /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-b-s.properties
              subPath: broker-b-s.properties
            - name: time
              mountPath: /etc/localtime
          lifecycle:
            postStart:
              exec:
                command: ["/bin/sh","-c","touch /tmp/health"]
          livenessProbe:
            exec:
              command: ["test","-e","/tmp/health"]
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
          readinessProbe:
            tcpSocket:
              port: 30814
            initialDelaySeconds: 15
            timeoutSeconds: 5
            periodSeconds: 20
          env:
            - name: JAVA_OPT_EXT
              value: '-Xmx4096m -Xms4096m -Xmn1048m'
          resources:
            requests:
              memory: 2024Mi
              cpu: 1024m
            limits:
              memory: 6024Mi
              cpu: 6000m
      volumes:
        - name: broker-config
          configMap:
            name: rocketmq-config
            items:
              - key: broker-b-s.properties
                path: broker-b-s.properties
        - name: time
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
  volumeClaimTemplates:
    - metadata:
        name: rocketmq-data-cluster
      spec:
        storageClassName: rook-ceph-block
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 20Gi
[root rocketmqDeploy]# cat namesrv-deployment.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app: mq-namesrv
  name: mq-namesrv
spec:
  type: NodePort
  ports:
    - port: 20801
      targetPort: 20801
      name: namesrv-port
      nodePort: 30815
  selector:
    app: mq-namesrv
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mq-namesrv
spec:
  serviceName: mq-namesrv
  replicas: 1
  selector:
    matchLabels:
      app: mq-namesrv
  template:
    metadata:
      labels:
        app: mq-namesrv
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - mq-namesrv
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: mq-namesrv
          image: 127.0.0.1/rocketmq/rocketmq_namesrv:4.9.3.1
          imagePullPolicy: Always
          env:
            - name: JAVA_OPT_EXT
              value: '-Xmx2048m -Xms2048m -Xmn512m'
          resources:
            requests:
              memory: 2024Mi
              cpu: 1024m
            limits:
              memory: 4096Mi
              cpu: 3000m
          lifecycle:
            postStart:
              exec:
                command: ["/bin/sh","-c","touch /tmp/health"]
          livenessProbe:
            exec:
              command: ["test","-e","/tmp/health"]
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
          readinessProbe:
            tcpSocket:
              port: 20801
            initialDelaySeconds: 15
            timeoutSeconds: 5
            periodSeconds: 20
[root rocketmqDeploy]# cat rocketmq-externals-deployment.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app: mq-externals
  name: mq-externals
spec:
  type: NodePort
  ports:
    - port: 8080
      targetPort: 8080
      name: console-port
      nodePort: 30816
  selector:
    app: mq-externals
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mq-externals
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mq-externals
  template:
    metadata:
      labels:
        app: mq-externals
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - mq-externals
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: mq-externals
          image: 127.0.0.1/rocketmq/rocketmq-dashboard:v4.9.3.1
          imagePullPolicy: Always
          lifecycle:
            postStart:
              exec:
                command: ["/bin/sh","-c","touch /tmp/health"]
          livenessProbe:
            exec:
              command: ["test","-e","/tmp/health"]
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
          readinessProbe:
            tcpSocket:
              port: 8080
            initialDelaySeconds: 15
          env:
            - name: JAVA_OPT_EXT
              value: '-Xmx1024m -Xms1024m -Xmn512m'
          resources:
            requests:
              memory: 1024Mi
              cpu: 1024m
            limits:
              memory: 4096Mi
              cpu: 3000m

2: 部署deploy

kubectl apply  -f ./  -n  romq
[root rocketmqDeploy]# kubectl  get po  -n  romq
NAME                           READY   STATUS    RESTARTS   AGE
broker-a-0                     1/1     Running   0          65m
broker-a-s-0                   1/1     Running   0          65m
broker-b-0                     1/1     Running   0          65m
broker-b-s-0                   1/1     Running   0          65m
mq-externals-6cfc5d9bc-w4cmp   1/1     Running   0          45s
mq-namesrv-0                   1/1     Running   0          65m
[root rocketmqDeploy]# kubectl  get svc  -n  romq
NAME           TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)           AGE
broker-a       NodePort   10.99.180.11     <none>        30811:30811/TCP   67m
broker-a-s     NodePort   10.105.248.30    <none>        30812:30812/TCP   66m
broker-b       NodePort   10.102.87.207    <none>        30813:30813/TCP   66m
broker-b-s     NodePort   10.103.106.247   <none>        30814:30814/TCP   66m
mq-externals   NodePort   10.96.128.101    <none>        8080:30816/TCP    66m
mq-namesrv     NodePort   10.105.103.115   <none>        20801:30815/TCP   66m

3:访问dashboard: http://$NODE_IP:30816/文章来源地址https://www.toymoban.com/news/detail-767176.html

版权 本文为云录原创文章,转载无需和我联系,但请注明来自云录 https://www.yunzhuan.site

到了这里,关于【云原生 | Kubernetes 系列】—K8S部署RocketMQ集群(双主双从+同步模式)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Kubernetes(K8S)集群部署

    目录 一、创建3台虚拟机 二、为每台虚拟机安装Docker 三、安装kubelet 3.1 安装要求 3.2 为每台服务器完成前置设置 3.3 为每台服务器安装kubelet、kubeadm、kubectl 四、使用kubeadm引导集群 4.1 master服务器 4.2 node1、node2服务器 4.3 初始化主节点 4.4 work节点加入集群 五、token过期怎么办?

    2024年02月07日
    浏览(84)
  • Kubernetes(k8s)集群安装部署

    名称 IP 系统 配置 主控节点 192.168.202.101 CentOS 7.9.2009 2核4G 工作节点1 192.168.202.102 CentOS 7.9.2009 2核4G 工作节点2 192.168.202.103 CentOS 7.9.2009 2核4G 2.1 升级操作系统内核 导入elrepo gpg key 安装elrepo YUM源仓库 安装kernel-ml版本,ml为长期稳定版本,lt为长期维护版本 设置grub2默认引导为0 重

    2024年02月10日
    浏览(80)
  • 云原生Kubernetes:阿里云托管k8s集群ACK创建和使用

    目录   一、理论 1.容器服务Kubernetes版 2.ACK Pro版集群概述 3.ACK版本说明 二、实验 1.创建专有版Kubernetes集群 三、问题 1.依赖检查未通过   (1)概念 阿里云容器服务Kubernetes版(Alibaba Cloud Container Service for Kubernetes,简称容器服务ACK)是全球首批通过Kubernetes一致性认证的服务平

    2024年02月13日
    浏览(79)
  • Kubernetes(k8s)集群部署----->超详细

    💖The Begin💖点点关注,收藏不迷路💖 Kubernetes(简称k8s)是一个开源的容器编排平台,可以帮助开发人员和运维团队更轻松地管理容器化应用程序。本文将详细介绍如何进行k8s集群的部署,以帮助读者快速搭建一个高可用、可伸缩的k8s集群。 1、操作系统:至少三台物理机或

    2024年02月05日
    浏览(65)
  • yum部署kubernetes(k8s)集群、k8s常用资源管理

    目录 一、环境搭建 1、准备环境 1)计算机说明,建议系统版本7.4或者7.6 2)修改所有主机的计算机名设置host文件  2、安装master节点 1)安装etcd配置etcd 2)安装k8s-master节点 3)配置apiserver 4)配置controller和scheduler 5)启动k8s服务 3、安装k8s-master上的node 1)安装node 2)配置kube

    2024年02月13日
    浏览(64)
  • 【云原生 | Kubernetes 系列】K8s 实战 管理 Secret 详解

    Secret 是一种包含少量敏感信息例如密码、令牌或密钥的对象。 这样的信息可能会被放在 Pod 规约中或者镜像中。 用户可以创建 Secret,同时系统也创建了一些 Secret。 一个 Secret 可以包含 Pod 访问数据库所需的用户凭证。 例如,由用户名和密码组成的数据库连接字符串。 你可

    2024年02月02日
    浏览(65)
  • 【云原生、k8s】管理Kubernetes应用搭建与部署

    官方提供Kubernetes部署3种方式 (一)minikube Minikube是一个工具,可以在本地快速运行一个单点的Kubernetes,尝试Kubernetes或日常开发的用户使用。不能用于生产环境。 官方文档:https://kubernetes.io/docs/setup/minikube/ (二)二进制包 从官方下载发行版的二进制包,手动部署每个组件,

    2024年01月21日
    浏览(76)
  • 【云原生 | Kubernetes 系列】K8s 实战 如何给应用注入数据

    前面我们已经一起学习了很多的东西了,本篇文章,我们将一起学习,如何给应用注入数据,当然,本篇文章不会讲解全部知识点,而是带领大家,一起学习如何对我们的项目进行相关的配置和设置。 创建 Pod 时,可以为其下的容器设置启动时要执行的命令及其参数。如果要

    2024年02月02日
    浏览(69)
  • 基于Docker的K8s(Kubernetes)集群部署

    开始搭建k8s集群 三台服务器修改主机名称 关闭对话窗口,重新连接 三台主机名称呢就修改成功了。 接下来修改每台节点的 hosts 文件 所有节点关闭 setLinux 查看是否关闭成功 为每个节点添加 k8s 数据源 如果安装docker数据源找不到yum-config 所有节点安装kubelet kubelet安装中… k

    2024年02月08日
    浏览(99)
  • 云原生Kubernetes:简化K8S应用部署工具Helm

    目录 一、理论 1.HELM ​编辑 2.部署HELM2 3.部署HELM3(2to3方式) 4.部署HELM3(单独安装) 二、实验 1.部署 HELM2 2.部署HELM3(2to3方式) 3.部署HELM3(单独安装) 三、问题 1.api版本过期 2.helm初始化报错 3.pod状态为ImagePullBackOff 4.helm 命令显示 no repositories to show 的错误 5.Helm安装报错

    2024年02月07日
    浏览(64)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包