rocketmq搭建精简版

rocketmq搭建精简版

十二月 19, 2019

德国地区是三台主机组成的集群,分配情况为三个nameserver三个broker无slave

所有主机都要配置:

  1. 配置hosts主机名
  2. 配置java环境
  3. 部署rocketmq
  4. 部署rocketmq_console(部署一台有外网IP的服务器即可)

[rocketmq]
172.17.4.20 rocketmq-nameserver1 rocketmq-master1
172.17.4.21 rocketmq-nameserver2 rocketmq-master2
172.17.4.22 rocketmq-nameserver3 rocketmq-master3

jdk-8u181-linux-x64.tar.gz
rocketmq-all-4.5.2-bin-release.tar.gz
rocketmq-console-ng-1.0.1.jar

配置java环境:

1
2
3
4
5
6
7
8
mkdir  /usr/lib/jvm/
tar -xzvf jdk-8u181-linux-x64.tar.gz -C /usr/lib/jvm/
echo "export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_181">>/etc/profile
echo 'export JRE_HOME=${JAVA_HOME}/jre'>>/etc/profile
echo 'export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib'>>/etc/profile
echo 'export PATH=${JAVA_HOME}/bin:$PATH'>>/etc/profile
source /etc/profile
java -version

部署rocketmq:

1
2
3
4
mkdir -p /data/rocketmq/store
cd rocketmq/store/
mkdir commitlog config consumequeue index
touch abort checkpoint lock

解压rocketmq并修改配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# cat /usr/local/rocketmq-all-4.5.2-bin-release/conf/2m-noslave/broker-a.properties
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
brokerClusterName=rocketmq-Cluster
brokerName=broker-a
brokerId=0
namesrvAddr=172.17.4.20:9876;172.17.4.21:9876;172.17.4.22:9876
defaultTopicQueueNums=6
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10911
deleteWhen=04
fileReservedTime=24
storePathRootDir=/data/rocketmq/store
storePathCommitLog=/data/rocketmq/store/commitlog
storePathConsumeQueue=/data/rocketmq/store/consumequeue
storePathIndex=/data/rocketmq/store/index
storeCheckpoint=/data/rocketmq/store/checkpoint
abortFile=/data/rocketmq/store/abort
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
maxTransferCountOnMessageInMemory=400
#发送消息的最大线程数
sendMessageThreadPoolNums=32
#large thread numbers
#发送消息是否使用可重入锁
useReentrantLockWhenPutMessage=true
waitTimeMillsInSendQueue=1000
transientStorePoolEnable=true
transientStorePoolSize=5

根据实例配置调整内存:

1
2
vim /usr/local/rocketmq-all-4.5.2-bin-release/bin/runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g"

启动服务顺序:
先启动nameserver再启动broker,停止服务时顺序也一样

启动nameserver:

1
2
# cat /home/david/start_mqnamesrv.sh
nohup sh /usr/local/rocketmq-all-4.5.2-bin-release/bin/mqnamesrv > /dev/null 2>&1 &

启动broker:

1
2
# cat /home/david/start_mqbroker.sh
nohup sh /usr/local/rocketmq-all-4.5.2-bin-release/bin/mqbroker -c /usr/local/rocketmq-all-4.5.2-bin-release/conf/2m-noslave/broker-a.properties > /dev/null 2>&1 &

检查集群状态:

1
2
3
4
5
6
7
8
[root@rocketmq-nameserver1 ~]# cd /usr/local/rocketmq-all-4.5.2-bin-release/bin/
[root@rocketmq-nameserver1 bin]# ./mqadmin clusterList --namesrvAddr=172.17.4.20:9876
RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.PlatformDependent0).
RocketMQLog:WARN Please initialize the logger system properly.
#Cluster Name #Broker Name #BID #Addr #Version #InTPS(LOAD) #OutTPS(LOAD) #PCWait(ms) #Hour #SPACE
rocketmq-cluster broker-b 0 172.17.4.21:10911 V4_5_2 0.00(0,0ms) 0.00(0,0ms) 0 438169.53 0.0003
rocketmq-cluster broker-c 0 172.17.4.22:10911 V4_5_2 0.00(0,0ms) 0.00(0,0ms) 0 438169.53 0.0003
rocketmq-Cluster broker-a 0 172.17.4.20:10911 V4_5_2 0.00(0,0ms) 0.00(0,0ms) 0 438169.53 0.0003

启动rocketmq_console:
console启动时只能识别第一个IP,所以开发打包时写死了集群IP

1
java -jar /opt/rocketmq-console/rocketmq-console-ng-1.0.1.jar --server.port=12581