Stand alone installation
Front work
Hardware requirements:
- 64 bit Linux/Unix/Mac/Windows
- 4G and above disk space
Software requirements:
- 64 bit JDK above 1.8
- Maven 3.2.x
- Git
Installation:
1. Download the installation package
2. Upload the downloaded package to Linux
It can be uploaded through rz command. For other upload methods, refer to: How to upload files to the server?
3. Decompression
For zip compression, you need to download zip for linux first
unzip xxxx
4. Modify the initial memory
Modify runserver sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m ...... "
Modify runbroker sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"
5. Start
Start NameServer
nohup sh bin/mqnamesrv & tail -f ~/logs/rocketmqlogs/namesrv.log
Start broker
nohup sh bin/mqbroker -n localhost:9876 & tail -f ~/logs/rocketmqlogs/broker.log
6. Send and receive message test
send message
export NAMESRV_ADDR=localhost:9876 sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
receive messages
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
7. Shut down the Server
[root@mqOS rocketmq]# sh bin/mqshutdown broker The mqbroker(1740) is running... Send shutdown request to mqbroker(1740) OK [root@mqOS rocketmq]# sh bin/mqshutdown namesrv The mqnamesrv(1692) is running... Send shutdown request to mqnamesrv(1692) OK [2]+ Exit 143 nohup sh bin/mqbroker -n localhost:9876
Installation and startup of console
RocketMQ has a visual dashboard, through which you can visually view a lot of data
1. Download zip
2. Modify the configuration
Modify application. In src/main/resources Properties configuration file
- The port is changed from 8080 to an uncommon port, such as server port=7000
- Specify the name server address of RocketMQ: RocketMQ config. nameserverAddr=mqOS:9876
3. Add dependency
Unzip POM. In the rocketmq console directory Add the following JAXB dependencies to XML
<dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.3.0</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId> <version>2.3.0</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-core</artifactId> <version>2.3.0</version> </dependency> <dependency> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> <version>1.1.1</version> </dependency>
JAXB: Java Architecture for XML Binding, Java Architecture for XML Binding, a technology that can generate Java classes according to XML templates
4. Packing
mvn clean package -Dmaven.test.skip=true
5. Start
java -jar rocketmq-console-1.0.0.jar
6. Visits
Enter: ip address: port number for access
Note: if it is a local virtual machine, you need to pay attention to whether the machine firewall is turned on, centOS Ubuntu operation
Cluster installation
framework
Build a broker cluster with dual master and dual slave asynchronous replication. For convenience, use two virtual machines to complete the building. The functions and broker roles are assigned as follows:
Serial number | host name | ip | function | role |
---|---|---|---|---|
1 | RocketMQ 1 | 192.168.15.5 | NameServer+Broker | Master1+Slave1 |
2 | RocketMQ 2 | 192.168.15.6 | NameServer+Broker | Master2+Slave2 |
Installation steps
Modify RocketMQ1 configuration file
The file is in conf/2m-2s-async in the RocketMQ decompression directory
Modify broker-a.properties
# Specify the name of the entire broker cluster, or RocketMQ cluster brokerClusterName=DefaultCluster # Specifies the name of the master slave cluster. A RocketMQ cluster can contain multiple master slave clusters brokerName=broker-a # The brokerId of master is 0 brokerId=0 # Specifies that the time to delete the message store expired file is 1 a.m deleteWhen=05 # Specify that the retention time of the message storage file that has not been updated is 24 hours. It will expire after 24 hours and will be deleted fileReservedTime=24 # Specifies that the current broker is asynchronous replication master brokerRole=ASYNC_MASTER # Specifies that the disk brushing strategy is asynchronous disk brushing flushDiskType=ASYNC_FLUSH # Specify the address of the Name Server namesrvAddr=192.168.15.5:9876;192.168.15.6:9876
Modify broker-b.properties
brokerClusterName=DefaultCluster # Specify that this is another master slave cluster brokerName=broker-b # The brokerId of the slave is not 0 brokerId=1 deleteWhen=04 fileReservedTime=24 # Specify the current broker as slave brokerRole=SLAVE flushDiskType=ASYNC_FLUSH namesrvAddr=192.168.15.5:9876;192.168.15.6:9876 # Specify the port on which the Broker communicates with producer and consumer. The default is 10911. # Since the current host acts as both master1 and slave1, and the previous master1 uses the default port, these two ports need to be distinguished to distinguish master1 from slave2 listenPort=11910 # Specifies the path associated with the message store. The default path is ~ / store directory. Since the current host acts as both master1 and slave2, master1 uses the default path. Here, you need to specify a different path storePathRootDir=~/store-s storePathCommitLog=~/store-s/commitlog storePathConsumeQueue=~/store-s/consumequeue storePathIndex=~/store-s/index storeCheckpoint=~/store-s/checkpoint abortFile=~/store-s/abort
Other configurations
#Specify the name of the entire broker cluster, or RocketMQ cluster brokerClusterName=rocket-MS #Specifies the name of the master slave cluster. A RocketMQ cluster can contain multiple master slave clusters brokerName=broker-a #0 means Master, > 0 means Slave brokerId=0 #nameServer address, semicolon split namesrvAddr=nameserver1:9876;nameserver2:9876 #The default is the number of queues created by creating a new Topic defaultTopicQueueNums=4 #Whether to allow the Broker to automatically create a Topic. It is recommended to close it in the production environment autoCreateTopicEnable=true #Whether to allow the Broker to automatically create subscription groups. It is recommended to turn it off in the production environment autoCreateSubscriptionGroup=true #The port on which the Broker provides external services, that is, the port on which the Broker communicates with the producer and the consumer listenPort=10911 #HA highly available listening port, that is, the communication port between Master and Slave. The default value is listenPort+1 haListenPort=10912 #Specifies that the time to delete the message store expired file is 4 a.m deleteWhen=04 #Specify that the retention time of the message storage file that has not been updated is 24 hours. It will expire after 24 hours and will be deleted fileReservedTime=24 #Specify the size of each file in the commitLog directory. The default is 1G mapedFileSizeCommitLog=1073741824 #Specify the number of messages that can be stored in each Queue file of each Topic of ConsumeQueue. The default is 30w messages mapedFileSizeConsumeQueue=300000 #When clearing expired files, If the file is occupied by another thread (the number of references is greater than 0, such as reading messages). At this time, the deletion task will be blocked. At the same time, the current timestamp will be recorded when the first attempt to delete the file is made. This attribute indicates the maximum length of time that the file can be retained since the first rejection of deletion. If the number of references is still not 0 within this time, the deletion will still be rejected. However, when the time expires, the file will be deleted Force delete destroyMapedFileIntervalForcibly=120000 #Specify the maximum utilization rate of the disk partition where commitlog and consumequeue are located. If this value is exceeded, the expired files need to be cleared immediately diskMaxUsedSpaceRatio=88 #Specifies the path to the store directory, which is in the current user's home directory by default storePathRootDir=/usr/local/rocketmq-all-4.5.0/store #commitLog directory path storePathCommitLog=/usr/local/rocketmq-all-4.5.0/store/commitlog #Consumeuue directory path storePathConsumeQueue=/usr/local/rocketmq-all-4.5.0/store/consumequeue #index directory path storePathIndex=/usr/local/rocketmq-all-4.5.0/store/index #checkpoint file path storeCheckpoint=/usr/local/rocketmq-all-4.5.0/store/checkpoint #abort file path abortFile=/usr/local/rocketmq-all-4.5.0/store/abort #Specifies the maximum size of the message maxMessageSize=65536 # Role of Broker # - ASYNC_MASTER asynchronous replication master # - SYNC_MASTER synchronous double write master # - SLAVE brokerRole=SYNC_MASTER #Disk brushing strategy # - ASYNC_FLUSH asynchronous brush disk # - SYNC_FLUSH synchronous brush disc flushDiskType=SYNC_FLUSH #Number of messaging thread pools sendMessageThreadPoolNums=128 #Number of pull message thread pools pullMessageThreadPoolNums=128 #The local IP is mandatory and needs to be modified according to each machine. The official introduction can be blank. The system automatically recognizes it by default, but the IP address may be read incorrectly when there are multiple network cards brokerIP1=192.168.3.105
Clone RocketMQ 2
Clone the rocketmqOS1 host and modify the configuration. The specified host name is rocketmqOS2.
Modify RocketMQ2 configuration file
For the rocketmqOS2 host, you also need to modify the two configuration files in the subdirectory 2m-2s-async of the conf directory of the rocketMQ decompression directory.
Modify broker-b.properties
brokerClusterName=DefaultCluster brokerName=broker-b brokerId=0 deleteWhen=04 fileReservedTime=24 brokerRole=ASYNC_MASTER flushDiskType=ASYNC_FLUSH namesrvAddr=192.168.15.5:9876;192.168.15.6:9876
Modify broker-a-s.properties
brokerClusterName=DefaultCluster brokerName=broker-a brokerId=1 deleteWhen=04 fileReservedTime=24 brokerRole=SLAVE flushDiskType=ASYNC_FLUSH namesrvAddr=192.168.15.5:9876;192.168.15.6:9876 listenPort=11910 storePathRootDir=~/store-s storePathCommitLog=~/store-s/commitlog storePathConsumeQueue=~/store-s/consumequeue storePathIndex=~/store-s/index storeCheckpoint=~/store-s/checkpoint abortFile=~/store-s/abort
Start the server
Start NameServer cluster
Start the NameServer in the rocketmq1 and rocketmq2 hosts respectively. The start command is exactly the same
nohup sh bin/mqnamesrv & tail -f ~/logs/rocketmqlogs/namesrv.log
Start two masters
Start the broker master in rocketmqOS1 and rocketmqOS2 respectively. Note that they specify that the configuration file to load is different.
nohup sh bin/mqbroker -c conf/2m-2s-async/broker-a.properties & tail -f ~/logs/rocketmqlogs/broker.log
nohup sh bin/mqbroker -c conf/2m-2s-async/broker-b.properties & tail -f ~/logs/rocketmqlogs/broker.log
Start two Slave
Start the broker slave in the rocketmq1 and rocketmq2 hosts respectively. Note that they specify that the configuration file to load is different.
nohup sh bin/mqbroker -c conf/2m-2s-async/broker-b-s.properties & tail -f ~/logs/rocketmqlogs/broker.log
nohup sh bin/mqbroker -c conf/2m-2s-async/broker-a-s.properties & tail -f ~/logs/rocketmqlogs/broker.log
mqadmin command
There is an mqadmin command under the bin directory of the mq decompression directory. This command is an operation and maintenance instruction, which is used to manage the topic, cluster, broker and other information of mq.
Modify bin / tools sh
Before running the mqadmin command, first modify bin / tools.exe in the mq decompression directory SH is the EXT directory location of the JDK configured. The EXT directory of this machine is in / usr / Java / jdk1.exe 8.0_ 161/jre/lib/ext
- Use the vim command to open tools SH file, and in JAVA_OPT configured - DJava Add the path of ext after the line ext.dirs.
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn256m - XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m" JAVA_OPT="${JAVA_OPT} - Djava.ext.dirs=${BASE_DIR}/lib:${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ ext:/usr/java/jdk1.8.0_161/jre/lib/ext" JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}" 123
Run mqadmin
Run the command directly, and you can see the commands that can be added. Many functions can be accomplished through these commands
./bin/mqadmin