Technical work, should be rewarded with praise, to form a good habitCopy the code
RocketMQ use tutorial related series of directories
Section 1: Server preparation
The cluster is set up in the mode of synchronous replication and asynchronous disk flushing.
Install four VMS as follows:
IP | hostname | mastername |
---|---|---|
192.168.88.135 | rocketmq-nameserver4 | rocketmq-master2-salave1 |
192.168.88.134 | rocketmq-nameserver3 | rocketmq-master2 |
192.168.88.133 | rocketmq-nameserver2 | rocketmq-master1-slave1 |
192.168.88.131 | rocketmq-nameserver1 | rocketmq-master1 |
Install virtual machine portal –>
Section two: Install RocketMQ
Install RocketMQ on each machine, which will not be repeated here
Chapter 1: RocketMQ Installation –> Portal
Just to restate the point
Create the RocketMQ storage directory
The existing directory structure looks like this
Creating a Storage Directory
mkdir logs
mkdir store
cd store
mkdir commitlog
mkdir consumequeue
mkdir index
Copy the code
Changing a Log Path
Go to the conf directory and replace ${user.home} in all XML files to ensure that the log path is correct
Grammar:
Sed -i batch replacement
Sed -i 'new string original string s # # # g' replacement file sed -i 's # # ${user. Home} / usr/local/server/mq/rocketmq# g' *. XMLCopy the code
The replacement succeeded
Modify runbroker. Sh
Adjust the memory size (for demonstration purposes only, the actual memory size depends on the production environment)
cd ..
cd bin/
vim runbroker.sh
Copy the code
Adjust to 1 g
Modify the runserver then executes. Sh
Adjust the memory size (for demonstration purposes only, the actual memory size depends on the production environment)
vim runserver.sh
Copy the code
Section 3: Configuration
Configure hosts
Configure the mapping between addresses and IP addresses in the host file
Modify the /etc/hosts file of each host to add the following mapping
vim /etc/hosts
Copy the code
192.168.88.131 Rocketmq-nameserver1 192.168.88.131 RocketMq-master1 192.168.88.133 RocketMq-Nameserver2 192.168.88.133 Rocketmq-master1-slave1 192.168.88.134 Rocketmq-nameserver3 192.168.88.134 RocketMq-master2 192.168.88.135 Rocketmq - nameserver4 192.168.88.135 rocketmq master2 -- slave1Copy the code
After the configuration is complete, restart the NIC
systemctl restart network
Copy the code
Rocketmq environment variable configuration
vim /etc/profile
Copy the code
Add the following command at the end of the profile file
#set rocketmq
ROCKETMQ_HOME=/usr/local/server/mq/rocketmq/
PATH=$PATH:$ROCKETMQ_HOME/bin
export ROCKETMQ_HOME PATH
Copy the code
Input: wq! Save and exit to make the configuration take effect immediately:
source /etc/profile
Copy the code
The JDK installation
Centos installation open-jdk8–> portal
A master-slave configuration
Host: 192.168.88.131
cd /usr/local/server/mq/rocketmq/conf
cd 2m-2s-sync/
vim broker-a.properties
Copy the code
BrokerName =broker- A #0 = Master >0 = Slave brokerId=0 #nameServer address, semicolon split namesrvAddr= RocketMQ-Nameserver1:9876; rocketmq-nameserver2:9876; rocketmq-nameserver3:9876; Rocketmq-nameserver4:9876 # Create a topic that does not exist on the server. DefaultTopicQueueNums =4 # Allow the Broker to automatically create subscription groups. Online closed autoCreateSubscriptionGroup = true # Broker foreign service listening on port brokerIP1 = 192.168.88.131 brokerIP2 = 192.168.88.131 ListenPort =10911 # deleteWhen=04 # file retention time, MapedFileSizeCommitLog =1073741824 #ConsumeQueue by default, 30W files are stored in each file. Adjust according to the business situation mapedFileSizeConsumeQueue = 120000 # 300000 # destroyMapedFileIntervalForcibly = redeleteHangedFileInterval = 120000 # test physical file disk space checkTransactionMessageEnable diskMaxUsedSpaceRatio = 88 # storage paths StorePathRootDir = / usr/local/server/mq/rocketmq/store # commitLog storage paths StorePathCommitLog = / usr/local/server/mq queue storage/rocketmq/store/commitlog # consumption path storage paths StorePathConsumeQueue = / usr/local/server/mq/rocketmq/store/consumequeue # message index storage paths StorePathIndex = / usr/local/server/mq/rocketmq/store/index # checkpoint file storage path StoreCheckpoint = / usr/local/server/mq/rocketmq/store/checkpoint # abort file storage path AbortFile = / usr/local/server/mq/rocketmq/store / # abort message limit maxMessageSize = 65536 # flushCommitLogLeastPages = 4 #flushConsumeQueueLeastPages=2 #flushCommitLogThoroughInterval=10000 #flushConsumeQueueThoroughInterval=60000 #Broker Role #- ASYNC_MASTER Asynchronous copy Master #- SYNC_MASTER Synchronous double write Master #- SLAVE brokerRole=SYNC_MASTER # Flush Asynchronous flush #- SYNC_FLUSH synchronous brush plate flushDiskType = # ASYNC_FLUSH checkTransactionMessageEnable = false number # # message thread pool sendMessageThreadPoolNums = 128 # message thread pool number # pullMessageThreadPoolNums = 128 # default the value is false, said the custom Broker not bearing system is used for storing news track topic traceTopicEnable = falseCopy the code
Key configuration:
BrokerName =broker- A #0 for Master, >0 for Slave brokerId=0 #nameServer address Semicolon split namesrvAddr= Rocketmq-Nameserver1:9876; rocketmq-nameserver2:9876; rocketmq-nameserver3:9876; Rocketmq-nameserver4:9876 # Role of Broker #- ASYNC_MASTER Asynchronous replication Master #- SYNC_MASTER Synchronous double write Master #- SLAVE BrokerRole =SYNC_MASTER # Flush Mode # -asynC_Flush Flush flushDiskType=ASYNC_FLUSHCopy the code
Remove the broker – a – supachai panitchpakdi roperties
rm -rf broker-a-s.properties
Copy the code
Copy broker-a.properties to broker-a-s.properties and modify
cp broker-a.properties ./broker-a-s.properties
vim broker-a-s.properties
Copy the code
Key configuration modifications:
BrokerName =broker- A #0 for Master, >0 for Slave brokerId=1 #nameServer address Semicolon split namesrvAddr= Rocketmq-Nameserver1:9876; rocketmq-nameserver2:9876; rocketmq-nameserver3:9876; Rocketmq-nameserver 4:9876 #Broker role #- ASYNC_MASTER Asynchronous replication Master #- SYNC_MASTER Synchronous double write Master #- SLAVE brokerRole=SLAVE -sync_flush flushDiskType=ASYNC_FLUSHCopy the code
Remove broker-b. perties and copy broker-a. perties to broker-B. perties
rm -rf broker-b.properties
cp broker-a.properties ./broker-b.properties
vim broker-b.properties
Copy the code
Key configuration modifications:
BrokerName =broker- B #0 for Master, >0 for Slave brokerId=0 #nameServer address Semicolon split namesrvAddr= Rocketmq-Nameserver1:9876; rocketmq-nameserver2:9876; rocketmq-nameserver3:9876; Rocketmq-nameserver4:9876 # Role of Broker #- ASYNC_MASTER Asynchronous replication Master #- SYNC_MASTER Synchronous double write Master #- SLAVE BrokerRole =SYNC_MASTER # Flush Mode # -asynC_Flush Flush flushDiskType=ASYNC_FLUSHCopy the code
Remove broker-b-s.perties and copy broker-a-s.perties to broker-b-s.perties
rm -rf broker-b-s.properties
cp broker-a-s.properties ./broker-b-s.properties
vim broker-b-s.properties
Copy the code
Key configuration modifications:
BrokerName =broker- B #0 for Master, >0 for Slave brokerId=1 #nameServer address Semicolon split namesrvAddr= Rocketmq-Nameserver1:9876; rocketmq-nameserver2:9876; rocketmq-nameserver3:9876; Rocketmq-nameserver 4:9876 #Broker role #- ASYNC_MASTER Asynchronous replication Master #- SYNC_MASTER Synchronous double write Master #- SLAVE brokerRole=SLAVE -sync_flush flushDiskType=ASYNC_FLUSHCopy the code
Synchronize configurations to multiple servers
Obtaining a Synchronization Path
Host 192.168.88.131 into/usr/local/server/mq/rocketmq/conf / 2 m – 2 s – sync directory
SCP *. The properties 192.168.88.133: / usr/local/server/mq/rocketmq/conf / 2 m - 2 s - syncCopy the code
Similar practices were replicated on several other servers
Section four: Startup
Start namesRV of master and slave hosts
nohup sh mqnamesrv > /dev/null 2>&1 &
Copy the code
Start the broker
Different servers launch different broker files
Main 1, start the broker
nohup sh mqbroker -c /usr/local/server/mq/rocketmq/conf/2m-2s-sync/broker-a.properties > /dev/null 2>&1 &
Copy the code
From 1, start the broker
nohup sh mqbroker -c /usr/local/server/mq/rocketmq/conf/2m-2s-sync/broker-a-s.properties > /dev/null 2>&1 &
Copy the code
Master 2, start the broker
nohup sh mqbroker -c /usr/local/server/mq/rocketmq/conf/2m-2s-sync/broker-b.properties > /dev/null 2>&1 &
Copy the code
From 2, start the broker
nohup sh mqbroker -c /usr/local/server/mq/rocketmq/conf/2m-2s-sync/broker-b-s.properties > /dev/null 2>&1 &
Copy the code
Section 5: Verify whether the primary and secondary are enabled
Start the
Check whether docker container Rocketmq-console-ng exists in advance. If so, delete it first
For those of you who are not familiar with Docker, portal -> Docker is used to manipulate container commands
Docker run - e "JAVA_OPTS = - Drocketmq. Namesrv. Addr = 192.168.88.131:9876; 192.168.88.133:9876; 192.168.88.134:9876; 192.168.88.135:9876 - Dcom. Rocketmq. SendMessageWithVIPChannel = false "-p 8080-8080 - t - name rocketmq - the console - ng styletang/rocketmq-console-ngCopy the code
As shown in the figure, the two-node cluster has been set up successfully.