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

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.mfbz.cn/a/187153.html

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

相关文章

vue2:组件中extends的使用

上一篇文章中我对mixin的使用进行了一个使用和测试,这里对extend进行一个使用,其实extend和mixin还是有区别的。 上一篇文章:vue2:mixin混入的使用-CSDN博客 不过也是看实际的业务场景,我们也可以使用extend完成和mixin几乎一摸一样的操作。 不废话,上代码 创建extendTest.…

位图的详细讲解

位运算操作符&#xff1a;或&#xff0c;与&#xff0c;异或&#xff0c;按位取反。 操作符 |两个中有一个是一则为一&两个都是一则为一^相同为零&#xff0c;不同为一~零变成一&#xff0c;一变成零 什么是位运算符: 位运算是直接对整型数据的二进制进行运算。 位图概念…

告别百度网盘,搭建自己的专属网盘 ——Cloudreve,不限制下载速度!

Cloudreve 是一个用 Go 语言写的公有网盘程序,我们可以用它来快速搭建起自己的网盘服务,公有云 / 私有云都可。 顺哥博客 先来看看文档介绍吧。 支持多家云存储驱动的公有云文件系统. 演示站 • 讨论社区 • 文档 • 下载 • Telegram 群组 • 许可证 :sparkles: 特性 :cl…

webshell之Laravel和yii

EvalLoader#load 免杀效果 EvalLoader#load分析 eval命令执行函数&#xff0c;参数可控 MockTrait#generate 免杀效果 MockTrait#generate函数分析 存在一个eval函数 MockTrait#generate 免杀效果 view#evaluateDynamicContent 免杀效果 view#evaluateDynamicContent分析 总结…

Facebook的特点优势

Facebook作为全球最大的社交媒体平台之一&#xff0c;同时也是最受欢迎的社交网站之一&#xff0c;Facebook具有许多独特的特点和优势。本文小编将说一些关于Facebook的特点及优势。 1、全球化 Facebook拥有数十亿的全球用户&#xff0c;覆盖了几乎所有国家和地区。这使得人们…

初学剪辑者找视频素材就上这6个网站

视频剪辑必备的6个素材网站&#xff0c;高清无水印&#xff0c;还可以免费下载&#xff0c;无版权限制&#xff0c;赶紧收藏起来&#xff01; 1、菜鸟图库 https://www.sucai999.com/video.html?vNTYxMjky 菜鸟图库网素材非常丰富&#xff0c;网站主要以设计类素材为主&#…

(4)BUUCTF-web-[极客大挑战 2019]EasySQL1

前言&#xff1a; 觉得这个题目挺有意义的&#xff0c;因为最近在学数据库&#xff0c;但是不知道在现实中有什么应用&#xff0c;所以学起来也没有什么兴趣&#xff0c;做了这个题目&#xff0c;发现数据库还是挺有用处的&#xff0c;哈哈 知识点&#xff1a; mysql 中and和…

2023-11-24--oracle--实验--[Merge 语句]

oracle--实验---Merge语句 1.认知Merge 语句 • merge 语句是 sql 语句的一种。在 SQL server 、 Oracle 数据库中可用&#xff0c; MySQL 中不可用。 • merge 用来合并 update 和 insert 语句。目的&#xff1a;通过 merge 语句&#xff0c;根据一张表&#xff08; 原数据表…

Let’s xrOS 一款让你优先体验社区创作者的 visionOS App工具

Let’s xrOS Apple Vision Pro 发布预示着空间计算时代的到来&#xff0c;让科技爱好者和开发者开始思考如何在新的交互、系统和硬件上打造独特的三维应用。 自 WWDC 2023 的发布会后&#xff0c;社交媒体上涌现了许多精美的 visionOS App 的效果图和演示视频&#xff0c;然而…

Windows核心编程 进程

目录 一、进程概述 二、创建进程相关API Winexec ShellExecute CreateProcess 三、进程退出相关API ExitProcess TerminateProcess GetCurrentProcess GetExitCodeProcess 四、如何理解虚拟内存空间 五、关于UAC 一、进程概述 进程&#xff1a;正在运行的程序 程…

set和map + multiset和multimap(使用+封装(RBTree))

set和map 前言一、使用1. set(1)、模板参数列表(2)、常见构造(3)、find和count(4)、insert和erase(5)、iterator(6)、lower_bound和upper_bound 2. multiset3. map(1)、模板参数列表(2)、构造(3)、modifiers和operations(4)、operator[] 4. multimap 二、封装RBTree迭代器原理R…

(11_23)构建高效数据流转的 ETL 系统:数据库 + Serverless 函数计算的最佳实践

作者&#xff5c;柳下 概述 随着企业规模和数据量的增长&#xff0c;数据的价值越来越受到重视。数据的变化和更新变得更加频繁和复杂&#xff0c;因此及时捕获和处理这些变化变得至关重要。为了满足这一需求&#xff0c;数据库 CDC&#xff08;Change Data Capture&#xff…

晶振为什么不能放置在PCB边缘

某行车记录仪&#xff0c;测试的时候要加一个外接适配器&#xff0c;在机器上电运行测试时发现辐射超标&#xff0c;具体频点是84MHz、144MHz、168MHz&#xff0c;需要分析其辐射超标产生的原因&#xff0c;并给出相应的对策。辐射测试数据如下&#xff1a; 图1&#xff1a;辐…

B/S前后端分离的Java医院云HIS信息管理系统源码(LIS源码+电子病历源码)

HIS系统采用主流成熟技术开发&#xff0c;软件结构简洁、代码规范易阅读&#xff0c;SaaS应用&#xff0c;全浏览器访问前后端分离&#xff0c;多服务协同&#xff0c;服务可拆分&#xff0c;功能易扩展。多医院、多集团统一登录患者主索引建立、主数据管理&#xff0c;统一对外…

鸿蒙开发-ArkTS 语言-状态管理

鸿蒙开发-ArkTS 语言-基础语法 3. 状态管理 变量必须被装饰器装饰才能成为状态变量&#xff0c;状态变量的改变才能导致 UI 界面重新渲染 概念描述状态变量被状态装饰器装饰的变量&#xff0c;改变会引起UI的渲染更新。常规变量没有状态的变量&#xff0c;通常应用于辅助计算…

CVE-2023-22515:Atlassian Confluence权限提升漏洞复现 [附POC]

文章目录 Atlassian Confluence权限提升(CVE-2023-22515)漏洞复现 [附POC]0x01 前言0x02 漏洞描述0x03 影响版本0x04 漏洞环境0x05 漏洞复现1.访问漏洞环境2.构造POC3.复现 0x06 修复建议 Atlassian Confluence权限提升(CVE-2023-22515)漏洞复现 [附POC] 0x01 前言 免责声明&…

Unity-类-Vector

Vector矢量 是一个基本的数学概念,它允许你描述方向和大小。在游戏和应用中,矢量通常用于描述一些基本属性,如角色的位置、物体移动的速度或两个物体之间的距离。 矢量算术是计算机编程很多方面(如图形、物理和动画)的基础,深入了解这一主题对于充分发挥 Unity 的功能很有…

从零学算法400

400.给你一个整数 n &#xff0c;请你在无限的整数序列 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, …] 中找出并返回第 n 位上的数字。 示例 1&#xff1a; 输入&#xff1a;n 3 输出&#xff1a;3 示例 2&#xff1a; 输入&#xff1a;n 11 输出&#xff1a;0 解释&#xff1a;第…

社交媒体广告数据采集:Jsoup 的最佳实践

搜狐是中国领先的综合门户网站之一&#xff0c;广告在其网站上广泛投放。为了了解搜狐广告的策略和趋势&#xff0c;采集和分析搜狐广告数据变得至关重要。但是&#xff0c;搜狐网站的广告数据通常需要通过网页抓取的方式获取&#xff0c;这就需要一个强大的工具来解析和提取数…

HTML4总结

一、前序知识 1. 认识两位先驱 2. 计算机基础知识 1. 计算机俗称电脑&#xff0c;是现代一种用于高速计算的电子计算机器&#xff0c;可以进行数值计算、逻辑计算&#xff0c;还 具有存储记忆功能。 2. 计算机由 硬件 软件 成&#xff1a; 硬件&#xff1a;看得见摸得着…
最新文章