rabbitmq的安裝教學

2020-08-09 18:34:12

部署單個範例

安裝

通過Package Cloud進行安裝

匯入Package Cloud簽名key

# import the new PackageCloud key that will be used starting December 1st, 2018 (GMT)
rpm --import https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey

通過package cloud拉取rpm指令碼自動安裝erlang和rabbitmq倉庫

#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

安裝erlang

sudo yum install erlang-22.3.4.5-1.el7.x86_64

安裝rabbitmq-server

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"

 安裝管理UI外掛 不需要重新啓動

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