相關簡稱
簡稱 | 說明 |
---|---|
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即可生效,動動小手測試下吧。