一,Rocketmq是什么?
1, RocketMQ是一个队列模型的消息中间件,具有高性能、高可靠、高实时、分布式特点
相比kafka,rocketmq的实时性更强
2,官方网站:
http://rocketmq.apache.org/
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,下载:
从官网找到下载地址后:
[root@localhost rocketmq]# pwd /usr/local/source/rocketmq [root@localhost rocketmq]# wget https://mirror.bit.edu.cn/apache/rocketmq/4.7.1/rocketmq-all-4.7.1-bin-release.zip
保存到源安装文件目录
三,解压:
[root@localhost rocketmq]# unzip rocketmq-all-4.7.1-bin-release.zip
移动到安装目录:
[root@localhost rocketmq]# mv rocketmq-all-4.7.1-bin-release /usr/local/soft/
四,配置rocketmq
1,配置conf文件:
[root@localhost rocketmq-all-4.7.1-bin-release]# vi conf/broker.conf
添加两行:
namesrvAddr = 127.0.0.1:9876 autoCreateTopicEnable = true
2,修改runserver.sh启动参数:
[root@localhost rocketmq-all-4.7.1-bin-release]# vi bin/runserver.sh
因为占用内存较多,需要改小,如果内存充足可以不改
原代码:
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
修改为:
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m”
3,修改runbroker.sh启动参数
[root@localhost rocketmq-all-4.7.1-bin-release]# vi bin/runbroker.sh
原代码:
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"
修改为:
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m"
五,生成启动和关闭的脚本:
[root@localhost rocketmq-all-4.7.1-bin-release]# vi start_namesrv.sh
代码:
nohup sh bin/mqnamesrv &
[root@localhost rocketmq-all-4.7.1-bin-release]# vi stop_namesrv.sh
代码:
sh bin/mqshutdown namesrv
[root@localhost rocketmq-all-4.7.1-bin-release]# vi start_broker.sh
代码:
nohup sh bin/mqbroker -c /usr/local/soft/rocketmq-all-4.7.1-bin-release/conf/broker.conf &
[root@localhost rocketmq-all-4.7.1-bin-release]# vi stop_broker.sh
代码:
sh bin/mqshutdown broker
给脚本增加执行权限:
[root@localhost rocketmq-all-4.7.1-bin-release]# chmod +x *.sh
六,用java13启动rocketmq4.7.1时的报错:
说明:启动时会出现报错是因为rocketmq针对的jdk版本较低,有一些启动项在新版java上已删除
如果使用低版本的jdk8可以解决,如果不想降低版本则需修改启动项
1,解决启动nameserver时报错:
报错:
[root@localhost rocketmq-all-4.7.1-bin-release]# bin/mqnamesrv Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. Unrecognized VM option 'UseCMSCompactAtFullCollection' Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
解决:
修改bin/runserver.sh
注释掉下面一行:
修改bin/runserver.sh
注释掉下面一行:
#JAVA_OPT="${JAVA_OPT} -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemar kEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 -XX:-UseParNewGC"
修改为:
JAVA_OPT="${JAVA_OPT} -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB =0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 "
报错:
[root@localhost rocketmq-all-4.7.1-bin-release]# bin/mqnamesrv Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. [0.001s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/dev/shm/rmq_srv_gc_%p_%t.log instead. Unrecognized VM option 'UseGCLogFileRotation' Error: Could not create the Java Virtual Machine.
解决 :
修改bin/runserver.sh
注释掉下面这一行
#JAVA_OPT="${JAVA_OPT} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m"
报错:
[root@localhost rocketmq-all-4.7.1-bin-release]# bin/mqnamesrv Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. [0.001s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/dev/shm/rmq_srv_gc_%p_%t.log instead. -Djava.ext.dirs=/usr/local/soft/jdk-13/jre/lib/ext:/usr/local/soft/rocketmq-all-4.7.1-bin-release/bin/../lib:/usr/local/soft/jdk-13/lib/ext is not supported. Use -classpath instead. Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
解决:
修改bin/runserver.sh
注释掉下面这一行
#JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib:${JAVA_HOME}/lib/ext"
报错:
[root@localhost rocketmq-all-4.7.1-bin-release]# bin/mqnamesrv Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. [0.001s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/dev/shm/rmq_srv_gc_%p_%t.log instead. [0.001s][warning][gc] -XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead. [0.009s][info ][gc] Using Concurrent Mark Sweep 错误: 找不到或无法加载主类 org.apache.rocketmq.namesrv.NamesrvStartup 原因: java.lang.ClassNotFoundException: org.apache.rocketmq.namesrv.NamesrvStartup
解决:
修改bin/runserver.sh
注释掉这一行
#export CLASSPATH=.:${BASE_DIR}/conf:${CLASSPATH}
修改为:
export CLASSPATH=${BASE_DIR}/lib/rocketmq-namesrv-4.7.1.jar:${BASE_DIR}/lib/*:${BASE_DIR}/conf:${CLASSPATH}:${CLASS_PATH}
2,启动broker时的报错
报错1
[root@localhost rocketmq-all-4.7.1-bin-release]# bin/mqbroker -c /usr/local/soft/rocketmq-all-4.7.1-bin-release/conf/broker.conf [0.001s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/dev/shm/rmq_broker_gc_%p_%t.log instead. Unrecognized VM option 'PrintGCDateStamps' Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
报错2:
[root@localhost rocketmq-all-4.7.1-bin-release]# bin/mqbroker -c /usr/local/soft/rocketmq-all-4.7.1-bin-release/conf/broker.conf [0.004s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/dev/shm/rmq_broker_gc_%p_%t.log instead. Unrecognized VM option 'PrintGCApplicationStoppedTime' Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
上面两个报错的解决:
修改bin/runbroker.sh
把下面一行注释掉
#JAVA_OPT="${JAVA_OPT} -verbose:gc -Xloggc:${GC_LOG_DIR}/rmq_broker_gc_%p_%t.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCAppli cationStoppedTime -XX:+PrintAdaptiveSizePolicy”
替换为:
JAVA_OPT="${JAVA_OPT} -verbose:gc -Xloggc:${GC_LOG_DIR}/rmq_broker_gc_%p_%t.log -XX:+PrintGCDetails"
报错:
[root@localhost rocketmq-all-4.7.1-bin-release]# bin/mqbroker -c /usr/local/soft/rocketmq-all-4.7.1-bin-release/conf/broker.conf [0.000s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/dev/shm/rmq_broker_gc_%p_%t.log instead. Unrecognized VM option 'UseGCLogFileRotation' Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
解决:
修改bin/runbroker.sh
注释掉下面一行:
#JAVA_OPT="${JAVA_OPT} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m"
报错:
[root@localhost rocketmq-all-4.7.1-bin-release]# bin/mqbroker -c /usr/local/soft/rocketmq-all-4.7.1-bin-release/conf/broker.conf [0.001s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/dev/shm/rmq_broker_gc_%p_%t.log instead. -Djava.ext.dirs=/usr/local/soft/jdk-13/jre/lib/ext:/usr/local/soft/rocketmq-all-4.7.1-bin-release/bin/../lib:/usr/local/soft/jdk-13/lib/ext is not supported. Use -classpath instead. Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
解决:
修改bin/runbroker.sh
注释掉下面一行
#JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib:${JAVA_HOME}/lib/ext"
报错:
[root@localhost rocketmq-all-4.7.1-bin-release]# bin/mqbroker -c /usr/local/soft/rocketmq-all-4.7.1-bin-release/conf/broker.conf [0.000s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/dev/shm/rmq_broker_gc_%p_%t.log instead. [0.001s][warning][gc] -XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead. [2.073s][info ][gc] Using G1 [2.124s][info ][gc] Periodic GC disabled 错误: 找不到或无法加载主类 org.apache.rocketmq.broker.BrokerStartup 原因: java.lang.ClassNotFoundException: org.apache.rocketmq.broker.BrokerStartup
解决:
修改bin/runbroker.sh
注释掉下面一行
#export CLASSPATH=.:${BASE_DIR}/conf:${CLASSPATH}
替换为:
export CLASSPATH=${BASE_DIR}/lib/rocketmq-broker-4.7.1.jar:${BASE_DIR}/lib/*:${BASE_DIR}/conf/:.:${CLASSPATH}:${CLASS_PATH}
七,启动rocketmq
先启动namesrv
[root@localhost rocketmq-all-4.7.1-bin-release]# ./start_namesrv.sh [root@localhost rocketmq-all-4.7.1-bin-release]# nohup: 把输出追加到 'nohup.out'
再启动broker
[root@localhost rocketmq-all-4.7.1-bin-release]# ./start_broker.sh [root@localhost rocketmq-all-4.7.1-bin-release]# nohup: 把输出追加到 'nohup.out'
八,测试安装效果:
1,通过jps查看进程:
[root@localhost rocketmq-all-4.7.1-bin-release]# /usr/local/soft/jdk-13/bin/jps 66026 BrokerStartup 65610 NamesrvStartup 66573 Jps
2,查看rocketmq生成的日志:
[root@localhost rocketmq-all-4.7.1-bin-release]# tail -f ~/logs/rocketmqlogs/broker.log 2020-09-11 15:25:55 INFO BrokerControllerScheduledThread1 - Slave fall behind master: 0 bytes 2020-09-11 15:25:55 INFO brokerOutApi_thread_3 - register broker[0]to name server 127.0.0.1:9876 OK 2020-09-11 15:26:25 INFO brokerOutApi_thread_4 - register broker[0]to name server 127.0.0.1:9876 OK 2020-09-11 15:26:55 INFO BrokerControllerScheduledThread1 - dispatch behind commit log 0 bytes 2020-09-11 15:26:55 INFO BrokerControllerScheduledThread1 - Slave fall behind master: 0 bytes 2020-09-11 15:26:55 INFO brokerOutApi_thread_1 - register broker[0]to name server 127.0.0.1:9876 OK 2020-09-11 15:27:25 INFO brokerOutApi_thread_2 - register broker[0]to name server 127.0.0.1:9876 OK 2020-09-11 15:27:55 INFO BrokerControllerScheduledThread1 - dispatch behind commit log 0 bytes 2020-09-11 15:27:55 INFO BrokerControllerScheduledThread1 - Slave fall behind master: 0 bytes 2020-09-11 15:27:55 INFO brokerOutApi_thread_3 - register broker[0]to name server 127.0.0.1:9876 OK
3,手动用命令创建topic
[root@localhost rocketmq-all-4.7.1-bin-release]# ./bin/mqadmin updateTopic -t laoliutest -b localhost:10911 -n localhost:9876 WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by io.netty.util.internal.PlatformDependent0$1 (file:/usr/local/soft/rocketmq-all-4.7.1-bin-release/lib/netty-all-4.0.42.Final.jar) to field java.nio.Buffer.address WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.PlatformDependent0$1 WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.PlatformDependent0). RocketMQLog:WARN Please initialize the logger system properly. create topic to localhost:10911 success. TopicConfig [topicName=laoliutest, readQueueNums=8, writeQueueNums=8, perm=RW-, topicFilterType=SINGLE_TAG, topicSysFlag=0, order=false][root@localhost rocketmq-all-4.7.1-bin-release]#
查看topic列表:
[root@localhost rocketmq-all-4.7.1-bin-release]# ./bin/mqadmin topicList -n localhost:9876 WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by io.netty.util.internal.PlatformDependent0$1 (file:/usr/local/soft/rocketmq-all-4.7.1-bin-release/lib/netty-all-4.0.42.Final.jar) to field java.nio.Buffer.address WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.PlatformDependent0$1 WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.PlatformDependent0). RocketMQLog:WARN Please initialize the logger system properly. laoliutest SCHEDULE_TOPIC_XXXX RMQ_SYS_TRANS_HALF_TOPIC DefaultCluster_REPLY_TOPIC BenchmarkTest OFFSET_MOVED_EVENT broker-a TBW102 SELF_TEST_TOPIC DefaultCluster
可以看到我们已创建的laoliutest这个topic
九,查看java的版本:
[root@localhost rocketmq-all-4.7.1-bin-release]# java --version java 13 2019-09-17 Java(TM) SE Runtime Environment (build 13+33) Java HotSpot(TM) 64-Bit Server VM (build 13+33, mixed mode, sharing)
十,查看linux的版本:
[root@localhost java]$ cat /etc/redhat-release CentOS Linux release 8.2.2004 (Core)