實踐環境 CentOS-7-x86_64-DVD-2009.iso rabbitmq-server-3.9.16-1.el7.noarch.rpm https://github.com/rabbitmq/rabbitmq-server/releases/tag/v3.9.16 https://git ...
實踐環境
rabbitmq-server-3.9.16-1.el7.noarch.rpm
https://github.com/rabbitmq/rabbitmq-server/releases/tag/v3.9.16
備註:rabbitmq-server最後一個支持CentOS7的版本
erlang-23.3.4.11-1.el7.x86_64.rpm
https://github.com/rabbitmq/erlang-rpm/releases
備註:Erlang最後一個支持Centos7的版本
實踐操作
下載RabbitMQ及Erlang軟體包
RabbitMQ是採用 Erlang語言開發的,所以系統環境必須提供 Erlang環境,需要是安裝 Erlang。Erlang版本要和需要安裝的RabbitMQ版本匹配,可通過網址https://www.rabbitmq.com/docs/which-erlang 不同Erlang支持的RabbitMQ版本。
安裝軟體包
# rpm -ivh erlang-23.3.4.11-1.el7.x86_64.rpm
# rpm -ivh rabbitmq-server-3.9.16-1.el7.noarch.rpm
說明:參照官方文檔,https://www.rabbitmq.com/docs/install-rpm#package-dependencies 還需要安裝依賴包:socat
,logrotate
,但是筆者實踐時未安裝這兩個依賴包。
運行RabbitMQ
RabbitMQ伺服器包安裝完成後,預設情況下伺服器不會作為守護進程啟動。運行以下命令,設置當系統啟動時,預設以管理員身份,以守護進程的方式啟動RabbitMQ
# systemctl enable rabbitmq-server
Created symlink from /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service to /usr/lib/systemd/system/rabbitmq-server.service.
停、啟伺服器
# 啟動服務
# systemctl start rabbitmq-server
# 查看服務狀態
# systemctl status rabbitmq-server
● rabbitmq-server.service - RabbitMQ broker
Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2024-07-13 04:02:54 EDT; 12s ago
Main PID: 1237 (beam.smp)
CGroup: /system.slice/rabbitmq-server.service
├─1237 /usr/lib64/erlang/erts-11.2.2.10/bin/beam.smp -W w -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -sbwt none -sbwtdcpu none -sbwtdio none -...
├─1252 erl_child_setup 32768
├─1275 /usr/lib64/erlang/erts-11.2.2.10/bin/epmd -daemon
├─1296 inet_gethost 4
└─1297 inet_gethost 4
Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Doc guides: https://rabbitmq.com/documentation.html
Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Support: https://rabbitmq.com/contact.html
Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Tutorials: https://rabbitmq.com/getstarted.html
Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Monitoring: https://rabbitmq.com/monitoring.html
Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Logs: /var/log/rabbitmq/[email protected]
Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: /var/log/rabbitmq/rabbit@localhost_upgrade.log
Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: <stdout>
Jul 13 04:02:49 localhost.localdomain rabbitmq-server[1237]: Config file(s): (none)
Jul 13 04:02:54 localhost.localdomain rabbitmq-server[1237]: Starting broker... completed with 0 plugins.
Jul 13 04:02:54 localhost.localdomain systemd[1]: Started RabbitMQ broker.
# 停止服務
# systemctl stop rabbitmq-server
參考鏈接:https://www.rabbitmq.com/docs/install-rpm#running-rpm
啟用管理插件
# rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@localhost:
rabbitmq_management
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
Applying plugin configuration to rabbit@localhost...
Plugin configuration unchanged.
備註:開啟插件後不需要重啟伺服器
開啟後,瀏覽器訪問管理界面(預設地址:http://node-hostname:15672/
.),如下,其中 192.167.206.101為RabbitMQ伺服器地址
參考連接:https://www.rabbitmq.com/docs/management#getting-started
配置文件管理
查找配置文件
# rabbitmq-diagnostics status
......
Config files
Log file(s)
* /var/log/rabbitmq/[email protected]
* /var/log/rabbitmq/rabbit@localhost_upgrade.log
* <stdout>
......
如上,配置文件位於 Log file(s)
上方,這裡筆者實踐時命令輸出中沒看到配置文件路徑信息,按官方文檔描述,應該Config files
下應該會包含配置文件路徑信息,類似如下
Config files
* /etc/rabbitmq/advanced.config
* /etc/rabbitmq/rabbitmq.conf
參考連接:
https://www.rabbitmq.com/docs/configure#configuration-files
https://www.rabbitmq.com/docs/configure#verify-configuration-config-file-location
用戶管理
預設用戶訪問
broker預設創建了一個用戶名和密碼都為guest
的用戶。預設情況下,該用戶只能在以訪問localhost
的方式連接到broker,即不能遠程訪問。嘗試遠程訪問伺服器時會提示User can only log in via localhost
。如果希望guest
也可以遠程登錄,需要修改rabbitmq.conf
配置文件,文件末尾添加loopback_users = none
# vi /etc/rabbitmq/rabbitmq.conf
loopback_users = none
# systemctl restart rabbitmq-server
參考連接:
https://www.rabbitmq.com/docs/install-rpm#default-user-access
https://www.rabbitmq.com/docs/access-control#user-management
添加用戶
# rabbitmqctl add_user "testacc"
Adding user "testacc" ...
Password:
test1234
Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.
獲取當前用戶列表
# rabbitmqctl list_users
Listing users ...
user tags
testacc []
guest [administrator]
# rabbitmqctl list_users --formatter=json
[
{"user":"testacc","tags":[]}
,{"user":"guest","tags":["administrator"]}
]
刪除用戶
# rabbitmqctl delete_user 'username'
用戶授權
使用rabbitmqctl set_permissions
要向虛擬主機中的用戶授予許可權:
# rabbitmqctl set_permissions -p "custom-vhost" "username" ".*" ".*" ".*"
說明:
第一個 ".*" 表示配置每個實體上的許可權(First ".*" for configure permission on every entity)
第二個 ".*" 表示每個實體的寫許可權(Second ".*" for write permission on every entity)
第二個 ".*" 表示每個實體的讀許可權(Third ".*" for read permission on every entity)
# rabbitmqctl set_permissions -p "/" "testacc" ".*" ".*" ".*"
Setting permissions for user "testacc" in vhost "/" ...
移除授權
使用rabbitmqctl clear_permissions
移除授予給虛擬主機中的用戶許可權:
# Revokes permissions in a virtual host
rabbitmqctl.bat clear_permissions -p 'custom-vhost' 'username'
參考連接:https://www.rabbitmq.com/docs/access-control#user-management
https://www.rabbitmq.com/docs/access-control#override-default-user-credentials
設置用戶標簽
# rabbitmqctl set_user_tags testacc administrator
Setting tags for user "testacc" to [administrator] ...
說明:如果不設置標簽,以 testacc 用戶登錄管理界面時,會提示Not management user
參考連接:
https://www.rabbitmq.com/docs/man/rabbitmqctl.8#set_user_tags
https://www.rabbitmq.com/docs/management#permissions
登錄管理界面
開啟mqtt相關插件
# rabbitmq-plugins enable rabbitmq_mqtt
Enabling plugins on node rabbit@localhost:
rabbitmq_mqtt
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_mqtt
rabbitmq_web_dispatch
Applying plugin configuration to rabbit@localhost...
The following plugins have been enabled:
rabbitmq_mqtt
參考鏈接:
https://www.rabbitmq.com/docs/mqtt#enabling-plugin
# rabbitmq-plugins enable rabbitmq_web_mqtt
Enabling plugins on node rabbit@localhost:
rabbitmq_web_mqtt
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_mqtt
rabbitmq_web_dispatch
rabbitmq_web_mqtt
Applying plugin configuration to rabbit@localhost...
The following plugins have been enabled:
rabbitmq_web_mqtt
started 1 plugins.
參考鏈接:https://www.rabbitmq.com/docs/web-mqtt#enabling
# rabbitmq-plugins enable rabbitmq_web_mqtt_examples
Enabling plugins on node rabbit@localhost:
rabbitmq_web_mqtt_examples
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_mqtt
rabbitmq_web_dispatch
rabbitmq_web_mqtt
rabbitmq_web_mqtt_examples
Applying plugin configuration to rabbit@localhost...
The following plugins have been enabled:
rabbitmq_web_mqtt_examples
參考鏈接:https://www.rabbitmq.com/docs/web-mqtt#examples
安裝後示例插件後,訪問 http://主機IP地址:15670
,出現類似如下頁面
作者:授客
微信/QQ:1033553122
全國軟體測試QQ交流群:7156436
Git地址:https://gitee.com/ishouke
友情提示:限於時間倉促,文中可能存在錯誤,歡迎指正、評論!
作者五行缺錢,如果覺得文章對您有幫助,請掃描下邊的二維碼打賞作者,金額隨意,您的支持將是我繼續創作的源動力,打賞後如有任何疑問,請聯繫我!!!
微信打賞
支付寶打賞 全國軟體測試交流QQ群