RocketMQ單機部署


一、安裝包下載

地址:http://mirror.bit.edu.cn/apache/rocketmq/

二、安裝RocketMQ

# unzip rocketmq-all-4.4.0-bin-release.zip  -d /usr/local/

1、修改配置文件: /usr/local/rocketmq-all-4.4.0-bin-release/conf/broker.conf

具體配置如下:

#所屬集群名字
brokerClusterName=rocketmq-cluster
#broker名字,注意此處不同的配置文件填寫的不一樣 (broker-b.properties的這里改成broker-b)
brokerName=broker-a
#0 表示 Master,>0 表示 Slave 
brokerId=0
#nameServer地址,分號分割
#namesrvAddr=rocketmq-nameserver:9876;rocketmq-nameserver2:9876
namesrvAddr=172.16.68.169:9876
#可選,該配置默認從系統可用地址中選擇一個;
#在某些場景可以手動配置ip,例如程序運行在虛擬機中外部無法訪問默認地址,或者用來解決docker本地ip外部無法訪問的問。
brokerIP1=172.16.68.169
#可選,broker的ha地址,其用途同上,不過一般不需要配置
#brokerIP2=192.168.1.152
 
#在發送消息時,自動創建服務器不存在的topic,默認創建的隊列數 
defaultTopicQueueNums=4
#是否允許 Broker 自動創建Topic,建議線下開啟,線上關閉 
autoCreateTopicEnable=true
#是否允許 Broker 自動創建訂閱組,建議線下開啟,線上關閉 
autoCreateSubscriptionGroup=true
#Broker 對外服務的監聽端口 
listenPort=10911
#刪除文件時間點,默認凌晨 4點 
deleteWhen=04
#文件保留時間,默認 48 小時 
fileReservedTime=120
#commitLog每個文件的大小默認1G 
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每個文件默認存30W條,根據業務情況調整 
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000 
#redeleteHangedFileInterval=120000 
#檢測物理文件磁盤空間 
diskMaxUsedSpaceRatio=88
#存儲路徑 
storePathRootDir=/usr/local/rocketmq-all-4.4.0-bin-release/store
#commitLog 存儲路徑 
storePathCommitLog=/usr/local/rocketmq-all-4.4.0-bin-release/store/commitlog
#消費隊列存儲路徑存儲路徑 
storePathConsumeQueue=/usr/local/rocketmq-all-4.4.0-bin-release/store/pathconsumequeue
#消息索引存儲路徑 
storePathIndex=/usr/local/rocketmq-all-4.4.0-bin-release/store/pathindex
#checkpoint 文件存儲
storeCheckpoint=/usr/local/rocketmq-all-4.4.0-bin-release/store/checkpoint
#abort 文件存儲路
abortFile=/usr/local/rocketmq-all-4.4.0-bin-release/store/abort
#限制的消息大小 
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色 
#- ASYNC_MASTER  異步復制Master 
#- SYNC_MASTER  同步雙寫Master 
#- SLAVE 
brokerRole=ASYNC_MASTER
#刷盤方式 
#- ASYNC_FLUSH  異步刷盤 
#- SYNC_FLUSH  同步刷盤 
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#發消息線程池數量 
#sendMessageThreadPoolNums=128 
#拉消息線程池數量 
#pullMessageThreadPoolNums=128lushDiskType=ASYNC_FLUSH

2、創建存儲路徑

# mkdir -p  /usr/local/rocketmq-all-4.4.0-bin-release/store/{commitlog,pathconsumequeue,pathindex}

注意:存儲路徑 storeCheckpoint ,abortFile 不需要創建文件夾,會自動創建checkpoint 文件 和 abort 文件,但是需要創建 commitlog ,consumequeue,index 文件夾, 這點需要特別注意。不然會報錯 Try to shutdown service thread:PullRequestHoldService started:false lastThread:null,起不來broker。

3、修改啟動腳本

# sed -i "s/4g/256m/g" /usr/local/rocketmq-all-4.4.0-bin-release/bin/runserver.sh
# sed -i "s/2g/128m/g" /usr/local/rocketmq-all-4.4.0-bin-release/bin/runserver.sh

# sed -i "s/8g/512m/g" /usr/local/rocketmq-all-4.4.0-bin-release/bin/runbroker.sh
# sed -i "s/4g/256m/g" /usr/local/rocketmq-all-4.4.0-bin-release/bin/runbroker.sh

 

4、啟動NameServer

# nohup sh /usr/local/rocketmq-all-4.4.0-bin-release/bin/mqnamesrv &
[root@localhost store]# jps
2856 NamesrvStartup
20730 Jps

5、啟動Broker

# export NAMESRV_ADDR=172.16.68.169:9876
# nohup sh /usr/local/rocketmq-all-4.4.0-bin-release/bin/mqbroker -c /usr/local/rocketmq-all-4.4.0-bin-release/conf/broker.conf &
[root@localhost store]# jps
2856 NamesrvStartup
3738 BrokerStartup
20730 Jps

 6、驗證

# /usr/local/rocketmq-all-4.4.0-bin-release/bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
# /usr/local/rocketmq-all-4.4.0-bin-release/bin/tools.sh org.apache.rocketmq.example.quickstart.Producer


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM