如何安裝RabbitMQ Cluster 建立測試環境與測試系統總是最花時間的,趁著今天重新安裝一組RabbitMQ 的測試環境,把所有的步驟和順序都整理起來吧。 安裝RabbitMQ Our APT repository To use our APT repository: - Add the following line to your /etc/apt/sources.list:
deb http://www.rabbitmq.com/debian/ testing main (Please note that the word testing in this line refers to the state of our release of RabbitMQ, not any particular Debian distribution. You can use it with Debian stable, testing or unstable, as well as with Ubuntu. We describe the release as "testing" to emphasise that we release somewhat frequently.) - (optional) To avoid warnings about unsigned packages, add our public key to your trusted key list using apt-key(8):
wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc sudo apt-key add rabbitmq-signing-key-public.asc - Run apt-get update.
- Install packages as usual; for instance,
sudo apt-get install rabbitmq-server
設定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 ".*" ".*" ".*"
启动HAProxy
/etc/default/haproxy # Set ENABLED to 1 if you want the init script to start haproxy. ENABLED=1 启动日志 /etc/rsyslog.d 添加文件haproxy.conf: $ModLoad imudp $UDPServerRun 514
local0.* -/var/log/haproxy-0.log local1.* -/var/log/haproxy-1.log HAProxy配置
# this config needs haproxy-1.1.28 or haproxy-1.2.1
global log 127.0.0.1 local0 log 127.0.0.1 local1 notice #log loghost local0 info maxconn 4096 #chroot /usr/share/haproxy user haproxy group haproxy daemon #debug #quiet
defaults log global mode tcp option tcplog option dontlognull retries 3 option redispatch maxconn 2000 contimeout 5000 clitimeout 50000 srvtimeout 50000
listen rabbitmq_cluster 0.0.0.0:5678 mode tcp balance roundrobin server rabbit65 192.168.1.200:5672 check inter 2000 rise 2 fall 3 server rabbit66 192.168.1.201:5672 check inter 2000 rise 2 fall 3 listen stats :1936 mode http stats enable stats hide-version stats realm Haproxy\ Statistics stats uri / stats auth admin:admin
|