KeepAlived+ha-proxy+rabbitmq
mirror 镜像队列,是保证 rabbitMQ 数据的高可靠性解决方案,主要就是实现数据的同步,一般来讲是 2 - 3 个节点实现数据同步。对于 100% 数据可靠性解决方案,一般是采用 3 个节点。 用 KeepAlived 做 HA-Proxy 的高可用,然后有 3 个节点的 MQ 服务,消息发送到主节点上,主节点通过 mirror 队列把数据同步到其他的 MQ 节点,来实现其高可靠。
构建rabbitmq
docker pull rabbitmq:3.9.11-management-alpine
version: "3.6"
services:
rabbitmq_server_175_10:
image: rabbitmq:3.9.11-management-alpine
ports:
- "15610:15672"
- "5610:5672"
networks:
rabbitmq:
ipv4_address: 175.22.1.10
hostname: rabbitmq_server_175_10
volumes:
- "/www/biny/rabbitmq/10:/var/lib/rabbitmq"
container_name: rabbitmq_server_175_10
rabbitmq_server_175_11:
image: rabbitmq:3.9.11-management-alpine
ports:
- "15611:15672"
- "5611:5672"
networks:
rabbitmq:
ipv4_address: 175.22.1.11
hostname: rabbitmq_server_175_11
volumes:
- "/www/biny/rabbitmq/11:/var/lib/rabbitmq"
container_name: rabbitmq_server_175_11
rabbitmq_server_175_12:
image: rabbitmq:3.9.11-management-alpine
ports:
- "15612:15672"
- "5612:5672"
networks:
rabbitmq:
ipv4_address: 175.22.1.12
hostname: rabbitmq_server_175_12
volumes:
- "/www/biny/rabbitmq/12:/var/lib/rabbitmq"
container_name: rabbitmq_server_175_12
networks:
rabbitmq:
driver: bridge
ipam:
config:
- subnet: "175.22.1.0/24"
docker-compose -f rabbitmq.yaml up -d 默认账号密码:guest docker exec -it rabbitmq_server_175_10 bash # 进入一台rabbitmq容器 cat /root/.erlang.cookie # 查看cookie并保存 将cookie替换到所有rabbitmq容器的.erlang.cookie文件中 如遇到权限问题,直接进入容器中编辑cookie文件,保持3个文件一致 执行 sh init_rabbitmq.sh 访问:http://127.0.0.1:15610/
构建ha-proxy
docker pull haproxy:1.7-apline
version: "3.6"
services:
haproxy_server_176_10:
image: haproxy:1.7-alpine
ports:
- "8110:8100"
- "5710:5600"
networks:
haproxy:
ipv4_address: 176.22.1.10
privileged: true
volumes:
- "/www/biny/haproxy:/haproxy"
- "/www/biny/haproxy/keepalived/10:/keepalived"
container_name: haproxy_server_176_10
command: haproxy -f /haproxy/haproxy.cfg
haproxy_server_176_11:
image: haproxy:1.7-alpine
ports:
- "8111:8100"
- "5711:5600"
networks:
haproxy:
ipv4_address: 176.22.1.11
privileged: true
volumes:
- "/www/biny/haproxy:/haproxy"
- "/www/biny/haproxy/keepalived/11:/keepalived"
container_name: haproxy_server_176_11
command: haproxy -f /haproxy/haproxy.cfg
networks:
haproxy:
driver: bridge
ipam:
config:
- subnet: "176.22.1.0/24"
docker-compose -f ha-proxy.yaml up -d
ha-proxy容器中安装keepalived
ha-proxy-Dockerfile重新构建安装好keepalived的haproxy容器 docker build -t haproxy .
FROM haproxy:2.3-dev3-alpine
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk add keepalived
docker-compose -f ha-proxy.yaml down 修改ha-proxy.yaml文件,启用新容器 docker-compose -f ha-proxy.yaml up -d 添加虚拟ip docker exec -it haproxy_server_176_10 sh keepalived -f /keepalived/keepalived.conf ip a docker exec -it haproxy_server_176_11 sh keepalived -f /keepalived/keepalived.conf ip a ifconfig eth0:0 176.22.1.100 netmask 255.255.255.0 up
nginx反向代理
增加nginx反向代理指向keepalived虚拟ip—haproxy—rabbitmq
version: "3.6"
services:
haproxy_server_176_10:
image: haproxy
ports:
- "8110:8100"
- "5710:5600"
networks:
haproxy:
ipv4_address: 176.22.1.10
privileged: true
volumes:
- "/www/biny/haproxy:/haproxy"
- "/www/biny/haproxy/keepalived/10:/keepalived"
container_name: haproxy_server_176_10
command: haproxy -f /haproxy/haproxy.cfg
haproxy_server_176_11:
image: haproxy
ports:
- "8111:8100"
- "5711:5600"
networks:
haproxy:
ipv4_address: 176.22.1.11
privileged: true
volumes:
- "/www/biny/haproxy:/haproxy"
- "/www/biny/haproxy/keepalived/11:/keepalived"
container_name: haproxy_server_176_11
command: haproxy -f /haproxy/haproxy.cfg
nginx_haproxy:
image: nginx:1.21
ports:
- "5600:5600"
networks:
haproxy:
ipv4_address: 176.22.1.12
volumes:
- "/www/biny/hanginx/conf:/etc/nginx"
container_name: nginx_haproxy_176_12
networks:
haproxy:
driver: bridge
ipam:
config:
- subnet: "176.22.1.0/24"
docker-compose -f ha-proxy.yaml up -d
宿主机执行访问测试
|