RocketMQ cluster configuration

The default port numbers of RocketMQ are as follows:

  1. Namesrv:9876
  2. Broker:10911

Note that these are default ports, you can change these ports in RocketMQ configuration file. Also, if you run multiple broker instances or namesrv instances, each instance needs to use a different port.

Two Namesrv instances, and two pairs of Broker instance master and backup, how to configure?
In this case, you can create a configuration file for each Broker instance separately, and specify the corresponding Namesrv address, Broker name, and role (Master or Slave) in each file.

The following are the specific steps:

1. Namesrv instance

Namesrv does not have a specific configuration file, all configuration is specified in the startup command. If you want to run multiple instances of Namesrv, you just need to specify a different port number for each instance. For example:

nohup sh mqnamesrv -n localhost:9876 > namesrv1.log 2>&1 &
nohup sh mqnamesrv -n localhost:9877 > namesrv2.log 2>&1 &

In this example, we started two Namesrv instances listening on ports 9876 and 9877 respectively.

2. Broker instance

confFor Broker instances, you can create 4 new configuration files in the RocketMQ directory, for example:

  • broker-a-master.properties
  • broker-a-slave.properties
  • broker-b-master.properties
  • broker-b-slave.properties

Then add the corresponding content in each configuration file.

For example, in broker-a-master.properties:

brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
autoCreateTopicEnable=true
namesrvAddr=localhost:9876;localhost:9877

In broker-a-slave.properties:

brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
autoCreateTopicEnable=true
namesrvAddr=localhost:9876;localhost:9877

Similarly, you also need to configure corresponding master and slave configurations for broker-b.

Then, you can start the 4 Broker instances separately with the following commands:

nohup sh mqbroker -c ../conf/broker-a-master.properties > broker-a-master.log 2>&1 &
nohup sh mqbroker -c ../conf/broker-a-slave.properties > broker-a-slave.log 2>&1 &
nohup sh mqbroker -c ../conf/broker-b-master.properties > broker-b-master.log 2>&1 &
nohup sh mqbroker -c ../conf/broker-b-slave.properties > broker-b-slave.log 2>&1 &

Note that each Broker instance requires a separate configuration file and brokerNameshould brokerIdbe unique. In each pair of Master and Slave, brokerNameit should be the same, while brokerIdit should be 0 in Master and 1 in Slave.

The above commands assume you are running in the RocketMQ bin directory. If you are running from another location, you may need to modify the path in the command.

In addition, if you want to run these commands in the background, you can use nohupthe command and redirect the output to a log file, as in the above command, namesrv1.log, namesrv2.log, broker-a-master.log`broker-a-slave

On a Linux system, you can use psthe command to view the running RocketMQ Namesrv and Broker instances. Here's how to use this command:

  1. Open a command line window.

  2. Enter the following command to view the running Namesrv instance:

ps -ef | grep mqnamesrv

If the Namesrv instance is running, you will see output similar to the following:

root     12345     1  0 Jun21 ?        00:00:00 sh mqnamesrv
  1. Enter the following command to view the running Broker instance:
ps -ef | grep mqbroker

If the Broker instance is running, you will see output similar to:

root     23456     1  0 Jun21 ?        00:00:00 sh mqbroker -c ../conf/2m-noslave.properties

In the output of these commands, you can see the commands that started Namesrv and Broker, and the associated process IDs.

For your specific case, you need to see two Namesrv instances and four Broker instances (a pair of master-slave per Broker).

Note that you may need to adjust these commands based on your actual Namesrv and Broker configuration. For example, if you use a different configuration file or command option, then you need to grepspecify the corresponding text in the command.

Guess you like

Origin blog.csdn.net/u011197085/article/details/131546629