通過Package Cloud進行安裝
# import the new PackageCloud key that will be used starting December 1st, 2018 (GMT)
rpm --import https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
#erlang
curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
#rabbitmq-server
curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash
sudo yum install erlang-22.3.4.5-1.el7.x86_64
rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
# For CentOS 7
sudo yum install -y rabbitmq-server-3.8.6-1.el7.noarch
# For CentOS 8
yum install -y rabbitmq-server-3.8.6-1.el8.noarch
systemctl enable rabbitmq-server.service
systemctl start rabbitmq-server.service
服務起來後,會生成一個預設的賬號guest :guest ,這個賬號預設只能通過localhost存取預設虛擬機器「/」。生產環境應該建立一個新的賬號使用。
1 通過修改組態檔
# default is "guest", and its access is limited to localhost only.
# See https://www.rabbitmq.com/access-control.html#default-state
default_user = a-user
# default is "guest"
default_pass = 768a852ed69ce916fa7faa278c962de3e4275e5f
可以通過Configuration Value Encryption檢視加密方式。
#加密
rabbitmqctl encode '<<"password">>' mypassphrase
#解密
rabbitmqctl decode '{encrypted, <<"...">>}' mypassphrase
2 通過用戶端工具CLI tools。
新增使用者
# will prompt for password, only use this option interactively
rabbitmqctl add_user "username"
#指定密碼方式1
# Password is provided via standard input.
# Note that certain characters such as $, &, &, #, and so on must be escaped to avoid
# special interpretation by the shell.
echo 'admin' | rabbitmqctl add_user 'admin'
#指定密碼方式2
# Password is provided as a command line argument.
# Note that certain characters such as $, &, &, #, and so on must be escaped to avoid
# special interpretation by the shell.
rabbitmqctl add_user 'admin' 'admin'
檢視使用者
rabbitmqctl list_users
rabbitmqctl list_users --formatter=json
刪除使用者
rabbitmqctl delete_user 'username'
授予許可權,遠端讀寫
rabbitmqctl set_permissions [-p vhost] user conf write read
#授予admin vhost "/" 許可權
rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
測試使用者許可權
rabbitmqctl authenticate_user 'admin' 'admin'
檢視虛擬機器下的使用者許可權
rabbitmqctl list_permissions --vhost /
移除許可權
# Revokes permissions in a virtual host
rabbitmqctl clear_permissions -p "custom-vhost" "username"
rabbitmq-plugins enable rabbitmq_management
http://{node-hostname}:15672/
# 建立一個使用者
rabbitmqctl add_user adminn admin
# 爲使用者指定 "administrator" 來獲取management UI and HTTP API所有的存取許可權
rabbitmqctl set_user_tags admin administrator