[RocketMQ] 005-Docker deploys RocketMQ

[RocketMQ] 005-Docker deploys RocketMQ

1. Deployment

1. Pull the image

MQ mirror

docker pull rocketmqinc/rocketmq:latest

Visual platform mirroring

docker pull styletang/rocketmq-console-ng:latest

2. Create a mount directory

Create a nameserver mount directory

mkdir -p /home/zibo/docker/rocketmq/data/namesrv/logs /home/zibo/docker/rocketmq/data/namesrv/store

Create a broker directory

mkdir -p /home/zibo/docker/rocketmq/data/broker/logs /home/zibo/docker/rocketmq/data/broker/store

Create a broker configuration file directory

mkdir -p /home/zibo/docker/rocketmq/data/conf

3. Edit the configuration file

Directory: /home/zibo/docker/rocketmq/data/conf

vim broker.conf

# 所属集群名称,如果节点较多可以配置多个
brokerClusterName = DefaultCluster
#broker名称,master和slave使用相同的名称,表明他们的主从关系
brokerName = broker-a
#0表示Master,大于0表示不同的slave
brokerId = 0
#表示几点做消息删除动作,默认是凌晨4点
deleteWhen = 04
#在磁盘上保留消息的时长,单位是小时
fileReservedTime = 48
#有三个值:SYNC_MASTER,ASYNC_MASTER,SLAVE;同步和异步表示Master和Slave之间同步数据的机制;
brokerRole = ASYNC_MASTER
#刷盘策略,取值为:ASYNC_FLUSH,SYNC_FLUSH表示同步刷盘和异步刷盘;SYNC_FLUSH消息写入磁盘后才返回成功状态,ASYNC_FLUSH不需要;
flushDiskType = ASYNC_FLUSH
# 设置broker节点所在服务器的ip地址,也就是centosOS7的服务ip
brokerIP1 = [ip地址]
# 磁盘使用达到95%之后,生产者再写入消息会报错 CODE: 14 DESC: service not available now, maybe disk full
diskMaxUsedSpaceRatio=95

4. Start the service

start nameserver

docker run -d --restart=always --name rocketmq_nameserver -p 9876:9876 -v /home/zibo/docker/rocketmq/data/namesrv/logs:/root/logs -v /home/zibo/docker/rocketmq/data/namesrv/store:/root/store -e "MAX_POSSIBLE_HEAP=100000000" rocketmqinc/rocketmq sh mqnamesrv
  • docker run: This is the Docker command used to create and manage Docker containers.
  • -d: This is an option that instructs Docker to run the container in the background.
  • --restart=always: This is an option that instructs the Docker container to always restart on exit.
  • --name rocketmq_nameserver: This is an option to specify a name for the container, here the container is named "rocketmq_nameserver".
  • -p 9876:9876: This is an option to map the host's port 9876 to the container's port 9876. RocketMQ's NameServer uses port 9876 for communication.
  • -v /home/zibo/docker/rocketmq/data/namesrv/logs:/root/logs: This is an option to /home/zibo/docker/rocketmq/data/namesrv/logsmount a directory on the host to a directory in the container /root/logs. This is done to save the log files of the NameServer on the host for easy viewing and management.
  • -v /home/zibo/docker/rocketmq/data/namesrv/store:/root/store: This is an option to /home/zibo/docker/rocketmq/data/namesrv/storemount a directory on the host to a directory in the container /root/store. This is done to save the data files stored by the NameServer on the host for persistent storage.
  • -e "MAX_POSSIBLE_HEAP=100000000": This is an option, used to set environment variables. Here, it sets an MAX_POSSIBLE_HEAPenvironment variable called and sets its value to 100000000. This environment variable can be used to adjust the nameserver heap memory size.
  • rocketmqinc/rocketmq: This specifies the name of the Docker image to use. Here, the official image provided by RocketMQ is used, which is used to run RocketMQ.
  • sh mqnamesrv: This is the command to run in the container. It starts the NameServer component of RocketMQ.

To sum up, this command will create a Docker container named "rocketmq_nameserver" and run RocketMQ's NameServer component in background mode in this container. The container will continue to run in the background, and if the container exits unexpectedly, Docker will automatically restart the container. Port 9876 of the host is mapped to port 9876 of the container, and the log and data files of the NameServer will be stored in the corresponding directories of the host. By setting environment variables, you can adjust the heap memory size of NameServer. The official image provided by RocketMQ is used to run the container.

start broker

docker run -d --restart=always --name rocketmq_broker --link rocketmq_nameserver:namesrv -p 10911:10911 -p 10909:10909 -v /home/zibo/docker/rocketmq/data/broker/logs:/root/logs -v /home/zibo/docker/rocketmq/data/broker/store:/root/store -v /home/zibo/docker/rocketmq/data/conf/broker.conf:/opt/rocketmqinc/rocketmq/conf/broker.conf -e "NAMESRV_ADDR=namesrv:9876" -e "MAX_POSSIBLE_HEAP=200000000" rocketmqinc/rocketmq sh mqbroker -c /opt/rocketmqinc/rocketmq/conf/broker.conf
  • docker run: This is the Docker command used to create and manage Docker containers.
  • -d: This is an option that instructs Docker to run the container in the background.
  • --restart=always: This is an option that instructs the Docker container to always restart on exit.
  • --name rocketmq_broker: This is an option to specify a name for the container, here the container is named "rocketmq_broker".
  • --link rocketmq_nameserver:namesrv: This is an option to rocketmq_nameserverlink a container with another container. This allows the Broker container to know the location of the NameServer.
  • -p 10911:10911 -p 10909:10909: This is the option to map the host's ports 10911 and 10909 to the container's ports 10911 and 10909. RocketMQ's Broker uses these ports for communication.
  • -v /home/zibo/docker/rocketmq/data/broker/logs:/root/logs: This is an option to /home/zibo/docker/rocketmq/data/broker/logsmount a directory on the host to a directory in the container /root/logs. This is done to save the Broker's log files on the host for easy viewing and management.
  • -v /home/zibo/docker/rocketmq/data/broker/store:/root/store: This is an option to /home/zibo/docker/rocketmq/data/broker/storemount a directory on the host to a directory in the container /root/store. This is done to save the data files stored by the Broker on the host for persistent storage.
  • -v /home/zibo/docker/rocketmq/data/conf/broker.conf:/opt/rocketmqinc/rocketmq/conf/broker.conf: This is an option to /home/zibo/docker/rocketmq/data/conf/broker.confmount the file on the host to the path in the container /opt/rocketmqinc/rocketmq/conf/broker.conf. This is done to mount a custom Broker configuration file into the container.
  • -e "NAMESRV_ADDR=namesrv:9876": This is an option, used to set environment variables. It sets an NAMESRV_ADDRenvironment variable named , and sets its value to namesrv:9876. This environment variable is used to inform the address and port of the Broker container NameServer.
  • -e "MAX_POSSIBLE_HEAP=200000000": This is an option, used to set environment variables. It sets an MAX_POSSIBLE_HEAPenvironment variable named , and sets its value to 200000000. This environment variable can be used to adjust the size of Broker's heap memory.
  • rocketmqinc/rocketmq: This specifies the name of the Docker image to use. Here, the official image provided by RocketMQ is used, which is used to run RocketMQ.
  • sh mqbroker -c /opt/rocketmqinc/rocketmq/conf/broker.conf: This is the command to run in the container. It starts the Broker component of RocketMQ and specifies the configuration file /opt/rocketmqinc/rocketmq/conf/broker.conf.

To sum up, this command will create a Docker container named "rocketmq_broker" and run RocketMQ's Broker component in background mode in the container. The container will continue to run in the background, and if the container exits unexpectedly, Docker will automatically restart the container. Ports 10911 and 10909 of the host are mapped to ports 10911 and 10909 of the container, and the log and data files of the Broker will be stored in the corresponding directories of the host. By setting environment variables, you can configure the address and port that the Broker connects to the NameServer, and adjust the heap memory size of the Broker. The official image provided by RocketMQ is used to run the container, and a custom Broker configuration file is specified.

Start the visualization platform

docker run -d --restart=always --name rocketmq_console -e "JAVA_OPTS=-Drocketmq.namesrv.addr=[nameserver的ip]:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" -p 9877:8080 styletang/rocketmq-console-ng
  • docker run: This is the Docker command used to create and manage Docker containers.
  • -d: This is an option that instructs Docker to run the container in the background.
  • --restart=always: This is an option that instructs the Docker container to always restart on exit.
  • --name rocketmq_console: This is an option to specify a name for the container, here the container is named "rocketmq_console".
  • -e "JAVA_OPTS=-Drocketmq.namesrv.addr=[nameserver的ip]:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false": This is an option, used to set environment variables. Here, an JAVA_OPTSenvironment variable named is set, which contains two parameters:
    • -Drocketmq.namesrv.addr=[nameserver的ip]:9876: This parameter is used to specify the address and port of the NameServer connected to the RocketMQ console. You need to [nameserver的ip]substitute the IP address of the actual NameServer.
    • -Dcom.rocketmq.sendMessageWithVIPChannel=false: This parameter is used to disable the VIP channel to send messages.
  • -p 9877:8080: This is an option to map port 9877 of the host to port 8080 of the container. The RocketMQ console uses port 8080 for access.
  • styletang/rocketmq-console-ng: This specifies the name of the Docker image to use. Here, the image of the RocketMQ console (Console) is used.

To sum up, this command will create a Docker container named "rocketmq_console" and run the RocketMQ console in background mode in this container. The container will continue to run in the background, and if the container exits unexpectedly, Docker will automatically restart the container. The RocketMQ console will connect to the specified NameServer, you need to [nameserver的ip]replace the IP address of the actual NameServer. The console will be accessed through port 9877 of the host, mapped to port 8080 of the container. The image of the RocketMQ console (Console) is used to run the container.

2. Access interface

ip:9877, don't forget to open the port!

image-20230712202335069

3. Others

Reference article:

docker deployment RocketMQ

https://blog.csdn.net/SmallCat0912/article/details/128535930

おすすめ

転載: blog.csdn.net/qq_29689343/article/details/131689776
おすすめ