正常搭建集群时,通过应当创建多台服务器,但是由于自身电脑不支持,所以考虑在虚拟机上创建centos服务器为node-master,在docker上创建两台ubuntu为node1和node2.
在搭建过程中遇到了很多问题,现记录一下。
1. 在ubuntu容器搭建过程中,发现需要在基本的ubuntu上安装诸多命令,所以采用Dockerfile方法,统一构建新的ubunturabbitmq镜像
FROM ubuntu
MAINTAINER xxxENV MYPATH /usr/local
WORKDIR $MYPATHRUN apt-get update && apt-get install -y systemd
RUN apt-get install net-tools
RUN apt-get install -y erlang-nox
RUN apt-get install -y rabbitmq-server
RUN apt-get install -y vim
RUN echo 'root:123456' | chpasswdEXPOSE 80
EXPOSE 15672
EXPOSE 5672
CMD usr/sbin/init
2. 启动node1时发现,容器中不包含systemctl命令,所以不能启动rabbitmq,直接install 时发现由于下载源的问题,无法进行update
https://blog.csdn.net/weixin_46389691/article/details/133523514
参考以上网址:执行
# 备份旧的下载源
mv /etc/apt/sources.list /etc/apt/sources.list.old
# 创建新的下载源
vim /etc/apt/sources.list
# 添加新的下载源
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse# 更新下载源
apt-get update
apt-get install systemd -y
apt-get install systemctl -y
此时发现apt update 报错 Certificate verification failed: The certificate is NOT trusted.
apt命令报证书错误的解决方法------- Certificate verification failed: The certificate is NOT trusted.-CSDN博客
参照以上网址,进行如下操作
#更改源文件,将所有的https改成http:
vim /etc/apt/sources.list
# 更新下载源
apt-get update
#安装/更新证书ca-certificates
apt-get install --reinstall ca-certificates
#将镜像源文件改回https
vim /etc/apt/sources.list
# 更新下载源
apt-get update
apt-get install systemd -y
apt-get install systemctl -y
3. 启动并进入容器后,依旧报错:System has not been booted with systemd as init system (PID 1). Can‘t operat
参考:-----System has not been booted with systemd as init system (PID 1). Can‘t operat - 码农教程
docker run --privileged -itd --network rabbitmqcluster -p 5674:5672 -p 82:80 -p 15674:5672 -p 23:22 --name node1 ubunturabbitmq:2.0 /bin/bash
此时顺利创建容器,并启动rabbitmq
4. 网络采取的时,虚拟机与主机采用NAT模式,使得虚拟机能与主机相连,容器采用bridge模式,使虚拟机与容器互通。
5. 修改3台机器的主机名称
vim /etc/hostname
6. 配置各个节点的host 文件,让各个节点都能互相识别对方
vim /etc/hosts
ip nodename
7. 确保各个节点的cookie文件使用同一个值
在node-master 节点上执行远程操作命令
scp /var/lib/rabbitmq/.erlang.cookie root@node1:/var/lib/rabbitmq/.erlang.cookie
scp /var/lib/rabbitmq/.erlang.cookie root@node2:/var/lib/rabbitmq/.erlang.cookie
发现两台机器没有ssh :
解决ssh:connecttohostxxxport22:Connectionrefuse。。。 - 百度文库
安装ssh
apt-get install openssh-server
apt-get install openssh-client
修改config文件
vim /etc/ssh/sshd_config 默认端口22注释解开
重启ssh
/etc/init.d/ssh restart
再次复制时,发现还是不行scp Permission denied (publickey,password)
参考网址:【精选】【ssh】【scp】scp Permission denied (publickey,password)解决方法-CSDN博客
在A主机里的用户
运行 #ssh-keygen -t rsa # 生成 rsa规则的密钥
把A主机上的id_rsa.pub文件,拷贝到B主机的root用户主目录下的.ssh目录下,并且改名为authorized_keys (可以不是root用户,其他用户也可以)
设置文件权限 777
8. 启动RabbitMQ服务
rabbitmq启动 报错ERROR: node with name "rabbit" already running on "localhost"
rabbitmqctl start_app
chown rabbitmq:rabbitmq .erlang.cookie
chmod 400 .erlang.cookie
9. 在node节点
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster rabbitmq@node
rabbitmqctl start_apps
10. 解除节点
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
rabbitmqctl cluster_status
rabbitmqctl forget_cluster_node rabbit@node2
未解决问题:
在添加node节点时,报错,怀疑版本不同,未解决,如果有那位大佬知道是什么问题,欢迎浏览评论
Error:
{:inconsistent_cluster, 'Mnesia protocol negotiation failed. Local version: {8,4}. Remote version {8,1}'}