openstack搭建4、部署rabbitmq訊息佇列
阿新 • • 發佈:2021-01-21
4、部署rabbitmq訊息佇列
4.1、所有控制節點安裝rabbitmq和erlang軟體包(controller1、controller2、controller3)
//節點:controller1 [root@controller1:/root]# yum install epel-release -y [root@controller1:/root]# yum install -y erlang rabbitmq-server.noarch [root@controller1:/root]# systemctl enable rabbitmq-server && systemctl start rabbitmq-server [root@controller1:/root]# systemctl status rabbitmq-server [root@controller1:/root]# netstat -ntlpa | grep 5672 //節點:controller2 [root@controller2:/root]# yum install epel-release -y [root@controller2:/root]# yum install -y erlang rabbitmq-server.noarch [root@controller2:/root]# systemctl enable rabbitmq-server && systemctl start rabbitmq-server [root@controller2:/root]# systemctl status rabbitmq-server [root@controller2:/root]# netstat -ntlpa | grep 5672 //節點:controller3 [root@controller3:/root]# yum install epel-release -y [root@controller3:/root]# yum install -y erlang rabbitmq-server.noarch [root@controller3:/root]# systemctl enable rabbitmq-server && systemctl start rabbitmq-server [root@controller3:/root]# systemctl status rabbitmq-server [root@controller3:/root]# netstat -ntlpa | grep 5672
4.2 檢視叢集狀態
(提示:Rabbitmq的配置檔案/etc/rabbitmq/rabbitmq.config) [root@controller1:/root]# rabbitmqctl cluster_status Cluster status of node rabbit@controller1 ... [{nodes,[{disc,[rabbit@controller1]}]}, {running_nodes,[rabbit@controller1]}, {cluster_name,<<"rabbit@controller1">>}, {partitions,[]}] ...done. [root@controller2:/root]# rabbitmqctl cluster_status Cluster status of node rabbit@controller2 ... [{nodes,[{disc,[rabbit@controller2]}]}, {running_nodes,[rabbit@controller2]}, {cluster_name,<<"rabbit@controller2">>}, {partitions,[]}] ...done. [root@controller3:/root]# rabbitmqctl cluster_status Cluster status of node rabbit@controller3 ... [{nodes,[{disc,[rabbit@controller3]}]}, {running_nodes,[rabbit@controller3]}, {cluster_name,<<"rabbit@controller3">>}, {partitions,[]}] ...done. //*注:partitions裡如果有節點一般非正常,可以通過重啟rabbitmq-server服務來恢復*//
4.3 編輯rabbitmq變數檔案
[root@controller1:/root]# 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=192.168.110.121 [root@controller2:/root]# 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=192.168.110.122 [root@controller3:/root]# 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=192.168.110.123
4.4 檢視rabbitmq外掛
[root@controller1:/root]# /usr/lib/rabbitmq/bin/rabbitmq-plugins list [ ] amqp_client 3.3.5 [ ] cowboy 0.5.0-rmq3.3.5-git4b93c2d [ ] eldap 3.3.5-gite309de4 [ ] mochiweb 2.7.0-rmq3.3.5-git680dba8 [ ] rabbitmq_amqp1_0 3.3.5 [ ] rabbitmq_auth_backend_ldap 3.3.5 [ ] rabbitmq_auth_mechanism_ssl 3.3.5 [ ] rabbitmq_consistent_hash_exchange 3.3.5 [ ] rabbitmq_federation 3.3.5 [ ] rabbitmq_federation_management 3.3.5 [ ] rabbitmq_management 3.3.5 [ ] rabbitmq_management_agent 3.3.5 [ ] rabbitmq_management_visualiser 3.3.5 [ ] rabbitmq_mqtt 3.3.5 [ ] rabbitmq_shovel 3.3.5 [ ] rabbitmq_shovel_management 3.3.5 [ ] rabbitmq_stomp 3.3.5 [ ] rabbitmq_test 3.3.5 [ ] rabbitmq_tracing 3.3.5 [ ] rabbitmq_web_dispatch 3.3.5 [ ] rabbitmq_web_stomp 3.3.5 [ ] rabbitmq_web_stomp_examples 3.3.5 [ ] sockjs 0.3.4-rmq3.3.5-git3132eb9 [ ] webmachine 1.10.3-rmq3.3.5-gite9359c7
4.5 所有node開啟rabbitmq的web管理頁面
rabbitmq-plugins enable rabbitmq_management systemctl restart rabbitmq-server systemctl status rabbitmq-server
4.6 檢視rabbitmq外掛是否載入成功(成功後前面有E)
[root@controller1:/root]# /usr/lib/rabbitmq/bin/rabbitmq-plugins list [e] amqp_client 3.3.5 [ ] cowboy 0.5.0-rmq3.3.5-git4b93c2d [ ] eldap 3.3.5-gite309de4 [e] mochiweb 2.7.0-rmq3.3.5-git680dba8 [ ] rabbitmq_amqp1_0 3.3.5 [ ] rabbitmq_auth_backend_ldap 3.3.5 [ ] rabbitmq_auth_mechanism_ssl 3.3.5 [ ] rabbitmq_consistent_hash_exchange 3.3.5 [ ] rabbitmq_federation 3.3.5 [ ] rabbitmq_federation_management 3.3.5 [E] rabbitmq_management 3.3.5 [e] rabbitmq_management_agent 3.3.5 [ ] rabbitmq_management_visualiser 3.3.5 [ ] rabbitmq_mqtt 3.3.5 [ ] rabbitmq_shovel 3.3.5 [ ] rabbitmq_shovel_management 3.3.5 [ ] rabbitmq_stomp 3.3.5 [ ] rabbitmq_test 3.3.5 [ ] rabbitmq_tracing 3.3.5 [e] rabbitmq_web_dispatch 3.3.5 [ ] rabbitmq_web_stomp 3.3.5 [ ] rabbitmq_web_stomp_examples 3.3.5 [ ] sockjs 0.3.4-rmq3.3.5-git3132eb9 [e] webmachine 1.10.3-rmq3.3.5-gite9359c7 提示:rabbitmq: web預設埠15672 rabbitmq: server預設埠5672
4.7 訪問:http://192.168.110.122:15672/
注:如果是阿里雲伺服器,需要開啟15672埠.(後期可能有80埠被佔用情況)
預設賬戶:guest/guest
4.8 所有node修改guest密碼為adminrabbitmq(預設使用者為:guest 密碼為:guest)
[root@controller1:/root]# rabbitmqctl change_password guest adminrabbitmq Changing password for user "guest" ... ...done. [1]+ Done rabbitmqctl change_password guest admin [root@controller2:/root]# rabbitmqctl change_password guest adminrabbitmq Changing password for user "guest" ... ...done. [1]+ Done rabbitmqctl change_password guest admin [root@controller3:/root]# rabbitmqctl change_password guest adminrabbitmq Changing password for user "guest" ... ...done.
4.9 controller1新增一個openstack的使用者,並設密碼為adminopenstack。並設定許可權成為管理員(成集群后,controller2和controller3上也可以登入)
[root@controller1:/root]# rabbitmqctl add_user openstack adminopenstack Creating user "openstack" ... ...done. [root@controller1:/root]# rabbitmqctl set_permissions openstack ".*" ".*" ".*" Setting permissions for user "openstack" in vhost "/" ... ...done. [root@controller1:/root]# rabbitmqctl set_user_tags openstack administrator Setting tags for user "openstack" to [administrator] ... ...done. [root@controller1:/root]# rabbitmqctl list_users Listing users ... guest [administrator] openstack [administrator] ...done.
4.10 傳送controller1上的erlang.cookie到其他節點配置叢集
[root@controller1:/root]# rabbitmqctl status Status of node rabbit@controller1 ... [{pid,12512}, {running_applications, [{rabbitmq_management,"RabbitMQ Management Console","3.3.5"}, {rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.3.5"}, {webmachine,"webmachine","1.10.3-rmq3.3.5-gite9359c7"}, {mochiweb,"MochiMedia Web Server","2.7.0-rmq3.3.5-git680dba8"}, {rabbitmq_management_agent,"RabbitMQ Management Agent","3.3.5"}, {rabbit,"RabbitMQ","3.3.5"}, {os_mon,"CPO CXC 138 46","2.2.14"}, {inets,"INETS CXC 138 49","5.9.8"}, {mnesia,"MNESIA CXC 138 12","4.11"}, {amqp_client,"RabbitMQ AMQP Client","3.3.5"}, {xmerl,"XML parser","1.3.6"}, {sasl,"SASL CXC 138 11","2.3.4"}, {stdlib,"ERTS CXC 138 10","1.19.4"}, {kernel,"ERTS CXC 138 10","2.16.4"}]}, {os,{unix,linux}}, {erlang_version, "Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:8:8] [async-threads:30] [hipe] [kernel-poll:true]\n"}, {memory, [{total,41896520}, {connection_procs,5600}, {queue_procs,5600}, {plugins,385080}, {other_proc,13866040}, {mnesia,60888}, {mgmt_db,50256}, {msg_index,34528}, {other_ets,1114200}, {binary,74848}, {code,20229052}, {atom,711569}, {other_system,5358859}]}, {alarms,[]}, {listeners,[{clustering,25672,"::"},{amqp,5672,"192.168.110.122"}]}, {vm_memory_high_watermark,0.4}, {vm_memory_limit,8331886592}, {disk_free_limit,50000000}, {disk_free,178624393216}, {file_descriptors, [{total_limit,3996}, {total_used,3}, {sockets_limit,3594}, {sockets_used,1}]}, {processes,[{limit,1048576},{used,190}]}, {run_queue,0}, {uptime,369}] ...done. [root@controller1:/root]# scp /var/lib/rabbitmq/.erlang.cookie controller2:/var/lib/rabbitmq/ [root@controller1:/root]# scp /var/lib/rabbitmq/.erlang.cookie controller3:/var/lib/rabbitmq/
4.11 controller2、controller3停止應用,並ram的方式加入controller1節點,之後重啟應用(先檢視controller1叢集名字)
[root@controller1:/root]# rabbitmqctl cluster_status Cluster status of node rabbit@controller1 ... [{nodes,[{disc,[rabbit@controller1]}]}, {running_nodes,[rabbit@controller1]}, {cluster_name,<<"rabbit@controller1">>}, {partitions,[]}] ...done. [root@controller2:/root]# systemctl restart rabbitmq-server [root@controller2:/root]# systemctl status rabbitmq-server [root@controller2:/root]# rabbitmqctl stop_app Stopping node rabbit@controller2 ... ...done. [root@controller2:/root]# rabbitmqctl join_cluster --ram rabbit@controller1 Clustering node rabbit@controller1 with rabbit@controller1 ... ...done. [root@controller2:/root]# rabbitmqctl start_app Starting node rabbit@controller2 ... ...done. [root@controller3:/root]# systemctl restart rabbitmq-server [root@controller3:/root]# systemctl status rabbitmq-server [root@controller3:/root]# rabbitmqctl stop_app [root@controller3:/root]# rabbitmqctl join_cluster --ram rabbit@controller1 Clustering node rabbit@controller3 with rabbit@controller1 ... ...done. [root@controller3:/root]# rabbitmqctl start_app Starting node rabbit@controller3 ... ...done.
4.12 檢測叢集狀態
[root@controller1:/root]# rabbitmqctl cluster_status Cluster status of node rabbit@controller1 ... [{nodes,[{disc,[rabbit@controller1]}, {ram,[rabbit@controller2,rabbit@controller3]}]}, {running_nodes,[rabbit@controller2,rabbit@controller3,rabbit@controller1]}, {cluster_name,<<"rabbit@controller1">>}, {partitions,[]}] ...done. [root@controller2:/root]# rabbitmqctl cluster_status Cluster status of node rabbit@controller2 ... [{nodes,[{disc,[rabbit@controller1]}, {ram,[rabbit@controller2,rabbit@controller3]}]}, {running_nodes,[rabbit@controller3,rabbit@controller1,rabbit@controller2]}, {cluster_name,<<"rabbit@controller1">>}, {partitions,[]}] ...done. [root@controller3:/root]# rabbitmqctl cluster_status Cluster status of node rabbit@controller3 ... [{nodes,[{disc,[rabbit@controller1]}, {ram,[rabbit@controller2,rabbit@controller3,]}]}, {running_nodes,[rabbit@controller1,rabbit@controller2,rabbit@controller3]}, {cluster_name,<<"rabbit@controller1">>}, {partitions,[]}] ...done.
4.13 為了保持rabbitmq的訊息一致性,可以設定訊息映象模式策略 所有節點執行
rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'