RocketMQ deployment (docker version)
1. Preparations before deployment
- A linux machine. (I am using a centos7 server of Aliyun here)
- The docker environment and related simple knowledge.
- Some simple knowledge of computer networks. (It can help you fully understand why it is deployed like this)
The docker deployment is very simple and fast, and the focus is on the characteristics of different networks. If you understand the characteristics of different networks, you can deploy related services with twice the result with half the effort.
Follow the link to learn the basic three basic networks in my last blog.
blog address
Reference documents:
- RocketMQ github official documentation https://github.com/apache/rocketmq
- Docker quickly builds RokcetMQ for short
2. Deployment process
Note: The official tutorial is directly on the host network, which is the same as the host network, so there is no need to open ports, and try not to open multiple containers. Multiple containers need to change ports. For multiple containers, please use the bridge mode.
2.1. Start the name server
docker run -it --net=host apache/rocketmq ./mqnamesrv
The startup is relatively simple and does not require any additional configuration files.
2.2. Start broker
- Create broker configuration (unlike nameserver, broker needs to manually configure broker address for routing registration.)
If you have started the broker, but you need to configure the address that the broker authenticates in the route, otherwise the consumer cannot be directed to the correct route.
The error is shown below
The ip here should be filled with the external network ip as much as possible ( note : the personal computer generally does not have a public network ip, so you can only fill in the local computer first, so that the program should also run on the local computer), because the middleware communication is generally not limited to one On the host, different hosts and even different locations are normal,
- Create broker mount related folders
mkdir -p /usr/dockerrocketmq/rmqbroker01/logs
mkdir -p /usr/dockerrocketmq/rmqbroker01/conf
mkdir -p /usr/dockerrocketmq/rmqbroker01/store
vi /usr/dockerrocketmq/rmqbroker01/conf/broker.conf
- Create a broker configuration file
#nameserver的外网ip地址,这个一般为9876端口,这个配置项也可以不要,启动的时候指定
namesrvAddr=ip:port
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
#broker主机所在的外网ip,非常关键
brokerIP1 = ip
listenPort=10911
- create container
docker run -it --net=host -v /usr/data/broker/logs:/root/logs -v /usr/dockerrocketmq/rmqbroker01/store:/root/store -v /usr/dockerrocketmq/rmqbroker01/conf/broker.conf:/opt/rocketmq-4.9.4/conf/broker.conf --name rmqbroker rocketmqinc/rocketmq sh mqbroker -n ip:9876 -c /opt/rocketmq-4.9.4/conf/broker.conf
Although it is very long, the core idea is to mount three volumes, and the conf volume must be mounted, otherwise it is easy to not recognize the external network ip, resulting in a semi-disabled state of the middleware!
2.3. Start the socketmq-dashboard (it is not necessary to deploy, but it is recommended for novices to deploy)
docker run -e "JAVA_OPTS=-Drocketmq.namesrv.addr=外网ip:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" -p 8082:8080 -t pangliang/rocketmq-console-ng
I have something on 8080 here, so I changed it to port 8082.