1. Overall structure
Before installing RocketMQ, let's first understand the deployment architecture and components of RocketMQ, and then install RocketMQ based on the current mainstream Docker. We install a single RocketMQ here. However, in order to prevent single node failure and ensure high availability, it is recommended to install RocketMQ cluster in the production environment.
1:NameServer is a very simple Topic routing registry. Its role is similar to zookeeper in Dubbo. It supports dynamic registration and discovery of brokers.
2:Broker is mainly responsible for message storage, delivery and query, as well as service high availability guarantee.
3:Producer's role of message publishing supports distributed cluster deployment. Producer selects the corresponding Broker cluster queue for message delivery through the load balancing module of MQ. The delivery process supports fast failure and low delay.
4: the role of consumer message consumption supports distributed cluster deployment. It supports the consumption of messages in push and pull modes. At the same time, it also supports cluster and broadcast consumption. It provides real-time message subscription mechanism, which can meet the needs of most users.
Reference address: https://github.com/apache/rocketmq/tree/master/docs/cn
2. Docker installation RocketMQ
2.1 installing NameServer
-
Pull image
docker pull rocketmqinc/rocketmq
-
Create data store directory
mkdir -p /docker/rocketmq/data/namesrv/logs /docker/rocketmq/data/namesrv/store
-
install
docker run -d --restart=always --name rmqnamesrv --privileged=true -p 9876:9876 -v /docker/rocketmq/data/namesrv/logs:/root/logs -v /docker/rocketmq/data/namesrv/store:/root/store -e "MAX_POSSIBLE_HEAP=100000000" rocketmqinc/rocketmq sh mqnamesrv
Parameter Description:
parameter | explain |
---|---|
-d | Start as a daemon |
- -restart=always | When docker restarts, the container restarts automatically |
- -name rmqnamesrv | Set the name of the container to rmqnamesrv |
-p 9876:9876 | Mount port 9876 in the container onto host 9876 |
-v /docker/rocketmq/data/namesrv/logs:/root/logs | Directory mount |
-v /docker/rocketmq/data/namesrv/store:/root/store | Directory mount |
rmqnamesrv | Name of the container |
-e "MAX_POSSIBLE_HEAP=100000000" | Set the maximum heap memory of the container to 100000000 |
rocketmqinc/rocketmq | Image name used |
sh mqnamesrv | Start the namesrv service |
2.2 installing Broker
border configuration: create a broker Conf configuration file VI / docker / rocketmq / conf / broker Conf, configured as follows:
# Cluster name. If there are many nodes, multiple can be configured brokerClusterName = DefaultCluster #broker name, master and slave use the same name, indicating their master-slave relationship brokerName = broker-a #0 means Master, and greater than 0 means different slave brokerId = 0 #Indicates when to delete a message. The default is 4 a.m deleteWhen = 04 #The length of time messages are retained on disk, in hours fileReservedTime = 48 #There are three values: SYNC_MASTER,ASYNC_MASTER,SLAVE; Synchronous and asynchronous represent the mechanism of synchronizing data between Master and slave; brokerRole = ASYNC_MASTER #Disk brushing strategy, value: ASYNC_FLUSH,SYNC_FLUSH indicates synchronous disk brushing and asynchronous disk brushing; SYNC_ The flush message is written to the disk before returning to the success status, ASYNC_FLUSH is not required; flushDiskType = ASYNC_FLUSH # Set the ip address of the server where the broker node is located brokerIP1 = 192.168.100.130 #Proportion of remaining disks diskMaxUsedSpaceRatio=99
Installing Broker:
docker run -d --restart=always --name rmqbroker --link rmqnamesrv:namesrv -p 10911:10911 -p 10909:10909 --privileged=true -v /docker/rocketmq/data/broker/logs:/root/logs -v /docker/rocketmq/data/broker/store:/root/store -v /docker/rocketmq/conf/broker.conf:/opt/rocketmq-4.4.0/conf/broker.conf -e "NAMESRV_ADDR=namesrv:9876" -e "MAX_POSSIBLE_HEAP=200000000" rocketmqinc/rocketmq sh mqbroker -c /opt/rocketmq-4.4.0/conf/broker.conf
Description of relevant parameters:
parameter | explain |
---|---|
-d | Start as a daemon |
- -restart=always | When docker restarts, the container restarts automatically |
- -name rmqbroker | Set the name of the container to rmqbroker |
- --link rmqnamesrv:namesrv | Communicate with rmqnamesrv container |
-p 9876:9876 | Mount port 9876 in the container onto host 9876 |
-p 10909:10909 | Mount the vip channel port of the container to the host |
-e "NAMESRV_ADDR=namesrv:9876" | The address of the specified namesrv is the ip address of the native namesrv: 9876 |
-e "MAX_POSSIBLE_HEAP=200000000" rocketmqinc/rocketmq sh mqbroker | Specifies the maximum heap memory for the broker service |
rocketmqinc/rocketmq | Mirror name used |
sh mqbroker -c /opt/rocketmq-4.4.0/conf/broker.conf | Specify the profile to start the broker node |
2.3 console installation
Pull image:
docker pull pangliang/rocketmq-console-ng
Console installation: remember to modify the IP address
docker run -d --restart=always --name rmqadmin -e "JAVA_OPTS=-Drocketmq.namesrv.addr=192.168.100.130:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" -p 8080:8080 pangliang/rocketmq-console-ng
2.4 turn off firewall (or open port)
ECS also needs to open related ports.
#Turn off firewall systemctl stop firewalld.service #Prohibit startup systemctl disable firewalld.service
2.5 testing
visit: http://192.168.100.130:8080/#/ (Chinese can be switched)