安装Docker服务(此处不详细描述)
下载rabbitMq images (可以用国内的源进行下载会快很多)
docker pull daocloud.io/library/rabbitmq
docker run -itd --hostname rabbitmq-5672 --name rabbitmq-5672 -p 5672:5672 -p 15672:15672 \
-v /home/rabbitmq:/var/lib/rabbitmq \
-e RABBITMQ_ERLANG_COOKIE='rabbitcookie' docker.io/rabbitmq
其中
–hostname 为主机名称
–name 为docker的容器名称
-p 为端口号
-v为挂载的目录
-e 设置RABBITMQ_ERLANG_COOKIE,参数值必须相同
启动后需要安装 rabbitmq_management 否则无法访问web管理(其他服务也需要enable rabbitmq_management)
docker exec -it rabbitmq-5672 bash
进入容器后执行命令
rabbitmqctl stop
rabbitmqctl reset
rabbitmq-plugins enable rabbitmq_management
rabbitmqctl start_app
docker run -itd --hostname rabbitmq-5673 --name rabbitmq-5673 -p 5673:5672 -p 15673:15672 \
-v /home/rabbitmq:/var/lib/rabbitmq \
-e RABBITMQ_ERLANG_COOKIE='rabbitcookie' \
--link rabbitmq-5672:rabbitmq-5672 docker.io/rabbitmq
–link 多个容器之间使用“–link”连接,此属性不能少.rabbitmq-5672为master的hostname
docker exec -it rabbitmq-5673 bash
进入容器后执行命令
rabbitmqctl stop
rabbitmqctl reset
rabbitmq-plugins enable rabbitmq_management
rabbitmqctl join_cluster --ram rabbit@rabbitmq-5672
rabbitmqctl start_app
docker run -itd --hostname rabbitmq-5674 --name rabbitmq-5674 -p 5674:5672 -p 15674:15672 \
-v /home/rabbitmq:/var/lib/rabbitmq \
-e RABBITMQ_ERLANG_COOKIE='rabbitcookie' \
--link rabbitmq-5672:rabbitmq-5672 \
--link rabbitmq-5673:rabbitmq-5673 \
docker.io/rabbitmq
docker exec -it rabbitmq-5674 bash
进入容器后执行命令
rabbitmqctl stop
rabbitmqctl reset
rabbitmq-plugins enable rabbitmq_management
rabbitmqctl join_cluster --ram rabbit@rabbitmq-5672
rabbitmqctl start_app
设置好完成以后 使用http访问web
http://物理机器ip:15672 进行访问,默认账号为guest/guest,也可设置密码
docker run -itd --hostname rabbitmq-5672 --name rabbitmq-5672 -p 5672:5672 -p 15672:15672 \
-v /home/rabbitmq:/var/lib/rabbitmq \
-e RABBITMQ_ERLANG_COOKIE='rabbitcookie' \
-e RABBITMQ_DEFAULT_USER=user \
-e RABBITMQ_DEFAULT_PASS=password \
docker.io/rabbitmq