运行环境
JDK版本:1.8.0_221
rocketmq版本:rocketmqall4.3.2incubatingbinrelease.zip (下载最好用VPN,不然很慢)
下载地址:http://mirrors.tuna.tsinghua.edu.cn/apache/rocketmq/4.3.2/rocketmqall4.3.2binrelease.zip
系统:centos 7
1、rocketmq加入环境变量
执行vim /etc/profile ,插入jdk与rocketmq的环境变量:
1 export JAVA_HOME=/usr/local/jdk
2 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
3 export PATH=$JAVA_HOME/bin:$PATH
#rocketmq目录
5 export ROCKETMQ_HOME=/usr/local/rocketmq/rocketmq‐all‐4.1.0‐incubating
6 export PATH=$ROCKETMQ_HOME/bin:$PATH
2、刷新环境变量:source /etc/profile
3、修改/usr/local/rocketmq/conf/broker.conf(启动时可选择该配置文件)
1 #集群名称,可自定义
2 brokerClusterName=DefaultCluster
3 brokerName=broker‐a
4 brokerId=0
5 //定义服务地址,主存地址
6 namesrvAddr=192.168.241.198:9876
7 deleteWhen=04
8 fileReservedTime=48
9 brokerRole=ASYNC_MASTER
10 flushDiskType=ASYNC_FLUSH
11 autoCreateTopicEnable=true
12 #消息存储根路径
13 storePathRootDir=/data/rocketmq/store
14 #日志路径
15 storePathCommitLog=/data/rocketmq/store/commitlog
4、机器内存不够(一般针对虚拟机),修、改/usr/local/rocketmq/bin/runserver.sh 与/usr/local/rocketmq/bin/runbroker.sh中JAVA_OPT关于内存的设置
1 #!/bin/sh
2
3 # Licensed to the Apache Software Foundation (ASF) under one or more
4 # contributor license agreements. See the NOTICE file distributed with
5 # this work for additional information regarding copyright ownership.
6 # The ASF licenses this file to You under the Apache License, Version 2.0
7 # (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE‐2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implie
d.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 #=======================================================================
====================
19 # Java Environment Setting
20 #=======================================================================
====================
21 error_exit ()
22 {
23 echo "ERROR: $1 !!"
24 exit 1
25 }
26
27 [ ! ‐e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
28 [ ! ‐e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
29 [ ! ‐e "$JAVA_HOME/bin/java" ] && error_exit "Please set the JAVA_HOME v
ariable in your environment, We need java(x64)!"
30
31 export JAVA_HOME
32 export JAVA="$JAVA_HOME/bin/java"
33 export BASE_DIR=$(dirname $0)/..
34 export CLASSPATH=.:${BASE_DIR}/conf:${CLASSPATH}
35
36 #=======================================================================
====================
37 # JVM Configuration
38 #=======================================================================
====================
39 #修改此处的内存大小,默认为4g,一般我们的虚拟机内存不会太大
40 #所以此处修改为256m,可以根据自己机器的配置合理设置
41 JAVA_OPT="${JAVA_OPT} ‐server ‐Xms256m ‐Xmx256m ‐Xmn128m ‐XX:MetaspaceSi
ze=64m ‐XX:MaxMetaspaceSize=128m"
42 JAVA_OPT="${JAVA_OPT} ‐XX:+UseConcMarkSweepGC ‐XX:+UseCMSCompactAtFullCo
llection ‐XX:CMSInitiatingOccupancyFraction=70 ‐XX:+CMSParallelRemarkEnable
d ‐XX:SoftRefLRUPolicyMSPerMB=0 ‐XX:+CMSClassUnloadingEnabled ‐XX:SurvivorR
atio=8 ‐XX:‐UseParNewGC"
43 JAVA_OPT="${JAVA_OPT} ‐verbose:gc ‐Xloggc:/dev/shm/rmq_srv_gc.log ‐XX:+P
rintGCDetails"
44 JAVA_OPT="${JAVA_OPT} ‐XX:‐OmitStackTraceInFastThrow"
45 JAVA_OPT="${JAVA_OPT} ‐XX:‐UseLargePages"
46 JAVA_OPT="${JAVA_OPT} ‐Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DI
R}/lib"
47 #JAVA_OPT="${JAVA_OPT} ‐Xdebug ‐Xrunjdwp:transport=dt_socket,address=955
5,server=y,suspend=n"
48 JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
49 JAVA_OPT="${JAVA_OPT} ‐cp ${CLASSPATH}"
50
51 $JAVA ${JAVA_OPT} $@
执行命令:vim runbroker.sh
6、假设我们的IP是:192.168.241.198,修改配置文件broker.conf,加上:
brokerIP1=192.168.241.198
7,运行服务namesrv(需在$ROCKETMQ_HOME/bin下执行)
执行命令:nohup sh bin/mqnamesrv ‐n 192.168.241.198:9876 &
8、启动broker(需在$ROCKETMQ_HOME/bin下执行)
8.1不指定启动配置文件
nohup sh bin/mqbroker ‐n 192.168.241.198:9876 autoCreateTopicEnable=true &
8.2指定启动配置配置文件
执行命令:
nohup sh bin/mqbroker ‐n 192.168.241.198:9876 ‐c conf/broker.conf autoCre
ateTopicEnable=true &
查看broker启动配置:
sh bin/mqbroker ‐m
(127.0.0.1:9876为nameserver,autoCreateTopicEnable=true(允许创建topic)😉
9、关闭防火墙
客户端访问可能会出现的问题:
RemotingTooMuchRequestException: sendDefaultImpl call timeout在客户端运行Producer时,可能会出现如上异常,这是因为从 Windows 上开发连接虚拟机中的 nameServer 时要经过 Linux 系统的防火墙,而防火墙一般都会超时的机制,在网络连接长时间不传输数据时,会关闭这个 TCP 的会话,关闭后再读写,就有可能导致这个异常。
contOS下命令如下:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
#查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
firewall‐cmd ‐‐state
broker.conf配置如下:
1 #rocketmq‐name服务地址,多个地址用;分开,不配置默认为localhost:9876
2 namesrvAddr = 192.168.241.198:9876
3 brokerClusterName = DefaultCluster
4 brokerName = broker‐a
5 brokerId = 0
6 deleteWhen = 04
7 fileReservedTime = 48
8 #主从角色SYNC_MASTER,ASYNC_MASTER,SLAVE
9 brokerRole = SYNC_MASTER
10 flushDiskType = ASYNC_FLUSH
11 #允许自动创建主题topic
12 autoCreateTopicEnable=true
13 #broker监听端口
14 listenPort=10911
15 #数据存储位置
16 storePathRootDir=/root/rocketmq/store
10、关闭命令
#方案一‐正常退出
2 sh mqshutdown broker ‐‐关闭broker
3 sh mqshutdown namesrv ‐‐关闭namesrv
4
5 #方案二‐杀掉进程
6 ps ‐ef|grep rocketmq 查看pid(进程号)
7 kill ‐9 pid(进程号)