rabbit是基於erlang編寫的,因此須要先安裝erlang環境。
首先在四臺主機上安裝erlang、rabbitmq-server;
讀取其中一臺節點上的erlang cookie,並複製到其餘節點(節點之間經過cookie肯定相互是否可通訊);
逐個啓動節點:rabbitmq-server -detached
查看各節點的狀態: rabbitmqctl status, rabbitmqctl cluster_status
將其餘節點加入集羣。html
//不重啓 臨時修改hostname hostname rabbitmq-node1~4 //永久設置hostname vim /etc/hostname rabbitmq-node1 vim /etc/sysconfig/network HOSTNAME=rabbitmq-node1 //在/etc/hosts中添加 10.30.128.67 rabbitmq-node1 10.30.128.68 rabbitmq-node2 10.30.128.69 rabbitmq-node3 10.30.128.70 rabbitmq-node4
下載otp_src_19.2.tar.gznode
yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel ncurses-devel yum -y install xz perl unixODBC unixODBC-devel mkdir -p /apache/RabbitMQ/erlang/ cd /apache/RabbitMQ/erlang/ wget http://erlang.org/download/otp_src_19.2.tar.gz tar xvf otp_src_19.2.tar.gz cd otp_src_19.2 ./configure make make install //輸入erl出現以下界面即表示安裝完成 [root@rabbitmq-node1 otp_src_19.2]# erl Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] Eshell V8.2 (abort with ^G) 1>
下載rabbitmq-server-generic-unix-3.6.6.tar.xzc++
cd /apache/RabbitMQ wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.6/rabbitmq-server-generic-unix-3.6.6.tar.xz xz -d rabbitmq-server-generic-unix-3.6.6.tar.xz tar xvf rabbitmq-server-generic-unix-3.6.6.tar vi /etc/profile export PATH=$PATH:/apache/RabbitMQ/rabbitmq_server-3.6.6/sbin source /etc/profile
首先使用參數-detached運行各節點,運行後才能集羣shell
rabbitmqctl stop rabbitmq-server -detached
設置erlang cookie
Rabbitmq的集羣是依賴於erlang的集羣來工做的,因此必須先構建起erlang的集羣環境。Erlang的集羣中各節點是經過一個magic cookie來實現的,這個cookie存放在 /root/.erlang.cookie 中,文件是400的權限。因此必須保證各節點cookie保持一致,不然節點之間就沒法通訊。咱們是刪除其中三臺的/root/.erlang.cookie,而後將另外一臺的/root/.erlang.cookie拷貝到這三臺上。文件權限是 400apache
scp /root/.erlang.cookie root@10.30.128.68:/root
組成集羣,在node2 3 4上分別運行:vim
rabbitmqctl stop_app rabbitmqctl reset rabbitmqctl join_cluster rabbit@rabbitmq-node1 //默認是磁盤節點,若是是內存節點的話,須要加--ram參數 rabbitmqctl start_app
[root@rabbitmq-node1 rabbitmq]# rabbitmqctl cluster_status -n rabbit Cluster status of node 'rabbit@rabbitmq-node1' ... [{nodes,[{disc,['rabbit@rabbitmq-node1','rabbit@rabbitmq-node2', 'rabbit@rabbitmq-node3','rabbit@rabbitmq-node4']}]}, {running_nodes,['rabbit@rabbitmq-node4','rabbit@rabbitmq-node2', 'rabbit@rabbitmq-node3','rabbit@rabbitmq-node1']}, {cluster_name,<<"rabbit@rabbitmq-node1">>}, {partitions,[]}, {alarms,[{'rabbit@rabbitmq-node4',[]}, {'rabbit@rabbitmq-node2',[]}, {'rabbit@rabbitmq-node3',[]}, {'rabbit@rabbitmq-node1',[]}]}] [root@DockerHost rabbitmq]#
rabbitmqctl rabbitmq管理工具
rabbitmq-plugins rabbitmq插件管理工具
rabbitmq-server rabbitmq服務cookie
參考:官方安裝指南
RabbitMQ nodes and CLI tools (e.g. rabbitmqctl) use a cookie to determine whether they are allowed to communicate with each other. For two nodes to be able to communicate they must have the same shared secret called the Erlang cookie. The cookie is just a string of alphanumeric characters. It can be as long or short as you like. Every cluster node must have the same cookie.
Erlang VM will automatically create a random cookie file when the RabbitMQ server starts up. The easiest way to proceed is to allow one node to create the file, and then copy it to all the other nodes in the cluster.
On Unix systems, the cookie will be typically located in /var/lib/rabbitmq/.erlang.cookie or $HOME/.erlang.cookie.app