這篇文章給大家介紹如何快速的搭建RocetMQ,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到潞城網(wǎng)站設(shè)計(jì)與潞城網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站設(shè)計(jì)、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊(cè)、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋潞城地區(qū)。選擇使用編譯好的bin包,版本為新的4.8.0。使用如下命令完成下載和解壓。順帶提一句本機(jī)安裝的Java版本是10.0.1,劃重點(diǎn)。
cd ~/Downloads weget https://mirrors.bfsu.edu.cn/apache/rocketmq/4.8.0/rocketmq-all-4.8.0-bin-release.zip unzip rocketmq-all-4.8.0-bin-release.zip mv rocketmq-all-4.8.0-bin-release rocketmq
然后需要啟動(dòng)NameServer和Broker Server,首先是NameServer,命令如下所示:
cd ~/Downloads/rocketmq/bin ./mqnamesrv
然后很有可能會(huì)遇到如下的報(bào)錯(cuò):
-Djava.ext.dirs=/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/jre/lib/ext:/Users/tony/Downloads/rocketmq-all-4.8.0-source-release/distribution/bin/../lib:/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/lib/ext is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
我根據(jù)這段報(bào)錯(cuò)一番艱難地百度\bing\Google之后,發(fā)現(xiàn)沒(méi)有人遇到完全類似的問(wèn)題,接近的是Could not create the java Virtual Machine的報(bào)錯(cuò),我嘗試性進(jìn)行了如下方法。
首先懷疑是因?yàn)槲业腏ava版本太高了,導(dǎo)致有一些runserver.sh里面的參數(shù)設(shè)置不能兼容,因?yàn)閚amesrv會(huì)執(zhí)行runserver.sh里面的命令。按照騰訊云上的原話是:
由于RocketMQ的啟動(dòng)文件都是按照J(rèn)DK8配置的,而前面我特意配置的JDK版本是11,有很多命令參數(shù)不支持導(dǎo)致的,使用JDK8,正常啟動(dòng)沒(méi)有問(wèn)題的。
于是編輯bin/runserver.sh文件,將下面的命令注釋掉:
# 注釋掉下面這行 #export CLASSPATH=.:${BASE_DIR}/conf:${CLASSPATH} # 修改成下面這行 export CLASSPATH=.:${BASE_DIR}/lib/*:${BASE_DIR}/conf:${CLASSPATH}
然后還需要將JAVA_OPT的參數(shù)注釋一部分,它們的位置是在文件內(nèi)容最后,如下所示:
# 注釋下面這兩行 #JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib:${JAVA_HOME}/lib/ext" #JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n"
是不是看起來(lái)很眼熟?這就是前面我們遇到的報(bào)錯(cuò)那段,據(jù)說(shuō)是Java1.9之后使用-Djava.ext.dirs會(huì)有問(wèn)題,我去RocketMQ的github上的issue討論看了一下,貌似官方團(tuán)隊(duì)也沒(méi)有fix這個(gè)問(wèn)題,2333。
保存好這些修改,然后重新運(yùn)行mqnamesrv即可,以后臺(tái)程序方式運(yùn)行的命令如下:
nohup sh mqnamesrv &
查看運(yùn)行的日志的命令和其輸出如下:
tail -f ~/logs/rocketmqlogs/namesrv.log 2020-12-31 16:15:30 INFO main - tls.client.authServer = false 2020-12-31 16:15:30 INFO main - tls.client.trustCertPath = null 2020-12-31 16:15:30 INFO main - Using OpenSSL provider 2020-12-31 16:15:30 INFO main - SSLContext created for server 2020-12-31 16:15:30 INFO NettyEventExecutor - NettyEventExecutor service started 2020-12-31 16:15:30 INFO main - Try to start service thread:FileWatchService started:false lastThread:null 2020-12-31 16:15:30 INFO FileWatchService - FileWatchService service started 2020-12-31 16:15:30 INFO main - The Name Server boot success. serializeType=JSON 2020-12-31 16:16:30 INFO NSScheduledThread1 - -------------------------------------------------------- 2020-12-31 16:16:30 INFO NSScheduledThread1 - configTable SIZE: 0
說(shuō)明NameServer已經(jīng)正常啟動(dòng)了。
第二步運(yùn)行Broker Server,還是在bin目錄下執(zhí)行:
./mqbroker
繼續(xù)收獲報(bào)錯(cuò),錯(cuò)誤日志輸出如下所示:
[0.002s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/Volumes/RAMDisk/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.
其本質(zhì)還是無(wú)法創(chuàng)建Java虛擬機(jī),推測(cè)還是出在GC的一些參數(shù)在Java10.0上無(wú)法兼容。查看mqbroker腳本里面的內(nèi)容,可以看到最后一行執(zhí)行了如下命令:
sh ${ROCKETMQ_HOME}/bin/runbroker.sh org.apache.rocketmq.broker.BrokerStartup $@
說(shuō)明執(zhí)行了runbroker.sh腳本,于是在runbroker.sh文件中找到如下命令:
# 注釋掉下面這行 #export CLASSPATH=.:${BASE_DIR}/conf:${CLASSPATH} # 修改成下面這行 export CLASSPATH=.:${BASE_DIR}/lib/*:${BASE_DIR}/conf:${CLASSPATH}
這段修改和mqnamesrv的類似,還有下面這段也需要調(diào)整:
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g" JAVA_OPT="${JAVA_OPT} -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -XX:SoftRefLRUPolicyMSPerMB=0" JAVA_OPT="${JAVA_OPT} -verbose:gc -Xloggc:${GC_LOG_DIR}/rmq_broker_gc_%p_%t.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy" JAVA_OPT="${JAVA_OPT} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m" JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow" JAVA_OPT="${JAVA_OPT} -XX:+AlwaysPreTouch" JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=15g" JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages -XX:-UseBiasedLocking" JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib:${JAVA_HOME}/lib/ext" #JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n"
注釋掉一些無(wú)效的命令,改后如下所示:
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g" #JAVA_OPT="${JAVA_OPT} -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -XX:SoftRefLRUPolicyMSPerMB=0" #JAVA_OPT="${JAVA_OPT} -verbose:gc -Xloggc:${GC_LOG_DIR}/rmq_broker_gc_%p_%t.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy" #JAVA_OPT="${JAVA_OPT} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m" JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow" JAVA_OPT="${JAVA_OPT} -XX:+AlwaysPreTouch" #JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=15g" JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages -XX:-UseBiasedLocking" JAVA_OPT="${JAVA_OPT} # -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib:${JAVA_HOME}/lib/ext" #JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n"
保存上述修改,然后就可以正常啟動(dòng)Broker Server了,執(zhí)行下面命令:
nohup sh bin/mqbroker -n localhost:9876 &
如果想最簡(jiǎn)單的方式測(cè)試一下服務(wù),那么可以使用RocketMQ腳本封裝好的工具,命令如下:
export NAMESRV_ADDR=localhost:9876 sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
可能遇到的報(bào)錯(cuò)如下:
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer -Djava.ext.dirs=bin/../lib:/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/jre/lib/ext:/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/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.
還是在tools.sh做類似的修改,如下所示:
# 注釋下面這行 #export CLASSPATH=.:${BASE_DIR}/conf:${CLASSPATH} # 新增下面這行 export CLASSPATH=.:${BASE_DIR}/lib/*:${BASE_DIR}/conf:${CLASSPATH} .... JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m" # 注釋掉下面這行,JDK1.9后不再支持該參數(shù) #JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${BASE_DIR}/lib:${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext" JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"
重新保存后運(yùn)行,如果看到如下輸出則說(shuō)明成功了:
st, brokerName=Tony-Mac-Pro.local, queueId=3], queueOffset=247] SendResult [sendStatus=SEND_OK, msgId=7F000001203D1DE0ACA60ED7764803E0, offsetMsgId=AC101A0000002A9F0000000000031232, messageQueue=MessageQueue [topic=TopicTest, brokerName=Tony-Mac-Pro.local, queueId=0], queueOffset=248] SendResult [sendStatus=SEND_OK, msgId=7F000001203D1DE0ACA60ED7764A03E1, offsetMsgId=AC101A0000002A9F00000000000312FD, messageQueue=MessageQueue [topic=TopicTest, brokerName=Tony-Mac-Pro.local, queueId=1], queueOffset=248] SendResult [sendStatus=SEND_OK, msgId=7F000001203D1DE0ACA60ED7764C03E2, offsetMsgId=AC101A0000002A9F00000000000313C8, messageQueue=MessageQueue [topic=TopicTest, brokerName=Tony-Mac-Pro.local, queueId=2], queueOffset=248] SendResult [sendStatus=SEND_OK, msgId=7F000001203D1DE0ACA60ED7764E03E3, offsetMsgId=AC101A0000002A9F0000000000031493, messageQueue=MessageQueue [topic=TopicTest, brokerName=Tony-Mac-Pro.local, queueId=3], queueOffset=248] SendResult [sendStatus=SEND_OK, msgId=7F000001203D1DE0ACA60ED7764F03E4, offsetMsgId=AC101A0000002A9F000000000003155E, messageQueue=MessageQueue [topic=TopicTest, brokerName=Tony-Mac-Pro.local, queueId=0], queueOffset=249] SendResult [sendStatus=SEND_OK, msgId=7F000001203D1DE0ACA60ED7764F03E5, offsetMsgId=AC101A0000002A9F0000000000031629, messageQueue=MessageQueue [topic=TopicTest, brokerName=Tony-Mac-Pro.local, queueId=1], queueOffset=249] SendResult [sendStatus=SEND_OK, msgId=7F000001203D1DE0ACA60ED7765003E6, offsetMsgId=AC101A0000002A9F00000000000316F4, messageQueue=MessageQueue [topic=TopicTest, brokerName=Tony-Mac-Pro.local, queueId=2], queueOffset=249] SendResult [sendStatus=SEND_OK, msgId=7F000001203D1DE0ACA60ED7765103E7, offsetMsgId=AC101A0000002A9F00000000000317BF, messageQueue=MessageQueue [topic=TopicTest, brokerName=Tony-Mac-Pro.local, queueId=3], queueOffset=249] 21:10:01.562 [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel: close the connection to remote address[172.16.26.0:10911] result: true 21:10:01.564 [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel: close the connection to remote address[127.0.0.1:9876] result: true
關(guān)于如何快速的搭建RocetMQ就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
分享標(biāo)題:如何快速的搭建RocetMQ-創(chuàng)新互聯(lián)
網(wǎng)站鏈接:http://jinyejixie.com/article8/ghoip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、網(wǎng)站改版、響應(yīng)式網(wǎng)站、品牌網(wǎng)站設(shè)計(jì)、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容