about
rocketmq下载
哪个能访问,你用哪个:
- 下载方式1:https://rocketmq.apache.org/zh/release-notes/
- 方式2:https://rocketmq.apache.org/download/
- 所有的版本都可以从这里下载:https://archive.apache.org/dist/rocketmq/
rocketmq5.1.0 for centos7
配置Java环境变量和Maven
参考:
安装rocketmq5
1. 下载安装包
我是从这个地址下载的:https://archive.apache.org/dist/rocketmq/5.1.0/
cd /opt
wget https://archive.apache.org/dist/rocketmq/5.1.0/rocketmq-all-5.1.0-bin-release.zip
ls rocket*
[root@cs opt]# cd /opt
[root@cs opt]# wget https://archive.apache.org/dist/rocketmq/5.1.4/rocketmq-all-5.1.4-bin-release.zip
[root@cs opt]# ls rocket*
rocketmq-all-5.1.0-bin-release.zip
2
3
4
5
6
7
8
2. 解压并添加环境变量
# 解压
cd /opt
unzip rocketmq-all-5.1.0-bin-release.zip
ll
# 添加环境变量
echo "export ROCKETMQ_HOME=/opt/rocketmq-all-5.1.0-bin-release" >> /etc/profile
echo "export PATH=\$PATH:\$ROCKETMQ_HOME/bin" >> /etc/profile
echo "export NAMESRV_ADDR='worker1:9876;worker2:9876;worker3:9876'" >> /etc/profile
cat /etc/profile
source /etc/profile
2
3
4
5
6
7
8
9
10
11
nameserver服务搭建
启动NameServer非常简单在$ROCKETMQ_HOME/bin
目录下有个mqnamesrv
脚本,直接执行这个脚本就可以启动RocketMQ的NameServer服务。由于RocketMQ默认预设的JVM内存是4G,这是RocketMQ给我们的最佳配置。你如果机器性能足够,可以不跟着本小节进行修改了。
我这边用的是虚拟机,所以需要调整下JVM内存大小。修改的方式是直接修改$ROCKETMQ_HOME/bin
目录下的runserver.sh
脚本。
修改runserver.sh
脚本
为了防止出现意外,我们应该把原始文件备份一下:
cd /opt
cp /opt/rocketmq-all-5.1.0-bin-release/bin/runserver.sh /opt/rocketmq-all-5.1.0-bin-release/bin/runserver.sh.bak
2
现在开始修改:
# 执行命令
cd /opt
vim /opt/rocketmq-all-5.1.0-bin-release/bin/runserver.sh
# 具体修改位置
choose_gc_options()
{
# Example of JAVA_MAJOR_VERSION value : '1', '9', '10', '11', ...
# '1' means releases befor Java 9
JAVA_MAJOR_VERSION=$("$JAVA" -version 2>&1 | awk -F '"' '/version/ {print $2}' | awk -F '.' '{print $1}')
if [ -z "$JAVA_MAJOR_VERSION" ] || [ "$JAVA_MAJOR_VERSION" -lt "9" ] ; then
# JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m" # 修改前
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m" # 修改后
JAVA_OPT="${JAVA_OPT} -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 -XX:-UseParNewGC"
JAVA_OPT="${JAVA_OPT} -verbose:gc -Xloggc:${GC_LOG_DIR}/rmq_srv_gc_%p_%t.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps"
JAVA_OPT="${JAVA_OPT} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m"
else
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
JAVA_OPT="${JAVA_OPT} -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -XX:SoftRefLRUPolicyMSPerMB=0"
JAVA_OPT="${JAVA_OPT} -Xlog:gc*:file=${GC_LOG_DIR}/rmq_srv_gc_%p_%t.log:time,tags:filecount=5,filesize=30M"
fi
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
启动nameserver服务
cd /opt
nohup sh /opt/rocketmq-all-5.1.0-bin-release/bin/mqnamesrv &
[root@cs opt]# nohup /opt/rocketmq-all-5.1.0-bin-release/bin/mqnamesrv &
[1] 1836
[root@cs opt]# nohup: ignoring input and appending output to ‘nohup.out’
[root@cs opt]#
[root@cs opt]# cat nohup.out
[root@cs opt]# jps
58483 NamesrvStartup
58517 Jps
2
3
4
5
6
7
8
9
10
11
12
broker服务搭建
同样的,启动Broker的脚本是$ROCKETMQ_HOME/bin
目录下的runbroker.sh
脚本。而Broker的默认预设内存是8G,你如果机器性能足够,可以不跟着本小节进行修改了。
我这边用的是虚拟机,所以需要调整下JVM内存大小。修改的方式是直接修改$ROCKETMQ_HOME/bin
目录下的runbroker.sh
脚本。
修改runbroker.sh
脚本
为了防止出现意外,我们应该把原始文件备份一下:
cd /opt
cp /opt/rocketmq-all-5.1.0-bin-release/bin/runbroker.sh /opt/rocketmq-all-5.1.0-bin-release/bin/runbroker.sh.bak
2
现在开始修改:
# 执行命令
cd /opt
vim /opt/rocketmq-all-5.1.0-bin-release/bin/runbroker.sh
# 具体修改位置
choose_gc_log_directory
# JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g" # 修改前
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g" # 修改后
choose_gc_options
JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow"
JAVA_OPT="${JAVA_OPT} -XX:+AlwaysPreTouch"
# JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=15g" # 修改前
JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=512m" # 修改后
JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages -XX:-UseBiasedLocking"
#JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n"
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
broker配置文件添加参数
echo "# 允许自动创建topic" >> /opt/rocketmq-all-5.1.0-bin-release/conf/broker.conf
echo "autoCreateTopicEnable=true" >> /opt/rocketmq-all-5.1.0-bin-release/conf/broker.conf
echo "# 添加namesever的地址" >> /opt/rocketmq-all-5.1.0-bin-release/conf/broker.conf
echo "namesrvAddr=1ocalhost:9876" >> /opt/rocketmq-all-5.1.0-bin-release/conf/broker.conf
cat /opt/rocketmq-all-5.1.0-bin-release/conf/broker.conf
2
3
4
5
启动broker服务
cd /opt
nohup sh /opt/rocketmq-all-5.1.0-bin-release/bin/mqbroker -c /opt/rocketmq-all-5.1.0-bin-release/conf/broker.conf &
# 备用命令: nohup sh /opt/rocketmq-all-5.1.0-bin-release/bin/mqbroker -c /opt/rocketmq-all-5.1.0-bin-release/conf/broker.conf -n localhost:9876 autoCreateTopicEnable=true &
[root@cs opt]# nohup sh /opt/rocketmq-all-5.1.0-bin-release/bin/mqbroker -c /opt/rocketmq-all-5.1.0-bin-release/conf/broker.conf &
[1] 1836
[root@cs opt]# nohup: ignoring input and appending output to ‘nohup.out’
[root@cs opt]#
[root@cs opt]# cat nohup.out
14:30:00,850 |-INFO in org.apache.rocketmq.logging.ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [RocketmqTraffic] to INFO
14:30:00,850 |-INFO in org.apache.rocketmq.logging.ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting additivity of logger [RocketmqTraffic] to false
14:30:00,850 |-INFO in org.apache.rocketmq.logging.ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [RocketmqTrafficAppender] to Logger[RocketmqTraffic]
14:30:00,850 |-INFO in org.apache.rocketmq.logging.ch.qos.logback.classic.model.processor.RootLoggerModelHandler - Setting level of ROOT logger to INFO
14:30:00,850 |-INFO in org.apache.rocketmq.logging.ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [DefaultAppender] to Logger[ROOT]
14:30:00,850 |-INFO in org.apache.rocketmq.logging.ch.qos.logback.core.model.processor.DefaultProcessor@c8afef - End of configuration.
14:30:00,850 |-INFO in org.apache.rocketmq.common.logging.JoranConfiguratorExt@169c6ba - Registering current configuration as safe fallback point
The Name Server boot success. serializeType=JSON, address 0.0.0.0:9876
Invalid maximum direct memory size: -XX:MaxDirectMemorySize=15g
The specified size exceeds the maximum representable size.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
The broker[broker-a, 192.168.11.150:10911] boot success. serializeType=JSON and name server is 1ocalhost:9876
[root@cs opt]# jps
58609 BrokerStartup
58483 NamesrvStartup
58723 Jps
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
最终测试
在RocketMQ的安装包中,提供了一个tools.sh
工具可以用来在命令行快速验证RocketMQ服务。
# 临时向消息队列中添加元素,这个脚本会自动添加1000个元素,添加完自动退出
cd /opt
export NAMESRV_ADDR='localhost:9876'
sh /opt/rocketmq-all-5.1.0-bin-release/bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
# 消费者,把1000个元素消费掉,注意,消费完毕,会出现卡主的现象,这是因为消费者还在监听这个队列,等待新的元素到来,你可以ctrl+c结束掉
cd /opt
export NAMESRV_ADDR='localhost:9876'
sh /opt/rocketmq-all-5.1.0-bin-release/bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
2
3
4
5
6
7
8
9
只要这两步能成功跑起来,就没啥问题了。
rocketmq5.1.4 for Windows
配置Java环境变量和Maven
参考:<>
安装
1. 下载
去这个地址:https://rocketmq.apache.org/zh/release-notes/ 下载,我选择二进制版本:
将其解压到一个没有中文和空格的路径下,我把解压后的安装包放到这里了:C:\software\rocketmq-all-5.1.4-bin-release
。
2. 添加环境变量
变量名 | 值 |
---|---|
ROCKETMQ_HOME | C:\software\rocketmq-all-5.1.4-bin-release |
系统的path | %ROCKETMQ_HOME%\bin |
rocketmq-dashboard安装
摘自官网:https://rocketmq.apache.org/zh/docs/4.x/deployment/03Dashboard/
RocketMQ Dashboard
是 RocketMQ 的管控利器,为用户提供客户端和应用程序的各种事件、性能的统计信息,支持以可视化工具代替 Topic 配置、Broker 管理等命令行操作。
下载
e-1.0.0>