RocketMQ介紹與雲服務器安裝

RocketMQ

介紹與概念

在github上的說法來看: Apache RocketMQ是一個分佈式消息傳遞和流媒體平臺,具備低延遲,高性能和可靠性,萬億級容量和靈活的可擴展性。它提供了多種功能:java

  • 發佈/訂閱消息模型和點對點
  • 預約的消息傳遞
  • 消息追溯性按時間或偏移量
  • 記錄流媒體的中心
  • 大數據集成
  • 可靠的FIFO和嚴格的有序消息傳遞在同一隊列中
  • 高效的推拉消費模式
  • 單個隊列中的百萬級消息累積容量
  • 多種消息傳遞協議,如JMS和OpenMessaging
  • 靈活的分佈式橫向擴展部署架構
  • Lightning-fast批處理消息交換系統
  • 各類消息過濾器機制,如SQL和Tag
  • Docker圖像用於隔離測試和雲隔離集羣
  • 功能豐富的管理儀表板,用於配置,指標和監控
  • 訪問控制列表
  • 消息跟蹤

上面都是官方列舉出來了,還有以下特色:git

  • 支持Broker和Consumer端消息過濾
  • 支持拉pull和推push兩種消費模式,也就是上面說的推拉消費模式
  • 支持單master節點,多master節點,多master節點多slave節點
  • 消息失敗重試機制,支持特定level的定時消息
  • 新版本底層採用Netty

官方網站: http://rocketmq.apache.org/docs/motivation/ 也對RocketMQ和ActiveMQ以及Kafka作了一個對比.github

核心概念

參考: http://rocketmq.apache.org/docs/core-concept/ 本人英文閱讀能力有點弱,你們請看官方文檔.apache

  • Producer: 消息生產者
  • Producer Group: 消息生產者組,發送同類消息的一個消息生產組
  • Consumer: 消息消費者
  • Consumer Group: 消費同類消息的多個實例
  • Tag: 標籤.子主題對topic的進一步細化,用於區分同一個主題下的不一樣業務的消息.
  • Topic: 主題,queue是消息的物理管理單位,而topic是邏輯管理單位,一個topic下能夠有多個queue,默認自動建立是4個,手動建立是8個.
  • Message: 消息,每一個Message必須指定一個topic
  • Broker: MQ程序,接受生產的消息,提供給消費者消費的程序
  • Name Server: 給生產和消費者提供路由信息,提供輕量級的服務發現、路由、元數據信息,能夠多個部署,互相獨立(比zookeeper更輕量)
  • Offset: 偏移量,能夠理解爲消息進度
  • commit log: 消息存儲會寫在Commit log文件裏面

雲服務器安裝RocketMQ

安裝RocketMQ

  1. 下載: http://rocketmq.apache.org/docs/quick-start/, 直接下載源代碼版本
  2. 上傳到雲服務器
  3. 開始操做(參考: http://rocketmq.apache.org/docs/quick-start/):
1. 安裝unzip命令: yum install unzip
2. 解壓: unzip rocketmq-all-4.4.0-source-release.zip
3. 重命名: mv rocketmq-all-4.4.0 rocketmq
4. 進入文件夾: cd rocketmq
5. 使用maven進行源碼編譯: mvn -Prelease-all -DskipTests clean install -U
6. 進入文件夾: cd distribution/target/apache-rocketmq
7. 啓動服務: sh bin/mqnamesrv (注意若是內存小於4G可能會失敗)
  1. 啓動失敗的緣由與解決:
    • 啓動失敗的緣由與解決:
    [root@iZwz94sw188z3yfl7lpmmsZ apache-rocketmq]# sh bin/mqnamesrv
         Java HotSpot(TM) 64-Bit Server VM warning: Using the DefNew
         young collector with the CMS collector is deprecated and will
         likely be removed in a future release
         Java HotSpot(TM) 64-Bit Server VM warning:
         UseCMSCompactAtFullCollection is deprecated and will likely be
         removed in a future release.
         Java HotSpot(TM) 64-Bit Server VM warning: INFO:
         os::commit_memory(0x00000006ec800000, 2147483648, 0) failed;
         error='Cannot allocate memory' (errno=12)
         #
         # There is insufficient memory for the Java Runtime Environment
         to continue.
         # Native memory allocation (mmap) failed to map 2147483648 bytes
         for committing reserved memory.
         # An error report file with more information is saved as:
         # /usr/local/software/rocketmq-all-
         4.4.0/distribution/target/apache-rocketmq/hs_err_pid8993.log
    
         這種緣由是內存不足致使的,默認是4G,解決辦法是編輯 bin/runserver.sh: 
             JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
  2. 以守護進程的方式啓動:
nohup sh bin/mqnamesrv &   這個命令可能會nohup: ignoring input and appending output to ‘nohup.out’,若是出現這個,執行: 
tail -f nohup.out

這個時候ctrl+c就不會退出程序,僅僅是讓程序後臺運行
  1. 啓動Broker
[root@wangzhi apache-rocketmq]# sh bin/mqbroker -n localhost:9876
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000005c0000000, 8589934592, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 8589934592 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /usr/local/software/rocketmq/distribution/target/apache-rocketmq/hs_err_pid3012.log

出現了Broker內存不足的問題:
vim bin/runbroker.sh 修改 JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g" 的內容爲:
JAVA_OPT="${JAVA_OPT} -server -Xms2g -Xmx2g -Xmn1g"

完成以後以守護進程的方式進行啓動:
nohup sh bin/mqbroker -n localhost:9876 &
tail -f nohup.out

這個時候可使用jps查看進程,而且能夠根據進程號來kill進程
  1. 進行測試:
export NAMESRV_ADDR=localhost:9876

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
  1. 遠程鏈接須要開發9876和10911端口,在生產環境不要開放

源碼安裝RcoketMQ4.X控制檯

  1. 上傳源碼包
  2. 解壓: unzip rocketmq-externals-master.zip
  3. 進入文件夾: cd rocketmq-externals-master
  4. 開始操做:
先修改兩個BUG,一個是修改pom.xml的版本號.
    cd rocketmq-console/
    vim pom.xml : 將裏面的rocketmq的版本號後面的snashop刪掉,只留個4.4.0就好
在上一個console的路徑下繼續:
    cd src/main/resources/
    vim application.properties : 修改nameserver地址 rocketmq.config.namesrvAddr=127.0.0.1:9876
返回到console目錄,進行編譯安裝:
    mvn clean package -Dmaven.test.skip
  1. 啓動:
cd target

java -jar rocketmq-console-ng-1.0.0.jar

使用ctrl + c關閉程序,以守護進程的方式進行啓動

nohup java -jar rocketmq-console-ng-1.0.0.jar &
tail -f nohup.out
相關文章
相關標籤/搜索