rockermq cluster building

Keywords: iptables firewall vim network

**rockermq cluster building
Cluster workflow

  1. Start NameServer, listen to the port after NameServer gets up, wait for Broker, Producer and Consumer to connect, which is equivalent to a routing control center.
  2. Broker starts, maintains a long connection with all nameservers, and sends heartbeat packets regularly. The heartbeat package contains the current broker information (IP + port, etc.) and stores all Topic information. After successful registration, there is a mapping relationship between Topic and broker in the NameServer cluster.
  3. Before sending and receiving messages, create a Topic first. When creating a Topic, you need to specify which brokers the Topic will be stored in, or you can automatically create a Topic when sending messages.
  4. When a Producer sends a message, it first establishes a long connection with one of the NameServer clusters, obtains the current sent topics from the NameServer on which brokers exist, polls and selects a queue from the queue list, and then establishes a long connection with the Broker where the queue is to send a message to the Broker.
  5. Consumer is similar to Producer in that it establishes a long connection with one of the nameservers, obtains which brokers the current subscription topics exist on, and then directly establishes a connection channel with the Broker to start consuming messages.

Server environment

No IP role Architecture mode
1 192.168.239.130 nameserver,brokerserver Master1,Slave2
2 192.168.239.128 nameserver,brokerserver Master2,Slave1

Add domain name information

vim /etc/hosts
Configure domain name
#nameserver
192.168.25.135 rocketmq-nameserver1
192.168.25.138 rocketmq-nameserver2
#broker
192.168.25.135 rocketmq-master1
192.168.25.135 rocketmq-slave2
192.168.25.138 rocketmq-master2
192.168.25.138 rocketmq-slave1
After configuration, restart the network card
service network restart

Turn off firewall

View firewall status
service iptables status
Stop firewall
service iptables stop
Start firewall
service iptables start
service iptables restart
service iptables restart
Turn off firewall permanently
chkconfig iptables off
Restart after permanent shutdown
chkconfig iptables on

Configure environment variables

After configuration, you can start mq in any directory without entering the bin directory
#set rocketmq
ROCKETMQ_HOME=/usr/local/rocketmq/rocketmq-all-4.4.0-bin-release
PATH=PATH:PATH:PATH:ROCKETMQ_HOME/bin
export ROCKETMQ_HOME PATH
Make the modified profile effective
source /etc/profile

Create a new message store directory under mq directory

mkdir /usr/local/rocketmq/store
mkdir /usr/local/rocketmq/store/commitlog
mkdir /usr/local/rocketmq/store/consumequeue
mkdir /usr/local/rocketmq/store/index

broker profile

1.master1
Server: 192.168.239.130
vi /usr/soft/rocketmq/conf/2m-2s-sync/broker-a.properties

#Cluster name
brokerClusterName=rocketmq-cluster
#broker name. Note that different configuration files are filled in differently
brokerName=broker-a
#0 for Master, > 0 for Slave
brokerId=0
#nameServer address, semicolon split
namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
#When sending messages, topic s that do not exist in the server are automatically created. The number of queues created by default
defaultTopicQueueNums=4
#Whether Broker is allowed to automatically create Topic? It is recommended to open offline and close Online
autoCreateTopicEnable=true
#Whether Broker is allowed to automatically create subscription groups. It is recommended to enable offline and close Online
autoCreateSubscriptionGroup=true
#Broker listening port for external services
listenPort=10911
#Delete file at 4 a.m. by default
deleteWhen=04
#File retention time, default 48 hours
fileReservedTime=120
#commitLog the size of each file is 1G by default
mapedFileSizeCommitLog=1073741824
#Each file of ConsumeQueue saves 30W by default, which is adjusted according to the business situation
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#Detect physical file disk space
diskMaxUsedSpaceRatio=88
#Storage path
storePathRootDir=/usr/local/rocketmq/store
#commitLog storage path
storePathCommitLog=/usr/local/rocketmq/store/commitlog
#Consumption queue storage path storage path
storePathConsumeQueue=/usr/local/rocketmq/store/consumequeue
#Message index storage path
storePathIndex=/usr/local/rocketmq/store/index
#checkpoint file storage path
storeCheckpoint=/usr/local/rocketmq/store/checkpoint
#abort file storage path
abortFile=/usr/local/rocketmq/store/abort
#Message size limit
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker's role
#- ASYNC_MASTER asynchronous replication master
#- SYNC_MASTER synchronous dual write master
#- SLAVE
brokerRole=SYNC_MASTER
#Brush disk mode
#- ASYNC_FLUSH asynchronous disc brush
#- SYNC_FLUSH synchronous brush disk
flushDiskType=SYNC_FLUSH
#checkTransactionMessageEnable=false
#Number of message thread pools
#sendMessageThreadPoolNums=128
#Number of pull message thread pools
#pullMessageThreadPoolNums=128

2.slave2
Server: 192.168.239.130
vi /usr/soft/rocketmq/conf/2m-2s-sync/broker-b-s.properties

#Cluster name
brokerClusterName=rocketmq-cluster
#broker name. Note that different configuration files are filled in differently
brokerName=broker-b
#0 for Master, > 0 for Slave
brokerId=1
#nameServer address, semicolon split
namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
#When sending messages, topic s that do not exist in the server are automatically created. The number of queues created by default
defaultTopicQueueNums=4
#Whether Broker is allowed to automatically create Topic? It is recommended to open offline and close Online
autoCreateTopicEnable=true
#Whether Broker is allowed to automatically create subscription groups? It is recommended to turn them on offline and off online
autoCreateSubscriptionGroup=true
#Broker listening port for external services
listenPort=11011
#Delete file at 4 a.m. by default
deleteWhen=04
#File retention time, default 48 hours
fileReservedTime=120
#commitLog the size of each file is 1G by default
mapedFileSizeCommitLog=1073741824
#Each file of ConsumeQueue saves 30W by default, which is adjusted according to the business situation
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#Detect physical file disk space
diskMaxUsedSpaceRatio=88
#Storage path
storePathRootDir=/usr/local/rocketmq/store1
#commitLog storage path
storePathCommitLog=/usr/local/rocketmq/store1/commitlog
#Consumption queue storage path storage path
storePathConsumeQueue=/usr/local/rocketmq/store1/consumequeue
#Message index storage path
storePathIndex=/usr/local/rocketmq/store1/index
#checkpoint file storage path
storeCheckpoint=/usr/local/rocketmq/store1/checkpoint
#abort file storage path
abortFile=/usr/local/rocketmq/store1/abort
#Message size limit
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker's role
#- ASYNC_MASTER asynchronous replication master
#- SYNC_MASTER synchronous dual write master
#- SLAVE
brokerRole=SLAVE
#Brush disk mode
#- ASYNC_FLUSH asynchronous disc brush
#- SYNC_FLUSH synchronous brush disk
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#Number of message thread pools
#sendMessageThreadPoolNums=128
#Number of pull message thread pools
#pullMessageThreadPoolNums=128

3.master 2
Server: 192.168.239.128

#Cluster name
brokerClusterName=rocketmq-cluster
#broker name. Note that different configuration files are filled in differently
brokerName=broker-b
#0 for Master, > 0 for Slave
brokerId=0
#nameServer address, semicolon split
namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
#When sending messages, topic s that do not exist in the server are automatically created. The number of queues created by default
defaultTopicQueueNums=4
#Whether Broker is allowed to automatically create Topic? It is recommended to open offline and close Online
autoCreateTopicEnable=true
#Whether Broker is allowed to automatically create subscription groups. It is recommended to enable offline and close Online
autoCreateSubscriptionGroup=true
#Broker listening port for external services
listenPort=10911
#Delete file at 4 a.m. by default
deleteWhen=04
#File retention time, default 48 hours
fileReservedTime=120
#commitLog the size of each file is 1G by default
mapedFileSizeCommitLog=1073741824
#Each file of ConsumeQueue saves 30W by default, which is adjusted according to the business situation
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#Detect physical file disk space
diskMaxUsedSpaceRatio=88
#Storage path
storePathRootDir=/usr/local/rocketmq/store
#commitLog storage path
storePathCommitLog=/usr/local/rocketmq/store/commitlog
#Consumption queue storage path storage path
storePathConsumeQueue=/usr/local/rocketmq/store/consumequeue
#Message index storage path
storePathIndex=/usr/local/rocketmq/store/index
#checkpoint file storage path
storeCheckpoint=/usr/local/rocketmq/store/checkpoint
#abort file storage path
abortFile=/usr/local/rocketmq/store/abort
#Message size limit
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker's role
#- ASYNC_MASTER asynchronous replication master
#- SYNC_MASTER synchronous dual write master
#- SLAVE
brokerRole=SYNC_MASTER
#Brush disk mode
#- ASYNC_FLUSH asynchronous disc brush
#- SYNC_FLUSH synchronous brush disk
flushDiskType=SYNC_FLUSH
#checkTransactionMessageEnable=false
#Number of message thread pools
#sendMessageThreadPoolNums=128
#Number of pull message thread pools
#pullMessageThreadPoolNums=128

4.slave1
Server: 192.168.239.128

#Cluster name
brokerClusterName=rocketmq-cluster
#broker name. Note that different configuration files are filled in differently
brokerName=broker-a
#0 for Master, > 0 for Slave
brokerId=1
#nameServer address, semicolon split
namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
#When sending messages, topic s that do not exist in the server are automatically created. The number of queues created by default
defaultTopicQueueNums=4
#Whether Broker is allowed to automatically create Topic? It is recommended to open offline and close Online
autoCreateTopicEnable=true
#Whether Broker is allowed to automatically create subscription groups. It is recommended to enable offline and close Online
autoCreateSubscriptionGroup=true
#Broker listening port for external services
listenPort=11011
#Delete file at 4 a.m. by default
deleteWhen=04
#File retention time, default 48 hours
fileReservedTime=120
#commitLog the size of each file is 1G by default
mapedFileSizeCommitLog=1073741824
#Each file of ConsumeQueue saves 30W by default, which is adjusted according to the business situation
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#Detect physical file disk space
diskMaxUsedSpaceRatio=88
#Storage path
storePathRootDir=/usr/local/rocketmq/store1
#commitLog storage path
storePathCommitLog=/usr/local/rocketmq/store1/commitlog
#Consumption queue storage path storage path
storePathConsumeQueue=/usr/local/rocketmq/store1/consumequeue
#Message index storage path
storePathIndex=/usr/local/rocketmq/store1/index
#checkpoint file storage path
storeCheckpoint=/usr/local/rocketmq/store1/checkpoint
#abort file storage path
abortFile=/usr/local/rocketmq/store1/abort
#Message size limit
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker's role
#- ASYNC_MASTER asynchronous replication master
#- SYNC_MASTER synchronous dual write master
#- SLAVE
brokerRole=SLAVE
#Brush disk mode
#- ASYNC_FLUSH asynchronous disc brush
#- SYNC_FLUSH synchronous brush disk
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#Number of message thread pools
#sendMessageThreadPoolNums=128
#Number of pull message thread pools
#pullMessageThreadPoolNums=128

Modify startup script file

vi /usr/local/rocketmq/bin/runbroker.sh
vim /usr/local/rocketmq/bin/runserver.sh
Modifying jvm parameters

JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

Service start

Start master and slave nodes respectively
master1

nohup sh mqbroker -c /usr/local/rocketmq/rocketmq-all-4.4.0-bin-release/conf/2m-2s-sync/broker-a.properties &

slave2

nohup sh mqbroker -c /usr/local/rocketmq/rocketmq-all-4.4.0-bin-release/conf/2m-2s-sync/broker-b-s.properties &

master2

nohup sh mqbroker -c /usr/local/rocketmq/rocketmq-all-4.4.0-bin-release/conf/2m-2s-sync/broker-b.properties &

slave1

nohup sh mqbroker -c /usr/local/rocketmq/rocketmq-all-4.4.0-bin-release/conf/2m-2s-sync/broker-a-s.properties &

Pit:
When modifying the broker configuration, be sure to note that the primary and secondary nodes not only need to listen to different ports, but also have different paths for message storage. Otherwise, another slave node will fail to start

Posted by vidago on Tue, 16 Jun 2020 23:49:56 -0700