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] "}, {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"}'