拉取rabbitmq management镜像
1
|
docker pull rabbitmq:3.7-rc-management |
若不使用rabbitmq的management功能,可以拉取镜像:rabbitmq:3.7-rc
参考:https://hub.docker.com/_/rabbitmq/
创建网络
创建rabbitmq私有网络
1
2
3
4
5
|
# docker network create rabbitmqnet # docker network ls network id name driver scope 65b44ea8847c rabbitmqnet bridge local ... |
创建节点
通过docker命令创建三个rabbitmq nodes;
注意这里使用相同的 rabbitmq_erlang_cookie 值
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# docker run -d \ --name=rabbitmq1 \ -p 5672:5672 \ -p 15672:15672 \ -e rabbitmq_nodename=rabbitmq1 \ -e rabbitmq_erlang_cookie= 'yzsdhwmfsmkembdhsggz' \ -h rabbitmq1 \ --net=rabbitmqnet \ rabbitmq:3.7-rc-management # docker run -d \ --name=rabbitmq2 \ -p 5673:5672 \ -p 15673:15672 \ -e rabbitmq_nodename=rabbitmq2 \ -e rabbitmq_erlang_cookie= 'yzsdhwmfsmkembdhsggz' \ -h rabbitmq2 \ --net=rabbitmqnet \ rabbitmq:3.7-rc-management # docker run -d \ --name=rabbitmq3 \ -p 5674:5672 \ -p 15674:15672 \ -e rabbitmq_nodename=rabbitmq3 \ -e rabbitmq_erlang_cookie= 'yzsdhwmfsmkembdhsggz' \ -h rabbitmq3 \ --net=rabbitmqnet \ rabbitmq:3.7-rc-management |
组建rabbitmq集群
登陆rabbitmq的后两个节点,执行命令加入第一个rabbitmq节点集群
1
2
3
4
5
6
7
8
9
10
11
12
13
|
### disk node # docker exec rabbitmq2 bash -c \ "rabbitmqctl stop_app && \ rabbitmqctl reset && \ rabbitmqctl join_cluster rabbitmq1@rabbitmq1 && \ rabbitmqctl start_app" ### ram node # docker exec rabbitmq3 bash -c \ "rabbitmqctl stop_app && \ rabbitmqctl reset && \ rabbitmqctl join_cluster --ram rabbitmq1@rabbitmq1 && \ rabbitmqctl start_app" |
退出集群
1
2
3
4
|
# docker exec rabbitmq3 bash -c \ "rabbitmqctl stop_app && \ rabbitmqctl reset && \ rabbitmqctl start_app" |
拉取haproxy镜像
拉取haproxy镜像
1
|
# docker pull haproxy |
启动haproxy
1
2
3
4
5
6
7
8
9
|
# cat haproxy-create.sh #! /bin/bash docker run -d \ --name rabbitmq-haproxy \ -p 1080:80 -p 5677:5677 -p 8001:8001 \ --net=rabbitmqnet \ - v /root/rabbitmq/haproxy-etc : /usr/local/etc/haproxy :ro \ haproxy:latest |
haproxy的配置文件如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
root@node0:~ /rabbitmq # cat haproxy-etc/haproxy.cfg # simple configuration for an http proxy listening on port 80 on all # interfaces and forwarding requests to a single backend "servers" with a # single server "server1" listening on 127.0.0.1:8000 global daemon maxconn 256 defaults mode http timeout connect 5000ms timeout client 5000ms timeout server 5000ms listen rabbitmq_cluster bind 0.0.0.0:5677 option tcplog mode tcp balance leastconn server rabbit1 rabbitmq1:5672 check inter 2s rise 2 fall 3 server rabbit2 rabbitmq2:5672 check inter 2s rise 2 fall 3 server rabbit3 rabbitmq3:5672 check inter 2s rise 2 fall 3 listen http_front bind 0.0.0.0:80 stats uri /haproxy ?stats listen rabbitmq_admin bind 0.0.0.0:8001 server rabbit1 rabbitmq1:15672 server rabbit2 rabbitmq2:15672 server rabbit3 rabbitmq3:15672 |
启动haproxy后,可以通过haproxy来访问rabbitmq集群:http://external-ip:8001
获取haproxy的状态:http://external-ip:1080/haproxy?stats
rabbitmq exporter部署
要收集rabbitmq的metrics给prometheus使用的话,可以使用开源的rabbitmq-exporter
参考如下:
https://github.com/kbudde/rabbitmq_exporter
https://hub.docker.com/r/kbudde/rabbitmq-exporter/
拉取镜像
1
|
# docker pull kbudde/rabbitmq-exporter |
启动rabbitmq实例
开启9090端口,这个是rabbitmq exporter的默认publish_port
启动rabbitmq exporter实例
1
|
# docker run -d --net=container:rabbitmq1 kbudde/rabbitmq-exporter |
获取rabbitmq的metrics
1
|
# wget http://localhost:9090/metrics |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:http://www.yangguanjun.com/2018/07/30/rabbitmq-cluster-deploy-with-docker