ActiveMQ 设置登陆密码

本文介绍如何配置ActiveMQ消息中间件,包括设置用户认证、调整内存和磁盘使用限制、限定最大连接数等关键参数。同时展示了如何通过配置文件activemq.xml启用多种协议的传输连接。

(1)修改activemq.xml配置,需要新增一个插件,在<broker>节点里面<systemUsage>节点前面添加如下
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}" schedulePeriodForDestinationPurge="3600000">

        <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>
    <policyEntry topic=">" gcInactiveDestinations="true" inactiveTimeoutBeforeGC="3600000" />
    <policyEntry queue=">" gcInactiveDestinations="true" inactiveTimeoutBeforeGC="3600000" />
              </policyEntries>
            </policyMap>
        </destinationPolicy>

 
        <managementContext>
            <managementContext createConnector="false"/>
        </managementContext>

        
        <persistenceAdapter>
            <kahaDB directory="${activemq.data}/kahadb"/>
        </persistenceAdapter>

<plugins>
         	<simpleAuthenticationPlugin>
         		<users>
         			<authenticationUser username="${activemq.username}" password="${activemq.password}" groups="users,admins"/>
         		</users>
         	</simpleAuthenticationPlugin>
         </plugins>
          
          <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:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
        </transportConnectors>

用户名密码文件为:credentials.properties

### 安装 ActiveMQ 在 Mac 系统上安装 ActiveMQ,可以使用 Homebrew 或手动下载安装包进行安装。 #### 使用 Homebrew 安装 如果已经安装了 [Homebrew](https://brew.sh/),可以通过以下命令安装 ActiveMQ: ```bash brew install activemq ``` 安装完成后,ActiveMQ 会被安装在 `/usr/local/opt/activemq` 目录下。 #### 手动安装 1. 访问 [ActiveMQ 官网](https://activemq.apache.org/components/classic/download/) 下载最新版本的 ActiveMQ。 2. 解压下载的压缩包: ```bash unzip apache-activemq-x.x.x-bin.zip ``` 3. 移动到 `/Applications` 或其他目录: ```bash mv apache-activemq-x.x.x /Applications/ActiveMQ ``` ### 启动 ActiveMQ #### 使用 Homebrew 启动 ```bash brew services start activemq ``` 或者直接运行启动脚本: ```bash /usr/local/opt/activemq/bin/macosx/activemq console ``` #### 手动启动 进入 ActiveMQ 的安装目录并运行: ```bash cd /Applications/ActiveMQ/bin ./activemq console ``` 默认情况下,ActiveMQ 会在 `http://localhost:8161` 提供 Web 控制台,可以通过浏览器访问。 --- ### 配置账号密码 ActiveMQ 的认证机制可以通过 `conf/jetty-realm.properties` 和 `conf/activemq.xml` 文件进行配置。 #### 修改 Web 控制台登录密码 编辑 `conf/jetty-realm.properties` 文件,内容格式如下: ``` admin: admin, admin user: password, user ``` 其中,第一列是用户名,第二列是密码,第三列是角色。默认情况下,管理员账号是 `admin/admin`。 修改后保存文件,重启 ActiveMQ 生效。 #### 配置消息队列连接认证 如果需要对客户端连接进行认证(如 JMS 客户端),需要在 `conf/activemq.xml` 中启用 `simpleAuthenticationPlugin` 插件。 在 `<broker>` 标签内添加以下内容: ```xml <plugins> <simpleAuthenticationPlugin> <users> <authenticationUser username="admin" password="admin" groups="users,admins"/> <authenticationUser username="user" password="password" groups="users"/> </users> </simpleAuthenticationPlugin> </plugins> ``` 该配置定义了两个用户 `admin` 和 `user`,并分配了不同的密码和权限组。 保存文件后重启 ActiveMQ。 --- ### 测试连接 使用 JMS 客户端或 `telnet` 命令测试连接是否正常: ```bash telnet localhost 61616 ``` 如果配置了密码,客户端连接时需要提供用户名和密码。 --- ### 配置 SSL(可选) 如果需要启用 SSL 加密连接,可以在 `conf/activemq.xml` 中配置 `sslContext`,并生成相应的密钥文件。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Farmwang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值