docker-compose配置rabbitmq集群服务器
交流QQ号:555913397有什么问题可以加群大家一起交流Docker安装安装环境:Centos71.安装dockeryum install -y docker2.配置阿里云docker镜像服务在阿里云容器镜像服务里有个镜像加速器,在里面可以得到私有的镜像加速地址下面编辑docker镜像加速vi /etc/docker/daemon.jso...
交流QQ号:555913397
有什么问题可以加群大家一起交流
Docker安装
安装环境:Centos7
1.安装docker
yum install -y docker
2.配置阿里云docker镜像服务
在阿里云容器镜像服务里有个镜像加速器,在里面可以得到私有的镜像加速地址
下面编辑docker镜像加速
vi /etc/docker/daemon.json
会得到如下内容
{}
下面来改造它
{
"registry-mirrors": ["https://你的私有地址.mirror.aliyuncs.com"]
}
保存文件进行docker配置文件重载
sudo systemctl daemon-reload
3.配置docker开机启动
systemctl enable docker.service
4.启动docker
systemctl start docker.service
5.创建docker网卡
docker network create subnet=172.21.0.0/16 rabbitmqnet
安装docker-conpose
curl -L https://github.com/docker/compose/releases/download/1.21.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
完成后就可以使用docker-compose了
使用配置rabbitmq集群
1.编写yml文件
第一个集群服务器yml配置-ram存储模式
version: '3.6'
networks:
rabbit:
external:
name: rabbitmqnet
services:
rabbitmq:
image: rabbitmq:management
ports:
- "4369:4369"
- "5671:5671"
- "25672:25672"
- "5672:5672"
- "15672:15672"
container_name: rabbitmq1
hostname: rabbitmq1
networks:
- rabbit
environment:
RABBITMQ_NODENAME: rabbitmq1
RABBITMQ_ERLANG_COOKIE: CURIOAPPLICATION
volumes:
- ./rabbitmq.sh:/home/rabbitmq.sh
第二个集群服务器配置-ram存储模式
version: '3.6'
networks:
rabbit:
external:
name: rabbitmqnet
services:
rabbitmq2:
image: rabbitmq:management
ports:
- "4369:4369"
- "5671:5671"
- "25672:25672"
- "5672:5672"
- "15672:15672"
container_name: rabbitmq2
hostname: rabbitmq2
networks:
- rabbit
environment:
RABBITMQ_NODENAME: rabbitmq2
RABBITMQ_ERLANG_COOKIE: CURIOAPPLICATION
volumes:
- ./rabbitmq.sh:/home/rabbitmq.sh
第三个集群服务器配置-disk存储模式
version: '3.6'
networks:
rabbit:
external:
name: rabbitmqnet
services:
rabbitmq3:
image: rabbitmq:management
ports:
- "4369:4369"
- "5671:5671"
- "25672:25672"
- "5672:5672"
- "15672:15672"
container_name: rabbitmq3
hostname: rabbitmq3
networks:
- rabbit
environment:
RABBITMQ_NODENAME: rabbitmq3
RABBITMQ_ERLANG_COOKIE: CURIOAPPLICATION
如果是配置在同一台宿主服务器这三个文件可以写在一个文件里,直接生成三台集群服务器.
2.shell文件
如果想用ram存储就用第一个shell文件,用硬盘存储就用第二个shell文件
ram集群服务器shell文件
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster --ram rabbitmq3@rabbitmq3
rabbitmqctl start_app
disk集群服务器shell文件
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster rabbitmq3@rabbitmq3
rabbitmqctl start_app
完成配置
1.生成容器
docker-compose -f rabbitmq1.yml -d up
docker-compose -f rabbitmq2.yml -d up
docker-compose -f rabbitmq2.yml -d up
2.进入容器执行shell文件完成集群连接
chmow +x /home/rabbitmq.sh
./home/rabbitmq.sh
这样就完成了rabbitmq集群服务器的配置,超级简单吧!
以下是经常遇到的问题,百度来的,下面的内容来自 醇氧 的CSDN 博客
问题一:
sudo rabbitmqctl join_cluster --ram rabbit@rabbitmq-node1
Clustering node rrabbit@rabbitmq-node1 with rabbit@rabbitmq-node1...
Error: unable to connect to nodes rabbit@rabbitmq-node1]: nodedown
DIAGNOSTICS
===========
attempted to contact: [rabbit@rabbitmq-node1]
rabbit@rabbitmq-node1:
* unable to connect to epmd (port 4369) on rabbitmq-node1: nxdomain (non-existing domain)
current node details:
- node name: 'rabbitmqctl-526rabbitmq-node1'
- home dir: /var/lib/rabbitmq
- cookie hash: 50YO3zK+HJHos0tab1vHjg==
解决之道:
集群节点间需能互相访问,故每个集群节点的hosts文件应包含集群内所有节点的信息以保证互相解析
vim /etc/hosts
1 IP rabbit@rabbitmq-node1
2 IP rabbit@rabbitmq-node2
3 IP rabbit@rabbitmq-node3
之后重启各节点中的rabbitmq
问题二:
cluster搭建起来后若在web管理工具中rabbitmq_management的Overview的Nodes部
“Node statistics not available”
说明在该节点上web管理插件还未启用。
直接在显示提示信息的节点上运行
rabbitmq-plugins enable rabbitmq_management
Error: mnesia_unexpectedly_running
原因:忘记先停止stop_app
解决:
rabbitmqctl stop_app
问题三:
[rabbit@rabbitmq-node2 ~]$ sudo rabbitmqctl start_app
Starting node rabbit@rabbitmq-node2 ...
BOOT FAILED
===========
Error description:
{error,{inconsistent_cluster,"Node rabbit@rabbitmq-node1 thinks it's clustered with node rabbit@rabbitmq-node1, but rabbit@rabbitmq-node2 disagrees"}}
Log files (may contain more information):
/var/log/rabbitmq/rabbit@VMS00782.log
/var/log/rabbitmq/rabbit@VMS00782-sasl.log
Stack trace:
[{rabbit_mnesia,check_cluster_consistency,0},
{rabbit,'-start/0-fun-0-',0},
{rabbit,start_it,1},
{rpc,'-handle_call_call/6-fun-0-',5}]
Error: {rabbit,failure_during_boot,
{error,
{inconsistent_cluster,
"Node rabbit@rabbitmq-node2 thinks it's clustered with node rabbit@rabbitmq-node1, but rabbit@rabbitmq-node2 disagrees"}}}
需要重置一下
[rabbit@rabbitmq-node2~]$ rabbitmqctl reset
Resetting node rabbit@rabbitmq-node2 ...
[rabbit@rabbitmq-node2~]$ rabbitmqctl start_app
Starting node rabbit@rabbitmq-node2 ...
问题四:
[root@redid-server01 mnesia]# rabbitmqctl join_cluster rabbit@rabbitmq-node2
Clustering node 'rabbit@redid-server01' with 'rabbit@rabbitmq-node2' ...
Error: {corrupt_or_missing_cluster_files,{error,enoent},{error,enoent}}
更多推荐
所有评论(0)