1. 程式人生 > >rabbitmq-cluster

rabbitmq-cluster

一、前期準備   (1)條件:準備3臺linux系統,確保能連到 download.yunwei.edu   (2)編寫yum源下載指令碼: vim yum-repo.sh wget -O /etc/yum.repos.d/Centos7-Base-yunwei.repo     download.yunwei.edu/shell/Centos7-Base-yunwei.repo wget -O /etc/yum.repos.d/epel-yunwei.repo    download.yunwei.edu/shell/epel-yunwei.repo
wget -O /etc/yum.repos.d/rdo-release-yunwei.repo   download.yunwei.edu/shell/rdo-release-yunwei.repo wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Cloud   download.yunwei.edu/shell/RPM-GPG-KEY-CentOS-SIG-Cloud wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7   download.yunwei.edu/shell/RPM-GPG-KEY-EPEL-7
  (3)將系統自帶網路源移走,執行yum-repo.sh sh yum-repo.sh   (4)DNS能夠解析此三臺主機   二、安裝過程:   (1)所有node安裝rabbtimq和erlang軟體包: yum install -y erlang rabbitmq-server.noarch systemctl enable rabbitmq-server.service systemctl start rabbitmq-server.service systemctl status rabbitmq-server.service   檢視監聽埠: netstat -lantp | grep 5672 配置檔案: vim /etc/rabbitmq/rabbitmq.config   (2)node1:修改guest密碼為admin(預設使用者為:guest 密碼為:guest) rabbitmqctl change_password guest admin   (3)node1:新增一個openstack的使用者,並設密碼為admin。並設定許可權和成為管理員 node1: rabbitmqctl add_user openstack admin rabbitmqctl set_permissions openstack ".*" ".*" ".*" rabbitmqctl set_user_tags openstack administrator   (4)node1:編輯rabbittmq變數檔案 vim /etc/rabbitmq/rabbitmq-env.conf RABBITMQ_NODE_PORT=5672 ulimit -S -n 4096 RABBITMQ_SERVER_ERL_ARGS="+K true +A30 +P 1048576 -kernel inet_default_connect_options [{nodelay,true},{raw,6,18,<<5000:64/native>>}] -kernel inet_default_listen_options [{raw,6,18,<<5000:64/native>>}]" RABBITMQ_NODE_IP_ADDRESS=172.16.254.60   (5)node1:將rabbittmq變數檔案拷貝到其他兩節點,之後並修改相應節點的ip scp /etc/rabbitmq/rabbitmq-env.conf con2:/etc/rabbitmq/ scp /etc/rabbitmq/rabbitmq-env.conf con3:/etc/rabbitmq/   檢視rabbitmq外掛 /usr/lib/rabbitmq/bin/rabbitmq-plugins list   (6)所有node 開啟rabbitmq的web管理頁面 /usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management mochiweb webmachine rabbitmq_web_dispatch amqp_client rabbitmq_management_agent 或者:rabbitmq-plugins enable rabbitmq_management   systemctl restart rabbitmq-server.service systemctl status rabbitmq-server.service   (7)node1傳送erlang.cookie到其他節點配置叢集 rabbitmqctl status scp /var/lib/rabbitmq/.erlang.cookie con2:/var/lib/rabbitmq/.erlang.cookie scp /var/lib/rabbitmq/.erlang.cookie con3:/var/lib/rabbitmq/.erlang.cookie   (8)node2和node3停止應用,並以ram的方式加入node1節點,之後重啟應用 systemctl restart rabbitmq-server.service rabbitmqctl stop_app rabbitmqctl join_cluster --ram
[email protected]
rabbitmqctl start_app   (9)node1檢查叢集狀態 [[email protected] conf]# rabbitmqctl cluster_status Cluster status of node [email protected] ... [{nodes,[{disc,[[email protected]]},{ram,[[email protected],[email protected]]}]}, {running_nodes,[[email protected],[email protected],[email protected]]}, {cluster_name,<<"[email protected]">>}, {partitions,[]}, {alarms,[{[email protected],[]},{[email protected],[]},{[email protected],[]}]}]   (10)登陸驗證: http://172.16.254.60:15672/#/             guest/admin         其他命令: (1)新增管理員: rabbitmqctl add_user mqadmin mqadmin rabbitmqctl set_user_tags mqadmin administrator rabbitmqctl set_permissions -p / mqadmin ".*" ".*" ".*"   (2)更改節點型別(記憶體型或磁碟型) rabbitmqctl stop_app rabbitmqctl change_cluster_node_type disc 或 rabbitmqctl change_cluster_node_type ram rabbitmqctl start_app   (3)從叢集移除節點(或者重置節點) rabbitmqctl stop_app rabbitmqctl reset rabbitmqctl start_app rabbitmqctl cluster_status   (4)從某個節點移除叢集中其他節點 rabbitmqctl forget_cluster_node [email protected] rabbitmqctl reset rabbitmqctl start_app rabbitmqctl cluster_status   1. 保證叢集中至少有一個磁碟型別的節點以防資料丟失,在更改節點型別時尤其要注意。 2. 若整個叢集被停掉了,應保證最後一個 down 掉的節點被最先啟動,若不能則要使用 forget_cluster_node 命令將其移出叢集 3. 若叢集中節點幾乎同時以不可控的方式 down 了此時在其中一個節點使用 force_boot 命令重啟節點