rabbitmq 集群
阿新 • • 發佈:2017-09-14
ont 端口說明 分享 cat -o err ext chm edi 搭建rabbitmq+HA 高可用集群
一.環境
centos6.5 192.168.9.27 rabbitmq1
centos6.5 192.168.9.28 rabbitmq2
centos6.5 192.168.9.29 rabbitmq3
二.每臺服務器搭建單點rabbitmq 服務,見本博客地址:http://www.cnblogs.com/lzcys8868/p/7506251.html
端口說明:15672是管理界面用的;25672是集群之間使用的端口;4369是erlang進程用來做node連接的。
http://192.168.9.27:15672 usename=admin passwd=admin
http://192.168.9.28:15672 username=admin passwd=admin
http://192.168.9.29:15672
三. 保證上面的三個節點可用,將三個節點連接起來形成高可用cluser。這樣我們就可以讓我們的exchange,queue在這兩個節點之間復制,形成高可用的queue。
1》.erlang.cookie 這個文件是erlang用來發現 和互相連接的基礎。將三個節點中的.erlang.cookie設置成一樣,這是erlang的約定,一樣的 .cookie hash key 他認為是合法和正確的
[[email protected] sbin]# find / -name .erlang.cookie -type f
/root/.erlang.cookie
[[email protected] ~]# scp 192.168.9.27:/root/.erlang.cookie /root
[email protected]‘s password:
.erlang.cookie
[[email protected] ~]# scp 192.168.9.27:/root/.erlang.cookie /root
[email protected]‘s password:
.erlang.cookie
[[email protected] ~]# chmod u+w .erlang.cookie //三臺服務器上都加上權限
[[email protected] ~]# ls -ld .erlang.cookie
-rw-------. 1 root root 20 3月 8 00:00 .erlang.cookie
2》保證三臺服務器hosts 相同,erlang會通過hosts文件發現節點
[[email protected] ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.9.27 rabbitmq1
192.168.9.28 rabbitmq2
192.168.9.29 rabbitmq3
3》將rabbitmq2,rabbitmq3與rabbitmq1組成集群 。rabbitmq2和rabbitmq3會默認連接在一起
[[email protected] sbin]# ./rabbitmqctl stop_app
Stopping node [email protected] ...
註:[rabbitmq-discuss] Error: unable to connect to node ‘[email protected]‘: nodedown.。如果執行 ./rabbitmqctl stop_app命令時報此錯誤,是“.erlang.cookie”的問題,從新復制同一臺上的cookie。殺掉 5672 15672 4369 端口的進程,然後再執行 ./rabbitmq-server --detached & 從新啟動rabbitmq,再次執行 ./rabbitmqctl stop_app 命令
[[email protected] sbin]# ./rabbitmqctl join_cluster [email protected] //rabbitmq2與rabbitmq1 組成集群
Clustering node [email protected] with [email protected] ...
[[email protected] sbin]# ./rabbitmqctl start_app
Starting node [email protected] ...
RabbitMQ 3.6.5. Copyright (C) 2007-2016 Pivotal Software, Inc.
## ## Licensed under the MPL. See http://www.rabbitmq.com/
## ##
########## Logs: /usr/local/rabbitmq/var/log/rabbitmq/[email protected]
###### ## /usr/local/rabbitmq/var/log/rabbitmq/[email protected]
##########
Starting broker...
completed with 6 plugins.
[[email protected] sbin]# ./rabbitmqctl stop_app
Stopping node [email protected] ...
[[email protected] sbin]# ./rabbitmqctl join_cluster [email protected] //rabbitmq3與rabbitmq1組成集群
Clustering node [email protected] with [email protected] ...
[[email protected] sbin]# ./rabbitmqctl start_app
Starting node [email protected] ...
RabbitMQ 3.6.5. Copyright (C) 2007-2016 Pivotal Software, Inc.
## ## Licensed under the MPL. See http://www.rabbitmq.com/
## ##
########## Logs: /usr/local/rabbitmq/var/log/rabbitmq/[email protected]
###### ## /usr/local/rabbitmq/var/log/rabbitmq/[email protected]
##########
Starting broker...
completed with 6 plugins.
4》集群驗證:三個節點都是可用的
http://192.168.9.27:15672
四.默認情況下節點占用的memory 是總內存的40%,可以根據自己的用途研究rabbitmq的配置項。為了提高性能,不需要三個節點都是disc 的節點,所以我們需要啟動一個節點為RAM模式。
[[email protected] sbin]# ./rabbitmqctl change_cluster_node_type ram //改變rabbitmq3的節點模式為ram
Turning [email protected] into a ram node ...
Error: Mnesia is still running on node [email protected]
Please stop the node with rabbitmqctl stop_app first.
根據提示操作:
[[email protected] sbin]# ./rabbitmqctl stop_app
Stopping node [email protected] ...
[[email protected] sbin]# ./rabbitmqctl change_cluster_node_type ram
Turning [email protected] into a ram node ...
[[email protected] sbin]# ./rabbitmqctl start_app
Starting node [email protected] ...
RabbitMQ 3.6.5. Copyright (C) 2007-2016 Pivotal Software, Inc.
## ## Licensed under the MPL. See http://www.rabbitmq.com/
## ##
########## Logs: /usr/local/rabbitmq/var/log/rabbitmq/[email protected]
###### ## /usr/local/rabbitmq/var/log/rabbitmq/[email protected]
##########
Starting broker...
completed with 6 plugins.
註:節點rabbitmq3的類型 已經是RAM了。可以把節點rabbitmq2節點類型也做修改
五.設置鏡像隊列策略
我們需要設置exchange,queue 高可用策略,這樣才能真的做到高可用。現在是物理上的機器或者說是虛擬節點是高可用的,但是裏面的對象需要我們進行配置策略。
三臺服務器上都執行:
[[email protected] sbin]# rabbitmqctl set_policy ha-all "^" ‘{"ha-mode":"all"}‘
註:exchange 裏有 ha-all
rabbitmq 集群