• 欢迎访问VPS岛网站,国外VPS,国内VPS,国外服务器,国内服务器,服务器主机,测评及优惠码,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站 QQ群

CentOS7.X环境下基于docker安装部署RabbitMQ集群

Centos技术 liveyoufo 59次浏览 已收录 0个评论

1、IP地址规划(将信息配置到/etc/hosts中)
主机名 IP地址
RabbitMQ01 192.168.8.131
RabbitMQ02 192.168.8.132
RabbitMQ03 192.168.8.133
RabbitMQ04 192.168.8.134
2、RabbitMQ集群安装
(1)四个节点同时运行,下载RabbitMQ镜像
[root@RabbitMQ01~]# docker pull rabbitmq:3-management
(2)四个节点分别运行,启动RabbitMQ容器

[root@RabbitMQ01~]# docker run -d –restart=always –hostname rabbit01 –name rabbit-01 -p 25672:25672 -p 15672:15672 -p 5672:5672 -p 5671:5671 -p 4369:4369 –add-host rabbit02:192.168.8.132 –add-host rabbit03:192.168.8.133 –add-host rabbit04:192.168.8.134 -e RABBITMQ_ERLANG_COOKIE=’rbmqcookie’ rabbitmq:3-management
[root@RabbitMQ02~]# docker run -d –restart=always –hostname rabbit02 –name rabbit-02 -p 25672:25672 -p 15672:15672 -p 5672:5672 -p 5671:5671 -p 4369:4369 –add-host rabbit01:192.168.8.131 –add-host rabbit03:192.168.8.133 –add-host rabbit04:192.168.8.134 -e RABBITMQ_ERLANG_COOKIE=’rbmqcookie’ rabbitmq:3-management
[root@RabbitMQ03~]# docker run -d –restart=always –hostname rabbit03 –name rabbit-03 -p 25672:25672 -p 15672:15672 -p 5672:5672 -p 5671:5671 -p 4369:4369 –add-host rabbit01:192.168.8.131 –add-host rabbit02:192.168.8.132 –add-host rabbit04:192.168.8.134 -e RABBITMQ_ERLANG_COOKIE=’rbmqcookie’ rabbitmq:3-management
[root@RabbitMQ04~]# docker run -d –restart=always –hostname rabbit04 –name rabbit-04 -p 25672:25672 -p 15672:15672 -p 5672:5672 -p 5671:5671 -p 4369:4369 –add-host rabbit01:192.168.8.131 –add-host rabbit02:192.168.8.132 –add-host rabbit03:192.168.8.133 -e RABBITMQ_ERLANG_COOKIE=’rbmqcookie’ rabbitmq:3-management
(3)、将节点添加至集群服务中,我们将节点03设置为集群的master节点,其他为子节点,注意配置两个节点为ram节点,另两个为disc节点,执行时注意命令的不同
节点01上执行:

[root@RabbitMQ01~]# docker exec -it rabbit-01 bash
[rabbit@rabbit01]# rabbitmqctl stop_app
[rabbit@rabbit01]# rabbitmqctl reset
[rabbit@rabbit01]# rabbitmqctl join_cluster –ram rabbit@rabbit03
[rabbit@rabbit01]# rabbitmqctl start_app
[rabbit@rabbit01]# exit
节点02上执行:

[root@RabbitMQ02~]# docker exec -it rabbit-02 bash
[rabbit@rabbit02]# rabbitmqctl stop_app
[rabbit@rabbit02]# rabbitmqctl reset
[rabbit@rabbit02]# rabbitmqctl join_cluster –ram rabbit@rabbit03
[rabbit@rabbit02]# rabbitmqctl start_app
[rabbit@rabbit02]# exit
节点04上执行:

[root@RabbitMQ04~]# docker exec -it rabbit-01 bash
[rabbit@rabbit04]# rabbitmqctl stop_app
[rabbit@rabbit04]# rabbitmqctl reset
[rabbit@rabbit04]# rabbitmqctl join_cluster rabbit@rabbit03
[rabbit@rabbit04]# rabbitmqctl start_app
[rabbit@rabbit04]# exit
节点03上执行:

[root@RabbitMQ03~]# docker exec -it rabbit-03 bash
[rabbit@rabbit03]# rabbitmqctl stop_app
[rabbit@rabbit03]# rabbitmqctl reset
[rabbit@rabbit03]# rabbitmqctl start_app
[rabbit@rabbit03]# exit
3、配置添加ha-mode镜像
Name:HA
Pattern:.
Definition:ha-mode = all
CentOS7.X环境下基于docker安装部署RabbitMQ集群

集群启动后的访问主界面:
CentOS7.X环境下基于docker安装部署RabbitMQ集群

3、安装配置nginx,以提供高可用
nginx的安装,这里略过,直接进入配置
[root@nginx~]# cd /usr/local/nginx/conf
[root@nginx~conf]# vi nginx.conf
其他配置略过

stream{
upstream rabbitmq{
server 192.168.8.131:5672 max_fails=2 fail_timeout=5s weight=2;
server 192.168.8.132:5672 max_fails=2 fail_timeout=5s weight=2;
server 192.168.8.133:5672 max_fails=2 fail_timeout=5s weight=2;
server 192.168.8.134:5672 max_fails=2 fail_timeout=5s weight=2;
}
server{
listen 5678;
proxy_pass rabbitmq;
}
}
[root@nginx~conf]# vi rabbitmqstream.conf
upstream mqweb {
ip_hash;
server 192.168.8.131:15672;
server 192.168.8.132:15672;
server 192.168.8.133:15672;
server 192.168.8.134:15672;
}
server {
listen 80;
server_name localhost;

location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
client_body_buffer_size 256k;

proxy_connect_timeout 60;
proxy_send_timeout 60;
proxy_read_timeout 60;

proxy_buffer_size 256k;
proxy_buffers 8 256k;
proxy_busy_buffers_size 512k;
proxy_temp_file_write_size 512k;
}
}
 重新启动nginx容器

[root@nginx~conf]# /usr/local/nginx/sbin/nginx -s reload
[root@nginx~conf]# /usr/local/nginx/sbin/nginx -s stop
[root@nginx~conf]# /usr/local/nginx/sbin/nginx


VPS岛 的文章和资源来自互联网,仅作为参考资料,如果有侵犯版权的资源请尽快联系站长,我们会在24h内删除有争议的资源。丨 转载请注明CentOS7.X环境下基于docker安装部署RabbitMQ集群
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址