赞
踩
rabbitmq普通集群部署后,存在服务单点承压的情况,故,需要通过前端负载解决单点承压的问题;将采用nginx作为负载器,对流量进行负载分发到各个集群节点,解决服务单点负载的问题
虚拟机4台,如下列表
主机名 | 主机ip | 用途 | 备注 |
---|---|---|---|
nginx-lsb | 10.0.3.132 | 负载器 | |
rabbitmq01 | 10.0.3.133 | rabbitmq-node1 | |
rabbitmq02 | 10.0.3.134 | rabbitmq-node2 | |
rabbitmq03 | 10.0.3.135 | rabbitmq-node3 |
同一个网络中
名称 | 版本 | 类型 | 备注 |
---|---|---|---|
centos | 7.9.2009 | 操作系统 | |
docker | 26.1.4 | 软件 | rpm部署 |
bitnami/rabbitmq | latest | 容器镜像 | 容器id:80583c0e1b06 |
nginx | 1.27.0 | 容器镜像 | 容器id:e0c9858e10ed |
pivotalrabbitmq/perf-test | latest | 容器镜像 | 容器id:3804df61f5ba |
systemctl stop firewalld
systemctl disable firewalld
sed -i 's~SELINUX=enforcing~SELINUX=disabled~' /etc/selinux/config
setenforce 0
新增一个数据目录(最好和系统盘分离)
mkdir /data/docker
rm -rf /etc/yum.repos.d/* curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo yum -y remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum install -y docker-ce docker-ce-cli containerd.io mkdir /etc/docker/ cat >> /etc/docker/daemon.json << EOF { "data-root": "/data/docker", "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn","http://hub-mirror.c.163.com"] } EOF systemctl restart docker systemctl enable docker wget https://github.com/docker/compose/releases/download/v2.28.0/docker-compose-linux-x86_64 chmod 755 docker-compose-linux-x86_64 \cp -fp ddocker-compose-linux-x86_64 /usr/bin/docker-compose
#在负载均衡(10.0.3.132)的虚机上执行
docker pull nginx:1.27.0
docker pull pivotalrabbitmq/perf-test
#在rabbitmq的三个节点上执行
docker pull bitnami/rabbitmq
docker pull pivotalrabbitmq/perf-test
mkdir -p /usr/yunji/nginx_4_lsb/conf.d cat > /usr/yunji/nginx_4_lsb/docker-compose.yml << EOF services: web: image: nginx:1.27.0 container_name: nginx-web ports: - "5672:5672" volumes: - "$PWD/conf.d:/etc/nginx/conf.d" - "$PWD/nginx.conf:/etc/nginx/nginx.conf:ro" restart: no EOF cat > /usr/yunji/nginx_4_lsb/nginx.conf << EOF user root; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { worker_connections 1024; } #http { # include /etc/nginx/mime.types; # default_type application/octet-stream; # # log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; # # access_log /var/log/nginx/access.log main; # # sendfile on; # #tcp_nopush on; # # keepalive_timeout 65; # # #gzip on; # # include /etc/nginx/conf.d/*.conf; #} stream { log_format proxy '$remote_addr [$time_local] ' '$protocol $status $bytes_sent $bytes_received ' '$session_time "$upstream_addr" ' '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"'; access_log /var/log/nginx/access.log proxy; open_log_file_cache off; upstream rabbitTcp { server 10.0.3.133:5672; server 10.0.3.134:5672; server 10.0.3.135:5672; } server { listen 5672; proxy_connect_timeout 5s; proxy_timeout 30s; proxy_pass rabbitTcp; } include /etc/nginx/conf.d/*.stream; } EOF
mkdir -p /usr/yunji/rabbitmq-server cat > /usr/yunji/rabbitmq-server/docker-compose.yml << EOF # Copyright Broadcom, Inc. All Rights Reserved. # SPDX-License-Identifier: APACHE-2.0 version: '2' services: rabbitmq: image: docker.io/bitnami/rabbitmq container_name: rabbitmq01 # ports: # - '4369:4369' # - '5551:5551' # - '5552:5552' # - '5672:5672' # - '25672:25672' # - '15672:15672' network_mode: "host" environment: - RABBITMQ_NODE_TYPE=stats - RABBITMQ_NODE_NAME=rabbit@rabbitmq01 - RABBITMQ_ERL_COOKIE=s3cr3tc00ki3 # - RABBITMQ_SECURE_PASSWORD=yes - RABBITMQ_LOGS=- extra_hosts: - "rabbitmq01:10.0.3.133" - "rabbitmq02:10.0.3.134" - "rabbitmq03:10.0.3.135" volumes: - 'rabbitmq_data:/bitnami/rabbitmq/mnesia' volumes: rabbitmq_data: driver: local EOF
mkdir -p /usr/yunji/rabbitmq-server cat > /usr/yunji/rabbitmq-server/docker-compose.yml << EOF # Copyright Broadcom, Inc. All Rights Reserved. # SPDX-License-Identifier: APACHE-2.0 version: '2' services: rabbitmq: image: docker.io/bitnami/rabbitmq container_name: rabbitmq02 # ports: # - '4369:4369' # - '5551:5551' # - '5552:5552' # - '5672:5672' # - '25672:25672' # - '15672:15672' network_mode: "host" environment: - RABBITMQ_NODE_TYPE=queue-disc - RABBITMQ_NODE_NAME=rabbit@rabbitmq02 - RABBITMQ_CLUSTER_NODE_NAME=rabbit@rabbitmq01 - RABBITMQ_ERL_COOKIE=s3cr3tc00ki3 # - RABBITMQ_SECURE_PASSWORD=yes - RABBITMQ_LOGS=- extra_hosts: - "rabbitmq01:10.0.3.133" - "rabbitmq02:10.0.3.134" - "rabbitmq03:10.0.3.135" volumes: - 'rabbitmq_data:/bitnami/rabbitmq/mnesia' volumes: rabbitmq_data: driver: local EOF
mkdir -p /usr/yunji/rabbitmq-server cat > /usr/yunji/rabbitmq-server/docker-compose.yml << EOF # Copyright Broadcom, Inc. All Rights Reserved. # SPDX-License-Identifier: APACHE-2.0 version: '2' services: rabbitmq: image: docker.io/bitnami/rabbitmq container_name: rabbitmq03 # ports: # - '4369:4369' # - '5551:5551' # - '5552:5552' # - '5672:5672' # - '25672:25672' # - '15672:15672' network_mode: "host" environment: - RABBITMQ_NODE_TYPE=queue-ram - RABBITMQ_NODE_NAME=rabbit@rabbitmq03 - RABBITMQ_CLUSTER_NODE_NAME=rabbit@rabbitmq01 - RABBITMQ_ERL_COOKIE=s3cr3tc00ki3 # - RABBITMQ_SECURE_PASSWORD=yes - RABBITMQ_LOGS=- extra_hosts: - "rabbitmq01:10.0.3.133" - "rabbitmq02:10.0.3.134" - "rabbitmq03:10.0.3.135" volumes: - 'rabbitmq_data:/bitnami/rabbitmq/mnesia' volumes: rabbitmq_data: driver: local EOF
cd /usr/yunji/rabbitmq-server
docker-compose -f docker-compose.yml up -d --no-deps
cd /usr/yunji/rabbitmq-server
docker-compose -f docker-compose.yml up -d --no-deps
cd /usr/yunji/rabbitmq-server
docker-compose -f docker-compose.yml up -d --no-deps
使用浏览器访问url: http://10.0.3.133:15672,确认节点是否都可以看到;如果是,则确认集群成功。
用户授权参考如下链接内容
RabbitMQ3.13.x之四_RabbitMQ角色说明及创建用户与授权
cd /usr/yunji/nginx_4_lsb/
docker-compose -f docker-compose.yml up -d --no-deps
docker run -it --rm pivotalrabbitmq/perf-test:latest -h "amqp://admin:admin@10.0.3.133:5672" -x 2 -y 4 -u "perf-test1" -a --id "test1" -s 4000
docker run -it --rm pivotalrabbitmq/perf-test:latest -H "amqp://admin:admin@10.0.3.133:5672,amqp://admin:admin@10.0.3.134:5672,amqp://admin:admin@10.0.3.135:5672" -x 2 -y 4 -u "perf-test1" -a --id "test1" -s 4000
docker run -it --rm pivotalrabbitmq/perf-test:latest -h "amqp://admin:admin@10.0.3.132:5672" -x 2 -y 4 -u "perf-test1" -a --id "test1" -s 4000
增加nginx负载均衡的能力,实现了流量负载的能力,确实可以解决单节点负载的问题。
rabbitmq节点宕机一个之后,该节点得到的消息是否仍然可以消费?
nginx单点部署,是否存在单点故障的问题
后端一个rabbitmq的节点宕机,nginx是否可以感知到,并且将后续的消息转向另外的节点?
rabbitmq节点宕机一个之后,该节点得到的消息是否仍然可以消费?
nginx单点部署,是否存在单点故障的问题
后端一个rabbitmq的节点宕机,nginx是否可以感知到,并且将后续的消息转向另外的节点?
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。