建立測試環境與測試系統總是最花時間的,趁著今天重新安裝一組RabbitMQ 的測試環境,把所有的步驟和順序都整理起來吧。
安裝RabbitMQ
說實在RabbitMQ安裝起來真的還蠻簡單的,參考RabbitMQ - 安裝指南:- 要先安裝epel-release的套件。 (會不定期更新,要確認是否有新版)
- 再安裝erlang
# rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm
# yum install erlang
# rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
# rpm -Uvh http://www.rabbitmq.com/releases/rabbitmq-server/v2.8.4/rabbitmq-server-2.8.4-1.noarch.rpm
設定Cluster
最簡易的方法就是先啟動,cluster master node產生 /var/lib/rabbitmq/.erlang.cookie 這份文件,然後再把這份文件copy 到 每一個cluster node鄉對應的目錄下面去,接下來就參考RabbitMQ - create cluster這份文件,範例事先建立3台的cluster。
1. 啟動每台rabbitMQ
# rabbit1$ rabbitmq-server -detached
# rabbit2$ rabbitmq-server -detached
# rabbit3$ rabbitmq-server -detached
2. 確認每一台rabbitmq 是否是standalone狀態
# rabbit1$ rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit1 ...
[{nodes,[{disc,[rabbit@rabbit1]}]},{running_nodes,[rabbit@rabbit1]}]
...done.
# rabbit2$ rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit2 ...
[{nodes,[{disc,[rabbit@rabbit2]}]},{running_nodes,[rabbit@rabbit2]}]
...done.
# rabbit3$ rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit3 ...
[{nodes,[{disc,[rabbit@rabbit3]}]},{running_nodes,[rabbit@rabbit3]}]
...done.
3. 依序加入cluster
rabbit2$ rabbitmqctl stop_app
Stopping node rabbit@rabbit2 ...done.
rabbit2$ rabbitmqctl reset
Resetting node rabbit@rabbit2 ...done.
rabbit2$ rabbitmqctl cluster rabbit@rabbit1
Clustering node rabbit@rabbit2 with [rabbit@rabbit1] ...done.
rabbit2$ rabbitmqctl start_app
Starting node rabbit@rabbit2 ...done.
4. 確認cluster status是否正確加入
rabbit1$ rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit1 ...
[{nodes,[{disc,[rabbit@rabbit1]},{ram,[rabbit@rabbit2]}]},
{running_nodes,[rabbit@rabbit2,rabbit@rabbit1]}]
...done.
rabbit2$ rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit2 ...
[{nodes,[{disc,[rabbit@rabbit1]},{ram,[rabbit@rabbit2]}]},
{running_nodes,[rabbit@rabbit1,rabbit@rabbit2]}]
...done.
設定Web Management Plugin
參考 rabbitmq - Management Plugin,重點是要在Cluster node的每一台都要安裝這個plugin
# rabbitmq-plugins enable rabbitmq_management
安裝好以後,要記得重啟服務
# service rabbitmq-server restart
設定好就可以連到http://server-name:55672/#/ 看看web 介面有沒有起來,預設的帳號密碼都是guest,如果是內部測試那還沒關係,如果是要連到外面,一定記得要改帳號密碼和permission。
設定帳號
最後我們可以設定一個vhost 以及這個vhost的帳號密碼和權限
#rabbitmqctl add_vhost /demo
#rabbitmqctl add_user demo mypass
#rabbitmqctl set_permissions -p /demo demo ".*" ".*" ".*"
Reference:
[1] RabbitMQ 指令集
沒有留言:
張貼留言