K8S如何部署ActiveMQ(单机、集群)

news2024/11/17 19:35:29

3.png

前言

大家好,在今天的讨论中,我们将深入研究如何将ActiveMQ迁移到云端,以便更好地利用Kubernetes的容器调度和资源管理能力,确保ActiveMQ的高可用性和可扩展性。

ActiveMQ是Apache开源组织推出的一款开源的、完全支持JMS1.1和J2EE1.4规范的JMS Provider实现的消息中间件(MOM)。它是所有开源项目中最流行也最强大的开源消息中间件,主要用于分布式系统架构中,可以实现高可用、高性能、可伸缩、易用和安全的企业级面向消息服务的系统。

ActiveMQ的核心概念主要包括以下几个方面:

  • 消息:消息是ActiveMQ中最基本的单位,它包含了实际需要传输的数据。
  • 主题(Topic):主题是一种广播类型的消息模式,一个生产者向一个主题发送消息,而所有的消费者都可以接收到这个消息。这种方式非常适合于需要将一条消息分发到多个消费者的场景。
  • 队列(Queue):队列是一种点对点的消息模式,一个生产者向一个队列发送消息,只有一个消费者能接收到这个消息。这种方式非常适合于需要将一条消息发送给一个特定的消费者的场景。
  • 消费者(Consumer):消费者是从队列或主题中获取并处理消息的应用程序。
  • 生产者(Producer):生产者是创建并向队列或主题发送消息的应用程序。
  • 消息代理(Broker):消息代理是ActiveMQ的核心组件,它负责接收、存储和转发消息。在ActiveMQ中,每一个运行的实例都是一个消息代理。
  • JMS(Java Message Service):Java消息服务是关于面向消息中间件的API,用于在两个应用程序之间或者分布式系统中发送消息,进行异步通信。JMS与具体的平台无关,绝大多数MOM(Message Oriented Middleware)提供商都对JMS提供了支持,例如ActiveMQ就是其中一个实现。

一、部署单机ActiveMQ

步骤一:创建ConfigMap

首先,我们需要创建ConfigMap,用来存储和管理ActiveMQ的相关配置。

apiVersion: v1
kind: ConfigMap
metadata:
  name: activemq-config-single
  namespace: 你实际的namespace
data:
  activemq.xml: |
    <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>
       <!-- Allows accessing the server log -->
        <bean id="logQuery" class="io.fabric8.insight.log.log4j.Log4jLogQuery"
              lazy-init="false" scope="singleton"
              init-method="start" destroy-method="stop">
        </bean>
        <!--
            The <broker> element is used to configure the ActiveMQ broker.
        -->
        <broker xmlns="http://activemq.apache.org/schema/core" brokerName="activemq-single" dataDirectory="${activemq.data}">	
            <plugins>
                <simpleAuthenticationPlugin>
                <users>
                <authenticationUser username="my_mq_test" password="my_mq_test" groups="users,admins"/>
                </users>
                </simpleAuthenticationPlugin>
            </plugins>
            <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
            -->
            <transportConnectors>
                <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
                <transportConnector name="openwire" uri="tcp://0.0.0.0:30226?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
                <transportConnector name="amqp" uri="amqp://0.0.0.0:30227?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
                <transportConnector name="stomp" uri="stomp://0.0.0.0:30228?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
                <transportConnector name="mqtt" uri="mqtt://0.0.0.0:30229?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
                <transportConnector name="ws" uri="ws://0.0.0.0:30230?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>
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: activemq-config-jetty-realm
  namespace: 你实际的namespace
data:
  jetty-realm.properties: |
    admin: my_mq_test, admin
    user: user, user

在上面的配置中,我们在activemq.xml中使用简单授权配置以及修改了默认的端口号以提高服务的安全性;在jetty-realm.properties中配置了web端控制台的登录用户名和密码,格式为:

用户名 : 密码 ,角色名

步骤二:创建Deployment

接下来,我们需要创建一个Deployment,用来定义ActiveMQ的副本数量、镜像版本等相关信息。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: activemq-single
  namespace: 你实际的namespace
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  selector:
    matchLabels:
      app: activemq-single
  strategy:
    rollingUpdate:
      maxSurge: 50%
      maxUnavailable: 50%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: activemq-single
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: project.node
                    operator: In
                    values:
                      - 你实际的节点名称
      volumes:
        - name: timezone
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
        - name: config-activemq
          configMap: 
            name: activemq-config-single
        - name: jetty-realm
          configMap: 
            name: activemq-config-jetty-realm
      containers:
        - name: activemq
          image: webcenter/activemq:5.14.3
          imagePullPolicy: IfNotPresent
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts: 
            - name: config-activemq
              mountPath: /opt/activemq/conf/activemq.xml
              subPath: activemq.xml
            - name: jetty-realm
              mountPath: /opt/activemq/conf/jetty-realm.properties
              subPath: jetty-realm.properties
          env:
            - name: HOST_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
            - name: POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: TZ
              value: "Asia/Shanghai"

在上述配置中,我们定义了一个名为activemq-single的Deployment。在这里,我们使用的镜像已经版本为webcenter/activemq:5.14.3,并且使用了之前创建的ConfigMap中的配置文件。

步骤三:创建Service

然后,我们还需要创建一个Service,用来将K8S集群中运行的ActiveMQ实例暴露为可访问的服务。

apiVersion: v1  
kind: Service  
metadata:  
  name: service-activemq-single
  namespace: 你实际的namespace
spec:  
  selector:  
    app: activemq-single
  type: NodePort
  sessionAffinity: None
  ports:
    - name: activemq-admin
      port: 8161
      targetPort: 8161
      nodePort: 30225
    - name: activemq-tcp
      port: 30226
      targetPort: 30226
      nodePort: 30226
    - name: activemq-amqp
      port: 30227
      targetPort: 30227
      nodePort: 30227
    - name: activemq-stomp
      port: 30228
      targetPort: 30228
      nodePort: 30228
    - name: activemq-mqtt
      port: 30229
      targetPort: 30229
      nodePort: 30229
    - name: activemq-ws
      port: 30230
      targetPort: 30230
      nodePort: 30230

步骤四:验证单机ActiveMQ

  • 首先,我们启动一个生产者链接到刚部署的单机ActiveMQ上,并且向名称为mdm_distribute_CostCenter的队列中发送了一条消息,消息内容为mdm_distribute_CostCenter

3.png

  • 接下来,我们再启动一个消息者同样链接到刚部署的单机ActiveMQ上,并且监听名为mdm_distribute_CostCenter的队列。

4.png

  • 最后,我们可以在web端的admin页面查看相应队列中的记录

6.png

小结

以上就是在K8S中部署单机ActiveMQ的相关步骤。通过这些步骤,我们成功地使用无状态的Deployment部署了一个可用的单机ActiveMQ。

二、部署ActiveMQ集群(networks of brokers)

步骤一:创建ConfigMap

与单机版类似,我们同样需要创建一个ConfigMap来存储和管理ActiveMQ的相关配置。

apiVersion: v1
kind: ConfigMap
metadata:
  name: activemq-config-node-0
  namespace: 你实际的namespace
data:
  activemq.xml: |
    <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>
       <!-- Allows accessing the server log -->
        <bean id="logQuery" class="io.fabric8.insight.log.log4j.Log4jLogQuery"
              lazy-init="false" scope="singleton"
              init-method="start" destroy-method="stop">
        </bean>
        <!--
            The <broker> element is used to configure the ActiveMQ broker.
        -->
        <broker xmlns="http://activemq.apache.org/schema/core" brokerName="activemq-node-0" dataDirectory="${activemq.data}">
            <networkConnectors>
                <networkConnector userName="my_mq_test" password="my_mq_test" uri="static:(tcp://你的实际ip:30220)" duplex="true"/>
            </networkConnectors>		
            <plugins>
                <simpleAuthenticationPlugin>
                <users>
                <authenticationUser username="my_mq_test" password="my_mq_test" groups="users,admins"/>
                </users>
                </simpleAuthenticationPlugin>
            </plugins>
            <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
            -->
            <transportConnectors>
                <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
                <transportConnector name="openwire" uri="tcp://0.0.0.0:30218?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
                <transportConnector name="amqp" uri="amqp://0.0.0.0:30221?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
                <transportConnector name="stomp" uri="stomp://0.0.0.0:30222?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
                <transportConnector name="mqtt" uri="mqtt://0.0.0.0:30223?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
                <transportConnector name="ws" uri="ws://0.0.0.0:30224?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>
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: activemq-config-node-1
  namespace: 你实际的namespace
data:
  activemq.xml: |
    <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>
       <!-- Allows accessing the server log -->
        <bean id="logQuery" class="io.fabric8.insight.log.log4j.Log4jLogQuery"
              lazy-init="false" scope="singleton"
              init-method="start" destroy-method="stop">
        </bean>
        <!--
            The <broker> element is used to configure the ActiveMQ broker.
        -->
        <broker xmlns="http://activemq.apache.org/schema/core" brokerName="activemq-node-0" dataDirectory="${activemq.data}">		
            <networkConnectors>
                <networkConnector userName="my_mq_test" password="my_mq_test" uri="static:(tcp://你的实际ip:30218)" duplex="true"/>
            </networkConnectors>
            <plugins>
                <simpleAuthenticationPlugin>
                <users>
                <authenticationUser username="my_mq_test" password="my_mq_test" groups="users,admins"/>
                </users>
                </simpleAuthenticationPlugin>
            </plugins>
            <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
            -->
            <transportConnectors>
                <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
                <transportConnector name="openwire" uri="tcp://0.0.0.0:30220?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
                <transportConnector name="amqp" uri="amqp://0.0.0.0:30221?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
                <transportConnector name="stomp" uri="stomp://0.0.0.0:30222?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
                <transportConnector name="mqtt" uri="mqtt://0.0.0.0:30223?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
                <transportConnector name="ws" uri="ws://0.0.0.0:30224?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>
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: activemq-config-jetty-realm
  namespace: 你实际的namespace
data:
  jetty-realm.properties: |
    admin: my_mq_test, admin
    user: user, user

步骤二:创建Deployment

接下来,我们需要创建2个Deployment,分别对应ActiveMQ集群中的2个节点。主要区别在于使用ConfigMap中的配置文件的不同和containers中暴露的端口不同。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: activemq-node-0
  namespace: 你实际的namespace
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  selector:
    matchLabels:
      app: activemq-node-0
  strategy:
    rollingUpdate:
      maxSurge: 50%
      maxUnavailable: 50%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: activemq-node-0
        name: activemq-node
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: project.node
                    operator: In
                    values:
                      - 你实际的节点名称
      volumes:
        - name: timezone
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
        - name: config-activemq
          configMap: 
            name: activemq-config-node-0
        - name: jetty-realm
          configMap: 
            name: activemq-config-jetty-realm
      containers:
        - name: activemq
          image: webcenter/activemq:5.14.3
          imagePullPolicy: IfNotPresent
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts: 
            - name: config-activemq
              mountPath: /opt/activemq/conf/activemq.xml
              subPath: activemq.xml
            - name: jetty-realm
              mountPath: /opt/activemq/conf/jetty-realm.properties
              subPath: jetty-realm.properties
          env:
            - name: HOST_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
            - name: POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: TZ
              value: "Asia/Shanghai"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: activemq-node-1
  namespace: 你实际的namespace
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  selector:
    matchLabels:
      app: activemq-node-1
  strategy:
    rollingUpdate:
      maxSurge: 50%
      maxUnavailable: 50%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: activemq-node-1
        name: activemq-node
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: project.node
                    operator: In
                    values:
                      - 你实际的节点名称
      volumes:
        - name: timezone
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
        - name: config-activemq
          configMap: 
            name: activemq-config-node-1
        - name: jetty-realm
          configMap: 
            name: activemq-config-jetty-realm
      containers:
        - name: activemq
          image: webcenter/activemq:5.14.3
          imagePullPolicy: IfNotPresent
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts: 
            - name: config-activemq
              mountPath: /opt/activemq/conf/activemq.xml
              subPath: activemq.xml
            - name: jetty-realm
              mountPath: /opt/activemq/conf/jetty-realm.properties
              subPath: jetty-realm.properties
          env:
            - name: HOST_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
            - name: POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: TZ
              value: "Asia/Shanghai"

步骤三:创建Service

然后,我们还需要来创建Service,用来将K8S集群中运行的ActiveMQ实例暴露为可访问的服务。这里同样需要创建2个Service,分别对应步骤二中的2个Deployment,还需要1个Service来暴露公共的端口。

apiVersion: v1  
kind: Service  
metadata:  
  name: service-activemq-common
  namespace: 你实际的namespace
spec:  
  selector:  
    name: activemq-node
  type: NodePort
  sessionAffinity: None
  ports:
    - name: activemq-amqp
      port: 30221
      targetPort: 30221
      nodePort: 30221
    - name: activemq-stomp
      port: 30222
      targetPort: 30222
      nodePort: 30222
    - name: activemq-mqtt
      port: 30223
      targetPort: 30223
      nodePort: 30223
    - name: activemq-ws
      port: 30224
      targetPort: 30224
      nodePort: 30224
---
apiVersion: v1
kind: Service
metadata:
  name: service-activemq-node-0
  namespace: 你实际的namespace
spec:
  selector:
    app: activemq-node-0
  type: NodePort
  sessionAffinity: None
  ports:
    - name: activemq-admin
      port: 8161
      targetPort: 8161
      nodePort: 30217
    - name: activemq-tcp
      port: 30218
      targetPort: 30218
      nodePort: 30218
---
apiVersion: v1
kind: Service
metadata:
  name: service-activemq-node-1
  namespace: 你实际的namespace
spec:
  selector:
    app: activemq-node-1
  type: NodePort
  sessionAffinity: None
  ports:
    - name: activemq-admin
      port: 8161
      targetPort: 8161
      nodePort: 30219
    - name: activemq-tcp
      port: 30220
      targetPort: 30220
      nodePort: 30220

步骤五:验证ActiveMQ集群

  • 首先,我们启动一个生产者链接到刚部署的集群ActiveMQ上,并且向名称为mdm_distribute_Employee的队列中发送了一条消息,消息内容为mdm_distribute_Employee

2.png

  • 接下来,我们再启动一个消息者同样链接到刚部署的集群ActiveMQ上,并且监听名为mdm_distribute_Employee的队列。

1.png

  • 最后,我们可以在web端的admin页面查看相应队列中的记录

5.png

小结

在K8S中部署ActiveMQ集群的相关步骤已经介绍完毕。通过这些步骤,我们成功地使用无状态的Deployment部署了一个可用的ActiveMQ集群。

结论

本文详尽地探讨了在K8S环境中部署ActiveMQ单机与集群的详细步骤。细读全文,我们可以发现,ActiveMQ的数据存储仍在POD中,这是由于业务需求所决定的。当发送MQ消息时,数据需要先被写入数据库,然后再进行发送,因此ActiveMQ的数据存储变得无关紧要。当然,我们还可以选择使用pvc或者直接挂载到宿主机等方式来保存数据。相较于传统的手动部署方式,利用K8S进行部署能够带来更高的便捷性和效率,从而更快速地完成ActiveMQ集群的部署和管理任务。

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

IBM X3650M4安装ESXI6.5卡在/lsl_mr3.v00

环境&#xff1a;IBM X3650M4服务器双盘配置raid1&#xff0c;通过rufus制作启动U盘&#xff0c;安装VMware Vsphere 5.5系统 问题&#xff1a;卡在/lsi_mr3.v00界面无法往下运行&#xff08;两台配置一样的机器遇到同样的问题&#xff09; 解决方案&#xff1a; 直接在U盘根…

软件设计中如何画各类图之二深入解析数据流图(DFD):系统设计与分析的关键视觉工具

目录 1 前言2 数据流图&#xff08;DFD&#xff09;的重要性3 数据流图的符号说明4 清晰的数据流图步骤4.1 确定系统边界4.2 识别数据流4.3 定义处理过程4.4 确认数据存储4.5 建立数据流动的连线4.6 细化和优化 5 数据流图的用途6 使用场景7 实际应用场景举例8 结语 1 前言 当…

Eclipse 设置try-cacth 默认格式

设置面板 第一处 第二处 其中NsRuntimeException是自定义的异常处理。这样设置后&#xff0c;打开代码补全功能&#xff0c;输入try回车就会默认显示设置的代码

雅可比矩阵(Jacobian Matrix)

假设给定一个从n维欧式空间到m维欧式空间的变换: 雅可比矩阵就是将一阶偏导数排列成一个m行、n列形式的矩阵&#xff0c;记作&#xff1a; 举一个例子&#xff1a; 雅可比矩阵等于&#xff1a;

新手如何对一个web网页进行一次渗透测试

新手如何对一个web网页进行一次渗透测试 什么是渗透测试? 在获得web服务运营的公司书面授权的情况下&#xff0c;模拟攻击者的行为&#xff0c;以确定系统的脆弱性&#xff0c;并为保护系统提供有效的建议。 渗透测试和红蓝对抗的区别 渗透测试和红蓝对抗别再傻傻分不清楚…

ChatGPT重磅升级!集简云支持GPT4 Turbo Vision, GPT4 Turbo, Dall.E 3,Whisper等最新模型

在11月7日凌晨&#xff0c;OpenAI全球开发者大会宣布了 GPT-4的一次大升级&#xff0c;推出了 GPT-4 Turbo号称为迄今为止最强的大模型。 此次GPT-4的更新和升级在多个方面显示出强大的优势和潜力。为了让集简云用户能快速体验新模型的能力&#xff0c;我们第一时间整理了大会发…

Leetcode103 二叉树的锯齿形层序遍历

二叉树的锯齿形层序遍历 题解1 层序遍历双向队列 给你二叉树的根节点 root &#xff0c;返回其节点值的 锯齿形层序遍历 。&#xff08;即先从左往右&#xff0c;再从右往左进行下一层遍历&#xff0c;以此类推&#xff0c;层与层之间交替进行&#xff09;。 提示&#xff1a…

力扣每日一题-统计和小于目标的下标对数目-2023.11.24

力扣每日一题&#xff1a;统计和小于目标的下标对数目 开篇 今天这道力扣打卡题写得我好狼狈&#xff0c;一开始思路有点问题&#xff0c;后面就是对自己的代码到处缝缝补补&#xff0c;最后蒙混过关。只能分享一下大佬的代码&#xff0c;然后我帮大家分享代码的思路。 题目链…

迈巴赫S480升级主动式氛围灯 浪漫婉转的气氛

主动式氛围灯有263个可多色渐变的LED光源&#xff0c;营造出全情沉浸的动态光影氛围。结合智能驾驶辅助系统&#xff0c;可在转向或检测到危险时&#xff0c;予以红色环境光提示&#xff0c;令光影艺术彰显智能魅力。配件有6个氛围灯&#xff0c;1个电脑模块。 1、气候&#xf…

2023年亚太杯数学建模A题——深度学习苹果图像识别(思路+模型+代码+成品)

Image Recognition for Fruit-Picking Robots 水果采摘机器人的图像识别功能 问题 1&#xff1a;计数苹果 根据附件 1 中提供的可收获苹果的图像数据集&#xff0c;提取图像特征&#xff0c;建立数学模型&#xff0c;计算每幅图像中的苹果数量&#xff0c;并绘制附件 1 中所有…

FANUC机器人系统配置相关--系统变量介绍

FANUC机器人系统配置相关–系统变量介绍 系统配置页相关变量 1- 停电处理$SEMIPOWERFL = TRUE(有效)/FALSE(无效) 2- 停电处理中的I/O $PWF_IO = 1(不恢复)/2(仿真恢复)/3(解除仿真)/4(恢复所有) 3- 停电处理无效时自动执行的程序 $PWR_NORMAL = ‘’ 4- 停电处理有效时自动…

VINS-MONO代码解读----vins_estimator(鲁棒初始化部分)

0. 前言 整个初始化部分的pipeline如下所示&#xff0c;参照之前的博客&#xff0c;接下来根据代码一步步讲解。 1. 旋转约束标定旋转外参Rbc 上回讲了processImage中addFeatureCheckParallax完成了对KF的筛选&#xff0c;我们知道了2nd是否为KF&#xff0c;接下来是初始化…

Diffusion Model: DDPM

本文相关内容只记录看论文过程中一些难点问题&#xff0c;内容间逻辑性不强&#xff0c;甚至有点混乱&#xff0c;因此只作为本人“备忘”&#xff0c;不建议其他人阅读。 Denoising Diffusion Probabilistic Models: https://arxiv.org/abs/2006.11239 DDPM 一、基于 已知…

使用Linux JumpServer堡垒机本地部署与远程访问

&#x1f308;个人主页&#xff1a;聆风吟 &#x1f525;系列专栏&#xff1a;网络奇遇记、Cpolar杂谈 &#x1f516;少年有梦不应止于心动&#xff0c;更要付诸行动。 文章目录 &#x1f4cb;前言一. 安装Jump server二. 本地访问jump server三. 安装 cpolar内网穿透软件四. 配…

mysql索引分为哪几类,聚簇索引和非聚簇索引的区别,MySQL索引失效的情况有哪几种情况,MySQL索引优化的手段,MySQL回表

文章目录 索引分为哪几类&#xff1f;聚簇索引和非聚簇索引的区别什么是[聚簇索引](https://so.csdn.net/so/search?q聚簇索引&spm1001.2101.3001.7020)&#xff1f;&#xff08;重点&#xff09;非聚簇索引 聚簇索引和非聚簇索引的区别主要有以下几个&#xff1a;什么叫回…

vcsa6.7 5480无法登录

停电维护硬件后&#xff0c;发现vcsa异常&#xff0c;https://ip:5480无法登录&#xff0c;https://ip/ui正常&#xff0c;ssh登录页正常 kb资料 通过端口 5480 登录到 VMware vCenter Server Appliance Web 控制台失败 (2120477) 操作过程 Connecting to 192.16.20.31:22..…

LLMLingua:集成LlamaIndex,对提示进行压缩,提供大语言模型的高效推理

大型语言模型(llm)的出现刺激了多个领域的创新。但是在思维链(CoT)提示和情境学习(ICL)等策略的驱动下&#xff0c;提示的复杂性不断增加&#xff0c;这给计算带来了挑战。这些冗长的提示需要大量的资源来进行推理&#xff0c;因此需要高效的解决方案&#xff0c;本文将介绍LLM…

2023大模型安全解决方案白皮书

今天分享的是大模型系列深度研究报告&#xff1a;《2023大模型安全解决方案白皮书》。 &#xff08;报告出品方&#xff1a;百度安全&#xff09; 报告共计&#xff1a;60页 前言 在当今迅速发展的数字化时代&#xff0c;人工智能技术正引领着科技创新的浪潮而其中的大模型…

一键填充字幕——Arctime pro

之前的博客中&#xff0c;我们聊到了PR这款专业的视频制作软件&#xff0c;但是pr有许多的功能需要搭配使用&#xff0c;相信不少小伙伴在剪辑视频时会发现一个致命的问题&#xff0c;就是字幕编写。伴随着人们对字幕需求的逐渐增加&#xff0c;这款软件便应运而生~ 相信应该有…

汽车业务增长乏力!又被法雷奥告上法庭,英伟达有点「难」

随着智能汽车进入「降本增效」的关键周期&#xff0c;对于上游产业链&#xff0c;尤其是芯片的影响也在持续发酵。 本周&#xff0c;英伟达发布截至2023年10月29日的第三季度财报数据&#xff0c;整体业务收入为181.2亿美元&#xff0c;比去年同期增长206%&#xff0c;比上一季…