docker 创建 RabbitMQ 脚本

 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
docker stop rabbit1
docker stop rabbit2
docker stop rabbit3

docker rm rabbit1
docker rm rabbit2
docker rm rabbit3

docker run -dit                                                   \
           -h rabbit1                                             \
           --name rabbit1                                         \
           -p 4361:4369                                           \
           -p 5671:5672                                           \
           -p 15671:15672                                         \
           -p 25671:25672                                         \
           -p 35191:35197                                         \
           -e RABBITMQ_ERLANG_COOKIE='rabbitcookie'               \
           -e RABBITMQ_LOGS=/var/log/rabbitmq/rabbit.log          \
           -v /data/docker/rabbit1/logs:/var/log/rabbitmq         \
           rabbitmq:3.6.6-management

docker run -dit -h node-2.rabbit                                  \
           -h rabbit2                                             \
           --name rabbit2                                         \
           -p 4362:4369                                           \
           -p 5672:5672                                           \
           -p 15672:15672                                         \
           -p 25672:25672                                         \
           -p 35192:35197                                         \
           -e RABBITMQ_ERLANG_COOKIE='rabbitcookie'               \
           -e RABBITMQ_LOGS=/var/log/rabbitmq/rabbit.log          \
           -v /data/docker/rabbit3/logs:/var/log/rabbitmq         \
           --link rabbit1:rabbit1                                 \
           rabbitmq:3.6.6-management

docker run -dit -h node-3.rabbit                                  \
           -h rabbit3                                             \
           --name rabbit3                                         \
           -p 4363:4369                                           \
           -p 5673:5672                                           \
           -p 15673:15672                                         \
           -p 25673:25672                                         \
           -p 35193:35197                                         \
           -e RABBITMQ_ERLANG_COOKIE='rabbitcookie'               \
           -e RABBITMQ_LOGS=/var/log/rabbitmq/rabbit.log          \
           -v /data/docker/rabbit3/logs:/var/log/rabbitmq         \
           --link rabbit1:rabbit1                                 \
           --link rabbit2:rabbit2                                 \
           rabbitmq:3.6.6-management


docker exec rabbit1 rabbitmqctl delete_user guest
docker exec rabbit1 rabbitmqctl add_user odoo 123456
docker exec rabbit1 rabbitmqctl set_user_tags odoo administrator

docker exec rabbit2 rabbitmqctl stop_app
docker exec rabbit2 rabbitmqctl join_cluster rabbit@rabbit1
docker exec rabbit2 rabbitmqctl start_app

docker exec rabbit3 rabbitmqctl stop_app
docker exec rabbit3 rabbitmqctl join_cluster --ram rabbit@rabbit1
docker exec rabbit3 rabbitmqctl start_app

docker exec rabbit1 rabbitmqctl cluster_status
docker exec rabbit2 rabbitmqctl cluster_status
docker exec rabbit3 rabbitmqctl cluster_status

# docker exec rabbit3 rabbitmqctl reset

查看 http://127.0.0.1:15671/#/

haproxy.cfg

 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
34
global
    daemon
    maxconn 30000
    pidfile /data/haproxy.pid
    log 127.0.0.1 local0 info
    log 127.0.0.1 local1 warning

defaults
    mode http
    log global
    option http-keep-alive
    option forwardfor
    option httplog
    timeout connect 5000ms
    timeout client 10000ms
    timeout server 50000ms
    timeout http-request 20000ms
    option httpchk GET /healthCheck.html

listen stats
    bind 0.0.0.0:8001
    stats refresh 30s
    stats uri /stats
    stats realm HAProxy\ Stats
    stats auth admin:admin

listen rabbitmq_cluster
    bind *:8002
    mode tcp
    balance roundrobin
    server rabbitnode1 172.17.0.2:5672 check inter 2000 rise 2 fall 3 weight 1
    server rabbitnode2 172.17.0.3:5672 check inter 2000 rise 2 fall 3 weight 1
    server rabbitnode3 172.17.0.4:5672 check inter 2000 rise 2 fall 3 weight 1

查看 haproxy(最好使用 firefox)

http://admin@admin:127.0.0.1:8001/stats

其他命令

1
2
3
4
5
6
# 用户命令
rabbitmqctl add_user username1 password1
rabbitmqctl delete_user username1
rabbitmqctl list_users
rabbitmqctl change_password username1 password2