相关简称
简称 | 说明 |
---|---|
MQ | 在本文中特指Apache-activeMQ |
$ACTIVEMQ_HOME | MQ的安装目录 |
修改MQ的控制台登录密码
由于MQ的启动是在jetty容器中,所以修改MQ的控制台密码,只需要修改以下两个地方即可。
- 进入MQ的配置文件目录
cd $ACTIVEMQ_HOME/conf
- 编辑jetty.xml中的securityConstraintBean下的authenticate属性为true即可,如图所示:
高版本MQ下的authenticate属性默认为true,可以不用修改
- 上一步骤中提到的authenticate属性设置为true之后,控制台登录的用户名/密码在同级目录下的jetty-realm.properties文件中维护,该配置文件的用户名/密码配置格式如下
username: password [,rolename ...]
所以冒号后的才是密码,逗号后的用户的权限名称,如图所示:不要改错了哦
- 修改完之后保存重启即可生效,http://localhost:8161/admin。
修改MQ的主题、队列用的用户名密码
接下来修改的我们在代码中去连接MQ队列/主题时使用的密码,MQ默认情况下,访问主题/队列时是不需要用户名/密码的,当然不信你也可以测试下。
下面开始修改这个配置,提高我们系统的安全性。
- 第一步还是进入到MQ的配置文件目录
cd $ACTIVEMQ_HOME/conf
- 修改activemq.xml,在如图所示位置添加以下内容
<plugins>
<!-- Configure authentication; Username, passwords and groups -->
<simpleAuthenticationPlugin>
<users>
<!-- 这里引用了两个变量,他们在同级目录下的credentials.properties文件中维护 -->
<authenticationUser username="${activemq.username}" password="${activemq.password}" groups="admins"/>
</users>
</simpleAuthenticationPlugin>
</plugins>
- 对应的用户名密码是在conf/credentials.properties文件中维护
## ---------------------------------------------------------------------------
## 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.
## ---------------------------------------------------------------------------
# Defines credentials that will be used by components (like web console) to access the broker
# 用户名(对应activemq.xml中新添加内容的变量${activemq.username})
activemq.username=system
# 密码 (对应activemq.xml中新添加内容的变量${activemq.password})
activemq.password=manager
guest.password=password
- 修改完配置后,保存重启MQ即可生效,动动小手测试下吧。