2023年11月29日发(作者:)

RocketMQ安装启动教程(单机版)

本篇博客是单机版的RocketMQ安装教程,能够满⾜基本的学习使⽤,属于⼊门级的教程,如果想要搭集群部署,可以参考其他资料,进⾏

配置即可。

⽂章⽬录

⼀、环境准备

JDK 1.8+

Maven 3.2+

必须在/etc/profile⽂件中配置环境java和maven的环境变量:

JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk

export JAVA_HOME

MAVEN_HOME=/usr/local/maven/apache-maven-3.5.4/

export MAVEN_HOME

export PATH=$PATH:$MAVEN_HOME/bin:$JAVA_HOME/bin

⼆、安装过程

准备RocketMQ解压后的安装包源⽂件:

rocketmq-all-4.7.0-source-release

1. 编译源⽂件

[root@8e597ba7e0c4 ~]# cd rocketmq-all-4.7.0-source-release/

[root@8e597ba7e0c4 rocketmq-all-4.7.0-source-release]# mvn -Prelease-all -DskipTests clean install -U

过程有点长,需要耐⼼等待。

[INFO] ------------------------------------------------------------------------

[INFO] Reactor Summary:

[INFO]

[INFO] Apache RocketMQ 4.7.0 4.7.0 ........................ SUCCESS [28:25 min]

[INFO] rocketmq-logging 4.7.0 ............................. SUCCESS [02:42 min]

[INFO] rocketmq-remoting 4.7.0 ............................ SUCCESS [ 43.422 s]

[INFO] rocketmq-common 4.7.0 .............................. SUCCESS [ 11.482 s]

[INFO] rocketmq-client 4.7.0 .............................. SUCCESS [ 11.573 s]

[INFO] rocketmq-store 4.7.0 ............................... SUCCESS [ 8.456 s]

[INFO] rocketmq-srvutil 4.7.0 ............................. SUCCESS [ 0.430 s]

[INFO] rocketmq-filter 4.7.0 .............................. SUCCESS [ 10.050 s]

[INFO] rocketmq-acl 4.7.0 ................................. SUCCESS [ 4.657 s]

[INFO] rocketmq-broker 4.7.0 .............................. SUCCESS [ 2.780 s]

[INFO] rocketmq-tools 4.7.0 ............................... SUCCESS [ 1.959 s]

[INFO] rocketmq-namesrv 4.7.0 ............................. SUCCESS [ 0.871 s]

[INFO] rocketmq-logappender 4.7.0 ......................... SUCCESS [ 2.929 s]

[INFO] rocketmq-openmessaging 4.7.0 ....................... SUCCESS [ 1.773 s]

[INFO] rocketmq-example 4.7.0 ............................. SUCCESS [ 0.954 s]

[INFO] rocketmq-test 4.7.0 ................................ SUCCESS [ 4.984 s]

[INFO] rocketmq-distribution 4.7.0 4.7.0 .................. SUCCESS [03:10 min]

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 36:15 min

[INFO] Finished at: 2020-07-22T03:11:55Z

[INFO] ------------------------------------------------------------------------

⽬录下的⽂件夹拷贝到⽬录下:

rocketmq-all-4.7.0-source-release/distribution/target/rocketmq-4.7.0rocketmq-4.7.0/usr/local/rocket

[root@8e597ba7e0c4 target]# mkdir /usr/local/rocket

[root@8e597ba7e0c4 rocketmq-4.7.0]# cp -r rocketmq-4.7.0/ /usr/local/rocket/

2. 配置RocketMQ

2.1 配置JVM参数

[root@8e597ba7e0c4 bin]# nohup sh mqnamesrv & tail -f

发现报错信息:

OpenJDK 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.

The Name Server boot success. serializeType=JSON

OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000005c0000000, 8589934592, 0) failed; error='Cannot allocate memory' (errno=12)

#

# There is insufficient memory for the Java Runtime Environment to continue.

# Native memory allocation (mmap) failed to map 8589934592 bytes for committing reserved memory.

# An error report file with more information is saved as:

# /usr/local/rocket/rocketmq-4.7.0/bin/hs_err_

⼤概意思就是你的运⾏内存不⾜,因为默认RocketMQ的JVM内存⽐较⼤,需要配置它的JVM参数。

修改:

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

修改

JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx512m -Xmn128m"

修改

JAVA_OPT="${JAVA_OPT} -server -Xms128m -Xmx256m -Xmn64m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m"

2.2 配置JVMext路径

mandException: ClusterListSubCommand command failed

at e(:93)

at 0(:139)

at (:90)

Caused by: eption: [10015:signature-failed] unable to calculate a request signature. error=[10015:signature-failed

] unable to calculate a request signature. error=Algorithm HmacSHA1 not available

at dBase64Encode(:84)

at nature(:73)

at nature(:68)

at nature(:69)

at reRequest(:44)

at reRpcHooks(:172)

at Sync(:368)

at kerClusterInfo(:1339)

at eBrokerClusterInfo(:306)

at eBrokerClusterInfo(:251)

at lusterBaseInfo(:172)

at e(:88)

... 2 more

Caused by: eption: [10015:signature-failed] unable to calculate a request signature. error=Algorithm HmacSHA1

not available

at (:63)

at dBase64Encode(:79)

... 13 more

Caused by: AlgorithmException: Algorithm HmacSHA1 not available

at tance(:181)

at (:57)

... 14 more

配置的"",添加jvm的ext绝对路径:

/usr/lib/jvm/java-1.8.0-openjdk/jre/lib/ext

JAVA_OPT="${JAVA_OPT} -=${BASE_DIR}/lib:${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext:/usr/lib/jvm/java-1.8.0-openjdk/jre/lib/ext"

再次查看broker列表:

[root@8e597ba7e0c4 bin]# sh mqadmin clusterList -n localhost:9876

RocketMQLog:WARN No appenders could be found for logger (rmDependent0).

RocketMQLog:WARN Please initialize the logger system properly.

#Cluster Name #Broker Name #BID #Addr #Version #InTPS(LOAD) #OutTPS(LOAD) #PCWait(ms) #Hour #SPACE

DefaultCluster broker-a 0 172.17.0.2:10911 V4_7_0 0.00(0,0ms) 0.00(0,0ms) 0 443166.62 -1.0000

三、启动RocketMQ

1. 启动NameServer

[root@8e597ba7e0c4 bin]# nohup sh mqnamesrv & tail -f

2. 启动Broker

[root@8e597ba7e0c4 bin]# nohup sh mqbroker -n localhost:9876 autoCreateTopicEnable=true -c ../conf/

启动完成后观察⽇志情况:

[root@8e597ba7e0c4 bin]# nohup sh mqnamesrv & tail -f

[1] 956

nohup: ignoring input and appending output to ''

# There is insufficient memory for the Java Runtime Environment to continue.

# Native memory allocation (mmap) failed to map 8589934592 bytes for committing reserved memory.

# An error report file with more information is saved as:

# /usr/local/rocket/rocketmq-4.7.0/bin/hs_err_

OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000005c0000000, 8589934592, 0) failed; error='Cannot allocate memory' (errno=12)

#

# There is insufficient memory for the Java Runtime Environment to continue.

# Native memory allocation (mmap) failed to map 8589934592 bytes for committing reserved memory.

# An error report file with more information is saved as:

# /usr/local/rocket/rocketmq-4.7.0/bin/hs_err_

OpenJDK 64-Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release

OpenJDK 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.

The Name Server boot success. serializeType=JSON

The broker[broker-a, 172.17.0.2:10911] boot success. serializeType=JSON and name server is localhost:9876

3. 默认⽇志和信息存储位置

⽬录下,为RocketMQ默认的⽇志和相关信息的存储位置:

/root

drwxr-xr-x. 3 root root 26 Jul 22 04:55 logs

drwxr-xr-x. 3 root root 50 Jul 22 06:48 store

四、测试是否启动成功

1. 查看进程状态

[root@8e597ba7e0c4 ~]# jps

1655 Jps

1464 BrokerStartup

1437 NamesrvStartup

2. 运⾏测试Producer

[root@8e597ba7e0c4 bin]# sh er

05:55:00.234 [main] DEBUG alLoggerFactory - Using SLF4J as the default logging framework

RocketMQLog:WARN No appenders could be found for logger (rmDependent0).

RocketMQLog:WARN Please initialize the logger system properly.

SendResult [sendStatus=SEND_OK, msgId=ACBC7C0546D6A91CF0000, offsetMsgId=6451B45400002A9F000014D8EFB1AB8C, message

Queue=MessageQueue [topic=TopicTest, brokerName=.9, queueId=7], queueOffset=14931]

SendResult [sendStatus=SEND_OK, msgId=ACBC7C0546D6A92120001, offsetMsgId=6451B45300002A9F000004BFEB56232D, messageQ

ueue=MessageQueue [topic=TopicTest, brokerName=taobaodaily-04, queueId=0], queueOffset=1368]

......

3. 运⾏测试Consumer

[root@8e597ba7e0c4 bin]# sh er

05:56:06.485 [main] DEBUG alLoggerFactory - Using SLF4J as the default logging framework

Consumer Started.

ConsumeMessageThread_1 Receive New Messages: [MessageExt [brokerName=taobaodaily-06, queueId=2, storeSize=273, queueOffset=2457, sysFlag

=0, bornTimestamp=76, bornHost=/11.164.198.52:43906, storeTimestamp=33, storeHost=/11.163.33.8:10911, msgId=0BA321

0800002A9F00000AE2141D8F88, commitLogOffset=264, bodyCRC=532471758, reconsumeTimes=0, preparedTransactionOffset=0, toStrin

g()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=2457, TRACE_ON=true, eagleTraceId=0ba4c634766635dda7e, MAX_OF

FSET=2536, MSG_REGION=DefaultRegion, CONSUME_START_TIME=04, UNIQ_KEY=0BA4C634999E2E0FA5D36A825140151A, WAIT=tr

ue, TAGS=TagA, eagleRpcId=9.1}, body=[72, 101, 108, 108, 111, 32, 77, 101, 116, 97, 81, 32, 48], transactionId='null'}]]

......

附:常⽤Rocket MQ命令

#nameServer

启动并查看启动状态

nohup sh mqnamesrv & tail -f

#Broker

启动

nohup sh mqbroker -n localhost:9876 autoCreateTopicEnable=true -c ../conf/

#Topic

创建(修改)

sh mqadmin updateTopic -b localhost:10911 -t testTopic -n localhost:9876

#topic

查询

sh mqadmin topicList -n localhost:9876

#Broker

停⽌

sh mqshutdown broker

#nameServer

停⽌

sh mqshutdown namesrv

查看所有broker列表:

sh mqadmin clusterList -n localhost:9876

查看topic列表:

sh mqadmin topicList -n localhost:9876