Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy distributed message system RocketMQ under Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to deploy distributed messaging system RocketMQ under Linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to deploy the distributed messaging system RocketMQ under Linux.

I. download the required documents for this article

Link: https://pan.baidu.com/s/17iUB1lBOjv4CBAEQFvn65A extraction code: v0sn

1. Build the Linux environment. 1. Install the jdk environment

RocketMQ java writing, requires a jdk environment

Download jdk 1.7.080to upload to linux, must be 64-bit, 32-bit RocketMQ does not support

Tar-zxvf jdk-7u80-linux-x64.tar.gz / / decompress

Modify the environment variable vim / etc/profile

Export JAVA_HOME=/usr/local/jdk1.7.0_80export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexport PATH=$JAVA_HOME/bin:$PATH

Refresh configuration

Source / etc/profile

Or jdk1.8 download installation tutorial: https://blog.csdn.net/qq_41463655/article/details/99173682

2. Install RocketMQ

Upload alibaba-rocketmq-3.2.6.tar.gz to linux for decompression and installation

Tar-zxvf alibaba-rocketmq-3.2.6.tar.gz-C / usr/local/ / extract to / usr/localmv / usr/local/alibaba-rocketmq / usr/local/alibaba-rocketmq-3.2.6 / / rename ln-s / usr/local/alibaba-rocketmq-3.2.6 rocketmq / / install

It's installed.

2.2. Create a storage path

Cd / usr/local/rocketmqmkdir storemkdir store/commitlogmkdir store/consumequeuemkdir store/index

2.3. Log configuration

Cd / usr/local/rocketmqmkdir logs cd conf & & sed-I's xml ${user.home} # / usr/local/rocketmq#g' *. Xml

2.4.Configuring broker-a.properties / broker-b.properties / usr/local/rocketmq/conf/2m-noslave/ directory

2.4.1 、 broker-a.properties

# brokerClusterName=rocketmq-cluster#broker name of the cluster to which it belongs. Note that different brokerName=broker-an is entered in different configuration files here | broker-b#0 indicates Master, > 0 indicates SlavebrokerId=0#nameServer address, and semicolon is divided into namesrvAddr=rocketmq-nameserver1:9876. When rocketmq-nameserver2:9876# sends messages, it automatically creates topic for which the server does not exist. Whether the number of queues created by default defaultTopicQueueNums=4# allows Broker to automatically create Topic, it is recommended that offline enable, online shutdown autoCreateTopicEnable=true# allows Broker to automatically create subscription groups, recommended offline enable, online shut down autoCreateSubscriptionGroup=true#Broker external service listening port listenPort=10911# delete file point, default 4: 00 am deleteWhen=04# file retention time Default 48-hour fileReservedTime=120#commitLog size per file default 1GmapedFileSizeCommitLog=1073741824#ConsumeQueue 30W per file by default Adjust mapedFileSizeConsumeQueue=300000#destroyMapedFileIntervalForcibly=120000#redeleteHangedFileInterval=120000# detection 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 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# limited message size maxMessageSize=65536#flushCommitLogLeastPages=4#flushConsumeQueueLeastPages=2#flushCommitLogThoroughInterval=10000#flushConsumeQueueThoroughInterval=60000#Broker role #-ASYNC_MASTER asynchronous replication Master#- SYNC_MASTER synchronous double write Master#- SLAVEbrokerRole=ASYNC_MASTER# flush mode #-ASYNC_FLUSH asynchronous flush disk #-SYNC_FLUSH synchronous flush flushDiskType=ASYNC_FLUSH#checkTransactionMessageEnable=false# number of sending thread pool # sendMessageThreadPoolNums=128# pull message thread pool # pullMessageThreadPoolNums=128

2.4.2 、 broker-b.properties

# brokerClusterName=rocketmq-cluster#broker name of the cluster to which it belongs. Note that different brokerName=broker-an is entered in different configuration files here | broker-b#0 indicates Master, > 0 indicates SlavebrokerId=0#nameServer address, and semicolon is divided into namesrvAddr=rocketmq-nameserver1:9876. When rocketmq-nameserver2:9876# sends messages, it automatically creates topic for which the server does not exist. Whether the number of queues created by default defaultTopicQueueNums=4# allows Broker to automatically create Topic, it is recommended that offline enable, online shutdown autoCreateTopicEnable=true# allows Broker to automatically create subscription groups, recommended offline enable, online shut down autoCreateSubscriptionGroup=true#Broker external service listening port listenPort=10911# delete file point, default 4: 00 am deleteWhen=04# file retention time Default 48-hour fileReservedTime=120#commitLog size per file default 1GmapedFileSizeCommitLog=1073741824#ConsumeQueue 30W per file by default Adjust mapedFileSizeConsumeQueue=300000#destroyMapedFileIntervalForcibly=120000#redeleteHangedFileInterval=120000# detection 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 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# limited message size maxMessageSize=65536#flushCommitLogLeastPages=4#flushConsumeQueueLeastPages=2#flushCommitLogThoroughInterval=10000#flushConsumeQueueThoroughInterval=60000#Broker role #-ASYNC_MASTER asynchronous replication Master#- SYNC_MASTER synchronous double write Master#- SLAVEbrokerRole=ASYNC_MASTER# flush mode #-ASYNC_FLUSH asynchronous flush disk #-SYNC_FLUSH synchronous flush flushDiskType=ASYNC_FLUSH#checkTransactionMessageEnable=false# number of sending thread pool # sendMessageThreadPoolNums=128# pull message thread pool # pullMessageThreadPoolNums=128

Two configuration files need to be modified

BrokerName=broker-a | broker-b cluster a server configuration modified to brokerName=broker-abrokerName=broker-a | broker-b cluster b server configuration modified to brokerName=broker-b

2.5. Modify startup parameters / rocketm/bin (jvm)

Runbroker.sh 's JAVA_OPT runserver.sh 's JAVA_OPT.

Modify JAVA_OPT= "${JAVA_OPT}-server-Xms4g-Xmx4g-Xmn2g-XX:PermSize=128m-XX:MaxPermSize=320m" to JAVA_OPT= "${JAVA_OPT}-server-Xms1g-Xmx1g-Xmn512m-XX:PermSize=128m-XX:MaxPermSize=320m"

2.6.Boot NameServer installation directory / usr/local/ / rocketmq/bin directory

Nohup sh mqnamesrv &

2.7.Boot the BrokerServer / rocketmq/bin directory

Nohup sh mqbroker-c / usr/local/rocketmq/conf/2m-noslave/broker-a.properties > / dev/null 2 > & 1 & netstat-ntlp

View startup status

Jps

The result is as follows: the startup was successful

3. Modify linux server host

Native ip, configure domain name

192.168.177.128 rocketmq-nameserver1192.168.177.128 rocketmq-master1192.168.111.129 rocketmq-nameserver2192.168.111.129 rocketmq-master2

Picture

4. Install the background management platform

Extract and install tomcat 7.0to / usr/local/

Tar-zxvf apache-tomcat-7.0.65.tar.gz-C / usr/local

Copy rocketmq-web-console.war to the webapps directory of apache-tomcat-7.0.65 to start tomcat automatic decompression, and then modify the config.properties configuration of config / rocketmq-web-console/WEB-INF/classes and modify ip

Single server rocketmq.namesrv.addr=192.168.177.128:9876 multi server rocketmq.namesrv.addr=192.168.177.128:9876;192.168.177.129:9876

Shut down tomcat / restart tomcat

Turn off the firewall

Systemctl disable firewalld or chkconfig iptables off

Visit-"ok when ip:8080/rocketmq-web-console appears below the interface."

Java operation 1, producer import com.alibaba.rocketmq.client.exception.MQClientException;import com.alibaba.rocketmq.client.producer.DefaultMQProducer;import com.alibaba.rocketmq.client.producer.SendResult;import com.alibaba.rocketmq.common.message.Message;public class Producer {public static void main (String [] args) throws MQClientException {DefaultMQProducer producer = new DefaultMQProducer ("rmq-group"); producer.setNamesrvAddr ("192.168.177.128 String 9876") Producer.setInstanceName ("producer"); producer.start (); try {for (int I = 0; I "test-topic", "TagA", ("test-topic-" + I) .getBytes ()); SendResult sendResult = producer.send (msg) System.out.println (sendResult.toString ());}} catch (Exception e) {e.printStackTrace ();} producer.shutdown ();}} 2, consumer import com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer;import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;import com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently Import com.alibaba.rocketmq.client.exception.MQClientException;import com.alibaba.rocketmq.common.message.MessageExt;import java.util.List;public class Consumer {public static void main (String [] args) throws MQClientException {DefaultMQPushConsumer consumer = new DefaultMQPushConsumer ("rmq-group"); consumer.setNamesrvAddr ("192.168.177.128 consumer.subscribe 9876"); consumer.setInstanceName ("consumer"); consumer.subscribe ("test-topic", "TagA") Consumer.registerMessageListener (new MessageListenerConcurrently () {@ Override public ConsumeConcurrentlyStatus consumeMessage (List msgs, ConsumeConcurrentlyContext context) {for (MessageExt msg: msgs) {System.out.println (msg.getMsgId () + "- -" + new String (msg.getBody ();} / / return successful consumption status return ConsumeConcurrentlyStatus.CONSUME_SUCCESS }}); consumer.start (); System.out.println ("Consumer Started.");}}

Idempotent problems will occur. Use global id, or timestamp, or the unique id of the business to judge whether it exists. Log records such as redis are used to determine whether it exists. The presence indicates that it has been consumed successfully.

At this point, I believe you have a deeper understanding of "how to deploy distributed messaging system RocketMQ under Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report