Kubernetes中安装部署ActiveMQ集群(手把手式记录)

目录

1、创建命名空间 nacos-cluster

2、配置文件准备 

2.1 activemq0.xml

2.2 activemq1.xml

2.3 activemq2.xml

3、创建configMap  cm-activemq

4、创建activemq-cluster.yaml

5、执行命令部署

6、部署成功,查看结果


这里以3个borker的集群为例,不同个数根据自己去修做相应的内容修改 

1、创建命名空间 nacos-cluster

这个根据自己需求创建指定的名称空间,我这里空间吗为nacos-cluster,如果改名,下边对应名称空间地方修改即可

kubectl create ns activemq-cluster

2、配置文件准备 

根据需要部署的集群数量准备对应的配置文件,该文件实际就是对安装软件对应的配置文件修改

修改的内容为borkerName和增加multicast广播地址

2.1 activemq0.xml

<!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You 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.
-->
<!-- START SNIPPET: example -->
<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

    <!-- Allows us to use system properties as variables in this configuration file -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <value>file:${activemq.conf}/credentials.properties</value>
        </property>
    </bean>

    <!--
        The <broker> element is used to configure the ActiveMQ broker.
    -->
    <broker xmlns="http://activemq.apache.org/schema/core" brokerName="borker0" dataDirectory="${activemq.data}">

        <destinationPolicy>
            <policyMap>
              <policyEntries>
                <policyEntry topic=">" >
                    <!-- The constantPendingMessageLimitStrategy is used to prevent
                         slow topic consumers to block producers and affect other consumers
                         by limiting the number of messages that are retained
                         For more information, see:

                         http://activemq.apache.org/slow-consumer-handling.html

                    -->
                  <pendingMessageLimitStrategy>
                    <constantPendingMessageLimitStrategy limit="1000"/>
                  </pendingMessageLimitStrategy>
                </policyEntry>
              </policyEntries>
            </policyMap>
        </destinationPolicy>


        <!--
            The managementContext is used to configure how ActiveMQ is exposed in
            JMX. By default, ActiveMQ uses the MBean server that is started by
            the JVM. For more information, see:

            http://activemq.apache.org/jmx.html
        -->
        <managementContext>
            <managementContext createConnector="false"/>
        </managementContext>

        <!--
            Configure message persistence for the broker. The default persistence
            mechanism is the KahaDB store (identified by the kahaDB tag).
            For more information, see:

            http://activemq.apache.org/persistence.html
        -->
        <persistenceAdapter>
            <kahaDB directory="${activemq.data}/kahadb"/>
        </persistenceAdapter>


          <!--
            The systemUsage controls the maximum amount of space the broker will
            use before disabling caching and/or slowing down producers. For more information, see:
            http://activemq.apache.org/producer-flow-control.html
          -->
          <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage percentOfJvmHeap="70" />
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="100 gb"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="50 gb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>

        <!--
            The transport connectors expose ActiveMQ over a given protocol to
            clients and other brokers. For more information, see:

            http://activemq.apache.org/configuring-transports.html
        -->
        <networkConnectors>
		  <networkConnector uri="multicast://default" duplex="false"/>  <!--  这里defalut广播名可以是随意取的  -->
	   </networkConnectors>
        <transportConnectors>
            <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
            <transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600" discoveryUri="multicast://default">
            </transportConnector>
            <transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
        </transportConnectors>

        <!-- destroy the spring context on shutdown to stop jetty -->
        <shutdownHooks>
            <bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
        </shutdownHooks>

    </broker>

    <!--
        Enable web consoles, REST and Ajax APIs and demos
        The web consoles requires by default login, you can disable this in the jetty.xml file

        Take a look at ${ACTIVEMQ_HOME}/conf/jetty.xml for more details
    -->
    <import resource="jetty.xml"/>

</beans>
<!-- END SNIPPET: example -->

2.2 activemq1.xml

同activemq0.xml文件,修改里面brokerName="broker1"

2.3 activemq2.xml

同activemq0.xml文件,修改里面brokerName="broker2"

3、创建configMap  cm-activemq

[K8S@k8s-master activemq-cluster]$ pwd
/home/K8S/k8s-project/activemq-cluster
[K8S@k8s-master activemq-cluster]$ tree
.
├── activemq-cluster.yaml
└── xmls
    ├── activemq0.xml
    ├── activemq1.xml
    └── activemq2.xml

1 directory, 4 files
[K8S@k8s-master activemq-cluster]$ kubectl create cm cm-activemq --from-file ./xmls/ -n activemq-cluster #根据文件创建configMap

4、创建activemq-cluster.yaml

注意1:因为这里每个实例要映射到配置文件不同,所以这里用了3个StatefulSet来分别独立管理每一个pod的创建

注意2:

  •  #测试过apache/activemq-classic,可以修改borkerName但是集群网络不能互通
  •  #测试过webcenter/activemq,修改brokerName无效,故此只能2个实例集群,多台实例无效
  •  #最终使用这个镜像rmohr/activemq  能实现多台实例集群

apiVersion: v1
kind: Service
metadata:
  name: activemq-cluster
  namespace: activemq-cluster
spec:
  selector:
    app: activemq-cluster
  ports:
    - port: 8161
      targetPort: 8161
      protocol: TCP
      name: admin
      nodePort: 30168
    - port: 61616
      targetPort: 61616
      protocol: TCP
      name: tcp
      nodePort: 30618
  type: NodePort
---
apiVersion: apps/v1
kind: StatefulSet
metadata:   
  name: activemq-cluster0  #这里根据集群数量配置多个statefulSet,因为每个deploy中容器挂在的activemq文件不同
  namespace: activemq-cluster
spec:
  serviceName: activemq-headless-cluster
  replicas: 1
  selector:
    matchLabels:
      name: activemq-cluster0 # statufulSet管理的pod标签
  template:
    metadata:
      labels:
        name: activemq-cluster0  #Pod的标签
        app: activemq-cluster
    spec:
      containers:
        - name: activemq
		  
			#测试过apache/activemq-classic,可以修改borkerName但是集群网络不能互通
            #测试过webcenter/activemq,修改brokerName无效,故此只能2个实例集群,多台实例无效
			#最终使用这个镜像能实现多台实例集群
          image: rmohr/activemq     
          ports:
            - containerPort: 61616
              name: tcp
            - containerPort: 8161
              name: admin
          volumeMounts:
            - name: config-activemq
              mountPath: /opt/activemq/conf/activemq.xml   #configmap中的activemq0.xml文件挂在到容器的这个目录下
              subPath: activemq.xml
      volumes:
        - name: timezone
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
        - name: config-activemq
          configMap:
            name: cm-activemq
            items: 
              - key: activemq0.xml  # cm-activemq 的key
                path: activemq.xml  # cm-activemq 的key对应的值的以文本名为activemq.xml的形式展现
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: activemq-cluster1
  namespace: activemq-cluster
spec:
  serviceName: activemq-headless-cluster
  replicas: 1
  selector:
    matchLabels:
      name: activemq-cluster1
  template:
    metadata:
      labels:
        name: activemq-cluster1
        app: activemq-cluster
    spec:
      containers:
        - name: activemq
          image: rmohr/activemq
          ports:
            - containerPort: 61616
              name: tcp
            - containerPort: 8161
              name: admin
          volumeMounts:
            - name: config-activemq
              mountPath: /opt/activemq/conf/activemq.xml
#              mountPath: /opt/apache-activemq/conf/activemq.xml
              subPath: activemq.xml
      volumes:
        - name: timezone
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
        - name: config-activemq
          configMap:
            name: cm-activemq
            items: 
              - key: activemq1.xml
                path: activemq.xml
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: activemq-cluster2
  namespace: activemq-cluster
spec:
  serviceName: activemq-headless-cluster
  replicas: 1
  selector:
    matchLabels:
      name: activemq-cluster2
  template:
    metadata:
      labels:
        name: activemq-cluster2
        app: activemq-cluster
    spec:
      containers:
        - name: activemq
          image: rmohr/activemq
          # image: apache/activemq-classic:latest
          ports:
            - containerPort: 61616
              name: tcp
            - containerPort: 8161
              name: admin
          volumeMounts:
            - name: config-activemq
              mountPath: /opt/activemq/conf/activemq.xml
#              mountPath: /opt/apache-activemq/conf/activemq.xml
              subPath: activemq.xml
      volumes:
        - name: timezone
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
        - name: config-activemq
          configMap:
            name: cm-activemq
            items: 
              - key: activemq2.xml
                path: activemq.xml
---
apiVersion: v1
kind: Service
metadata:
  name: activemq-headless-cluster
  namespace: activemq-cluster
spec:
  ports:
  - port: 61616
    targetPort: tcp
    name: tcp
  - port: 8161
    targetPort: web
    name: web
  - port: 1883
    targetPort: mqtt
    name: mqtt
  selector:
    app: activemq-cluster

5、执行命令部署

[K8S@k8s-master activemq-cluster]$ kubectl apply -f activemq-cluster.yaml 

6、部署成功,查看结果

当前访问的是borker0,这里每次访问的borker可能不一样,也有可能是borker1、borker2

查看Connections和Network存在2个连接说明3台实例集群成功 

看当前访问的Connections页面,这里显示borker0和broker2,说明我们当前访问的是broker1

看当前访问的Network页面,这里显示borker0和broker1,说明我们当前访问的是broker2 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/552434.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Facade 外观

意图 为子系统中的一组接口提供一个一致的界面&#xff0c;Facade模式定义了一个高层接口&#xff0c;这个接口使得这一字系统更加容易使用。 结构 其中&#xff1a; Facade知道哪些子系统负责处理请求&#xff1b;将客户的请求代理给适当的子系统对象。 Subsystem classes…

QGIS插件Geo-SAM使用(基于SAM半自动标注遥感图像)

0.Geo-SAM介绍 Geo-SAM是一个QGIS插件&#xff0c;旨在帮助人们在使用大尺寸地理空间栅格图像时有效地分割、描绘或标记地貌。Segment Anything Model &#xff08;SAM&#xff09; 是一个具有超能力的基础 AI 模型&#xff0c;但模型大小巨大&#xff0c;即使使用现代 GPU&am…

C++学习进阶版(一):用C++写简单的状态机实现

目录 一、基础知识 1、状态机 2、四大要素 3、描述方式 4、设计步骤 5、实现过程中需注意 &#xff08;1&#xff09; 状态定义 &#xff08;2&#xff09; 状态转换规则 &#xff08;3&#xff09; 输入处理 &#xff08;4&#xff09; 状态机的封装 &#xff08;5…

Nginx第2篇-HTTPS配置教程

背景 我最近做个项目要上线&#xff0c;接口部署到服务器&#xff0c;总不能给别人个ip地址加端口吧&#xff0c;而且小程序上线要有接口不能是ip和http协议&#xff0c;必须是https协议。这里记录下使用Nginx配置HTTPS的过程&#xff0c;主要包含以下三部分。 申请域名SSL证…

远程预付费集抄管理系统

远程预付费集抄管理系统是一种用于能源(如水、电等)预付费管理的智能化系统&#xff0c;其核心在于提供远程集中抄表和费用管理服务。这种系统通过集成先进的远程监控技术和预付费管理功能&#xff0c;为用户提供了便捷的能源管理解决方案。下文将从核心功能、工作流程、优势特…

离世界模型更近一步!Meta开源OpenEQA,评估AI Agent情景理解能力

Yann LeCun 朝着 “世界模型” 又近了一步。 Meta最新的开源工作OpenEQA&#xff1a;从文字模型到世界模型&#xff0c;可以像人一样记忆、推理的新基准&#xff0c;AI理解物理空间又近了一步。 场景1: 假设你正准备离开家&#xff0c;但找不到你的工牌。 现在&#xff0c;…

5.2 iHRM人力资源 - 员工管理 - 使用文件导入导出员工

iHRM人力资源 - 员工管理 - 导入导出员工 文章目录 iHRM人力资源 - 员工管理 - 导入导出员工一、员工导出Excel二、员工导入Excel2.1 Excel导入组件封装2.2 下载导入模板2.3 Excel 导入功能 三、删除员工 一、员工导出Excel 这个地方涉及一个接口二进制流blob 就是下面这一大片…

使用嘉立创EDA打开JSON格式的PCB及原理图

一、将PCB和原理图放同一文件夹 并打包成.zip文件 二、打开嘉立创EDA并导入.zip文件 文件 -> 导入 -> 嘉立创EDA标准版/专业版 三、选择.zip文件并选择 “导入文件并提取库” 四、自定义工程路径 完成导入并转换为.eprj文件 五、视频教学 bilibili_使用立创EDA打开JSO…

香港科技大学广州|数据科学与分析学域硕博招生宣讲会—华东师范大学专场

时间&#xff1a;2024年4月25日&#xff08;星期四&#xff09;13:30 地点&#xff1a;华东师范大学普陀校区文附楼507 报名链接&#xff1a;https://www.wjx.top/vm/Q0cKTUI.aspx# 跨学科研究领域 *数据驱动的人工智能和机器学习 *统计学习和建模 工业和商业分析 *特定行业…

float实现文字环绕效果

实现效果如下&#xff1a; 一、问题分析 接到需求就是右侧显示图片&#xff0c;左侧显示一个标题和内容。第一时间没有想到其他的布局的好的实现方式&#xff0c;就想到了float布局。于是乎去查了下有关float的文档&#xff0c;float 是相当的好用。 float定义如下&#xf…

kibana源码编译

一、安装nodejs16.14.2及yarn &#xff08;一&#xff09;nodejs 1、下载 https://cdn.npmmirror.com/binaries/node/v16.14.2/node-v16.14.2-linux-x64.tar.gz2、解压 tar -zxf node-v16.14.2-linux-x64.tar.gz -C /app cd /app mv node-v16.14.2-linux-x64 node3、配置环…

在Linux系统中设定延迟任务

一、在系统中设定延迟任务要求如下&#xff1a; 要求&#xff1a; 在系统中建立easylee用户&#xff0c;设定其密码为easylee 延迟任务由root用户建立 要求在5小时后备份系统中的用户信息文件到/backup中 确保延迟任务是使用非交互模式建立 确保系统中只有root用户和easylee用户…

Matlab|基于改进遗传算法的配电网故障定位

目录 1 主要内容 2 部分代码 3 部分程序结果 4 下载链接 1 主要内容 该程序复现文章《基于改进遗传算法的配电网故障定位》&#xff0c;将改进的遗传算法应用于配电网故障定位中, 并引入分级处理思想, 利用配电网呈辐射状的特点, 首先把整个配电网划分为主干支路和若干独立…

2024年阿里云4核8G配置云服务器价格低性能高!

阿里云4核8G服务器租用优惠价格700元1年&#xff0c;配置为ECS通用算力型u1实例&#xff08;ecs.u1-c1m2.xlarge&#xff09;4核8G配置、1M到3M带宽可选、ESSD Entry系统盘20G到40G可选&#xff0c;CPU采用Intel(R) Xeon(R) Platinum处理器&#xff0c;阿里云优惠 aliyunfuwuqi…

【Python】高级进阶(专版提升3)

Python 1 程序结构1.1 模块 Module1.1.1 定义1.1.2 作用1.1.3 导入1.1.3.1 import1.1.3.2 from import 1.1.4 模块变量1.1.5 加载过程1.1.6 分类 1.2 包package1.2.1 定义1.2.2 作用1.2.3 导入1.1.3.1 import1.1.3.2 from import 2 异常处理Error2.1 异常2.2 处理 3 迭代3.1 可…

TinyEMU源码分析之访存处理

TinyEMU源码分析之访存处理 1 访存指令介绍2 指令译码3 地址转换3.1 VA与PA3.2 VA转PA 4 判断地址空间范围5 执行访存操作5.1 访问RAM内存5.2 访问非RAM&#xff08;设备&#xff09;内存 6 访存处理流程图 本文属于《 TinyEMU模拟器基础系列教程》之一&#xff0c;欢迎查看其…

数据结构排序算法

排序也称排序算法(SortAlgorithm)&#xff0c;排序是将一组数据&#xff0c;依指定的顺序进行排列的过程。 分类 内部排序【使用内存】 指将需要处理的所有数据都加载到内部存储器中进行排序插入排序 直接插入排序希尔排序 选择排序 简单选择排序堆排序 交换排序 冒泡排序快速…

两阶段提交进阶

两阶段提交之进阶 上一节我们讲了&#xff0c;两阶段提交逻辑上的表现&#xff0c;其实较为肤浅&#xff0c;并且偏向理论&#xff0c;可能大家都能看懂&#xff0c;但是如果放入实际的mysql应用中并联系事务和日志进行分析&#xff0c;又会怎么样呢&#xff1f; 这次就专门分…

Unity类银河恶魔城学习记录13-1 p142 Save system源代码

Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释&#xff0c;可供学习Alex教程的人参考 此代码仅为较上一P有所改变的代码 【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili FileDataHandler.cs using System; using System.IO; using UnityEngine; p…

软考133-上午题-【软件工程】-软件项目估算

一、COCOMO 估算模型 COCOMO 模型是一种精确的、易于使用的成本估算模型。 COCOMO 模型按其详细程度分为&#xff1a;基本 COCOMO 模型、中级 COCOMO 模型和详细 COCOMO 模型。 1&#xff09;基本 COCOMO 模型 基本 COCOMO 模型是一个静态单变量模型&#xff0c;用于对整个软…
最新文章