RocketMQ-初体验RocketMQ(03)_RocketMQ多机集群部署
文章目錄
- 環境準備
- 參考配置
- 集群搭建
- 130主機
- broker 配置文件
- 啟動namesrv
- 啟動broker Master 和 broker Slave
- 131主機
- broker 配置文件
- 啟動namesrv
- 啟動broker Master 和 broker Slave
- 查看集群監控狀態
- 測試發送和消費消息
- 雙機互為主備的配置
- RocketMQ4.3.X配置參數
完成了單節點的RocketMQ的安裝 RocketMQ-初體驗RocketMQ(02)_單節點RocketMQ的安裝 ,我們來搞個2個節點的集群來玩下
環境準備
CentOS7
192.168.18.130 、192.168.18.131
Q: 生產環境,假設你有2臺主機,應該如何部署RocketMQ集群更HA一些?
A:
你有 A、B兩臺主機,
A主機 部署 : broker-a 主節點 和 broker-b 從節點
B主機 部署: broker-b 主節點 和 borker-a 從節點
兩臺主機互為主備,HA更可靠一些,即使有一臺主機,假設B主機 宕機了。 我們的A主機上 仍然還有是 broker-a 主節點 和 broker-b 從節點, 這個時候只是 broker-b 只能提供消費消息的能力了,不能寫入了。 還是要比 整個 broker-b cluster 因為主機B的宕機而全部不能提供服務了好。
參考配置
在RocketMQ 安裝目錄 conf目錄下,官方提供了一些參考配置
可以集合自己的場景,到對應的目錄下看下官方推薦的配置。
集群搭建
130 : brokera-m brokera-s
131: brokerb-m brokerb-s
broker集群在同一臺主機上互為主備 。
每臺機器上啟動一個namesrv。 兩個 broker節點,互為主備,構成一個broker集群。
130主機
broker 配置文件
cp 兩個文件出來
broker-m.conf master節點的配置文件
broker-s.conf slave節點的配置文件
broker-m.conf
# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.#集群名稱,可自定義 brokerClusterName=DefaultCluster brokerName=broker‐a # 0 表示主節點 brokerId=0 # rocketmq‐name服務地址,多個地址用;分開,不配置默認為localhost:9876 namesrvAddr=192.168.18.130:9876;192.168.18.131:9876 deleteWhen=04 fileReservedTime=48 #當前節點角色 brokerRole=SYNC_MASTER flushDiskType=ASYNC_FLUSH autoCreateTopicEnable=true #broker通信端口,默認端口 listenPort=10911 #消息存儲根路徑 storePathRootDir=/data/rocketmq/store-mbroker-s.conf
# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.#集群名稱,可自定義 brokerClusterName=DefaultCluster brokerName=broker‐a # 非0 表示從節點 brokerId=1 # rocketmq‐name服務地址,多個地址用;分開,不配置默認為localhost:9876 namesrvAddr=192.168.18.130:9876;192.168.18.131:9876 deleteWhen=04 fileReservedTime=48 #當前節點角色 brokerRole=SLAVE flushDiskType=ASYNC_FLUSH autoCreateTopicEnable=true #broker通信端口,默認端口 listenPort=10811 #消息存儲根路徑 storePathRootDir=/data/rocketmq/store-s主要注意的地方
- brokerName 主從節點 保持一致
- brokerId 0 表示主節點,從節點 1,2,3…依次類推
- namesrvAddr 配置所有 namesrv的地址,多個地址 使用 ; 分開
- brokerRole 這個要注意 主節點 SYNC_MASTER 或者 ASYNC_MASTER 從節點 SLAVE
- listenPort 確定端口不要重復占用,否則啟動失敗
啟動namesrv
nohup sh bin/mqnamesrv -n 192.168.18.130:9876& 最好通過-n指定主IP,否則的話有可能在多網卡 或者docker環境下 啟動失敗
[root@artisan rocketmq-all-4.3.2-bin-release]# pwd /usr/local/rocketmq/rocketmq-all-4.3.2-bin-release [root@artisan rocketmq-all-4.3.2-bin-release]# nohup sh bin/mqnamesrv -n 192.168.18.130:9876& [1] 9236 [root@artisan rocketmq-all-4.3.2-bin-release]# nohup: ignoring input and appending output to ‘nohup.out’ tail -f nohup.out 日志如下: 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. The Name Server boot success. serializeType=JSON查看進程
[root@artisan rocketmq-all-4.3.2-bin-release]# jps |grep -v Jps 9239 NamesrvStartup [root@artisan rocketmq-all-4.3.2-bin-release]#啟動broker Master 和 broker Slave
主節點: nohup sh bin/mqbroker -c conf/broker-m.conf & 從節點: nohup sh bin/mqbroker -c conf/broker-s.conf &
[root@artisan rocketmq-all-4.3.2-bin-release]# >nohup.out 主節點啟動 [root@artisan rocketmq-all-4.3.2-bin-release]# nohup sh bin/mqbroker -c conf/broker-m.conf & [2] 9415 [root@artisan rocketmq-all-4.3.2-bin-release]# nohup: ignoring input and appending output to ‘nohup.out’ tailf nohup.out The broker[brokeraa, 192.168.18.130:10911] boot success. serializeType=JSON and name server is 192.168.18.130:9876;192.168.18.131:9876^C^C 從節點啟動 [root@artisan rocketmq-all-4.3.2-bin-release]# nohup sh bin/mqbroker -c conf/broker-s.conf & [3] 9495 [root@artisan rocketmq-all-4.3.2-bin-release]# nohup: ignoring input and appending output to ‘nohup.out’ tailf nohup.out The broker[brokeraa, 192.168.18.130:10911] boot success. serializeType=JSON and name server is 192.168.18.130:9876;192.168.18.131:9876The broker[brokeraa, 192.168.18.130:10811] boot success. serializeType=JSON and name server is 192.168.18.130:9876;192.168.18.131:9876^C 查看進程 [root@artisan rocketmq-all-4.3.2-bin-release]# jps |grep -v Jps 9239 NamesrvStartup 9419 BrokerStartup 9499 BrokerStartup [root@artisan rocketmq-all-4.3.2-bin-release]#131主機
broker 配置文件
操作同130 , 唯一不同的就是這個 brokerName 。
這里貼下 配置
主節點
[root@artisan conf]# cat broker-m.conf # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.#集群名稱,可自定義 brokerClusterName=DefaultCluster brokerName=broker‐b # 0 表示主節點 brokerId=0 # rocketmq‐name服務地址,多個地址用;分開,不配置默認為localhost:9876 namesrvAddr=192.168.18.130:9876;192.168.18.131:9876 deleteWhen=04 fileReservedTime=48 #當前節點角色 brokerRole=SYNC_MASTER flushDiskType=ASYNC_FLUSH autoCreateTopicEnable=true #broker通信端口,默認端口 listenPort=10911 #消息存儲根路徑 storePathRootDir=/data/rocketmq/store-m從節點
[root@artisan conf]# cat broker-s.conf # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.#集群名稱,可自定義 brokerClusterName=DefaultCluster brokerName=broker‐b # 非0 表示從節點 brokerId=1 # rocketmq‐name服務地址,多個地址用;分開,不配置默認為localhost:9876 namesrvAddr=192.168.18.130:9876;192.168.18.131:9876 deleteWhen=04 fileReservedTime=48 #當前節點角色 brokerRole=SLAVE flushDiskType=ASYNC_FLUSH autoCreateTopicEnable=true #broker通信端口,默認端口 listenPort=10811 #消息存儲根路徑 storePathRootDir=/data/rocketmq/store-s [root@artisan conf]#啟動namesrv
同130
啟動broker Master 和 broker Slave
同130
查看集群監控狀態
mqadmin clusterlist -n 192.168.18.130:9876
[root@artisan rocketmq-all-4.3.2-bin-release]# sh bin/mqadmin clusterlist -n 192.168.18.130:9876 Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0 Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0 #Cluster Name #Broker Name #BID #Addr #Version #InTPS(LOAD) #OutTPS(LOAD) #PCWait(ms) #Hour #SPACE DefaultCluster brokeraa 0 192.168.18.130:10911 V4_3_2 0.00(0,0ms) 0.00(0,0ms) 0 436943.73 0.1331 DefaultCluster brokeraa 1 192.168.18.130:10811 V4_3_2 0.00(0,0ms) 0.00(0,0ms) 0 436943.73 0.1331 DefaultCluster brokerab 0 192.168.18.131:10911 V4_3_2 0.00(0,0ms) 0.00(0,0ms) 0 436943.73 0.1654 DefaultCluster brokerab 1 192.168.18.131:10811 V4_3_2 0.00(0,0ms) 0.00(0,0ms) 0 436943.73 0.1654 ^C^C^C[root@artisan rocketmq-all-4.3.2-bin-release]# ^C [root@artisan rocketmq-all-4.3.2-bin-release]# sh bin/mqadmin clusterlist -n 192.168.18.131:9876 Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0 Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0 #Cluster Name #Broker Name #BID #Addr #Version #InTPS(LOAD) #OutTPS(LOAD) #PCWait(ms) #Hour #SPACE DefaultCluster brokeraa 0 192.168.18.130:10911 V4_3_2 0.00(0,0ms) 0.00(0,0ms) 0 436943.73 0.1331 DefaultCluster brokeraa 1 192.168.18.130:10811 V4_3_2 0.00(0,0ms) 0.00(0,0ms) 0 436943.73 0.1331 DefaultCluster brokerab 0 192.168.18.131:10911 V4_3_2 0.00(0,0ms) 0.00(0,0ms) 0 436943.73 0.1654 DefaultCluster brokerab 1 192.168.18.131:10811 V4_3_2 0.00(0,0ms) 0.00(0,0ms) 0 436943.73 0.1654 [root@artisan rocketmq-all-4.3.2-bin-release]#如果碰到了如下錯誤
[root@artisan bin]# ./mqadmin clusterlist -n 192.168.18.130:9876 Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0 Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0 org.apache.rocketmq.tools.command.SubCommandException: ClusterListSubCommand command failedat org.apache.rocketmq.tools.command.cluster.ClusterListSubCommand.execute(ClusterListSubCommand.java:93)at org.apache.rocketmq.tools.command.MQAdminStartup.main0(MQAdminStartup.java:132)at org.apache.rocketmq.tools.command.MQAdminStartup.main(MQAdminStartup.java:83) Caused by: org.apache.rocketmq.remoting.exception.RemotingTimeoutException: wait response on the channel <192.168.18.130:9876> timeout, 463(ms)at org.apache.rocketmq.remoting.netty.NettyRemotingAbstract.invokeSyncImpl(NettyRemotingAbstract.java:391)at org.apache.rocketmq.remoting.netty.NettyRemotingClient.invokeSync(NettyRemotingClient.java:374)at org.apache.rocketmq.client.impl.MQClientAPIImpl.getBrokerClusterInfo(MQClientAPIImpl.java:1180)at org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl.examineBrokerClusterInfo(DefaultMQAdminExtImpl.java:275)at org.apache.rocketmq.tools.admin.DefaultMQAdminExt.examineBrokerClusterInfo(DefaultMQAdminExt.java:222)at org.apache.rocketmq.tools.command.cluster.ClusterListSubCommand.printClusterBaseInfo(ClusterListSubCommand.java:172)at org.apache.rocketmq.tools.command.cluster.ClusterListSubCommand.execute(ClusterListSubCommand.java:88)... 2 more [root@artisan bin]# ^C 重試幾次 [root@artisan bin]# ./mqadmin clusterlist -n 192.168.18.130:9876 Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0 Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0 #Cluster Name #Broker Name #BID #Addr #Version #InTPS(LOAD) #OutTPS(LOAD) #PCWait(ms) #Hour #SPACE DefaultCluster broker?a 0 192.168.18.130:10911 V4_3_2 0.00(0,0ms) 0.00(0,0ms) 0 436999.54 0.1360 DefaultCluster broker?a 1 192.168.18.130:10811 V4_3_2 0.00(0,0ms) 0.00(0,0ms) 0 436999.54 0.1360 DefaultCluster broker?b 0 192.168.18.131:10911 V4_3_2 0.00(0,0ms) 0.00(0,0ms) 0 436999.54 0.1690 DefaultCluster broker?b 1 192.168.18.131:10811 V4_3_2 0.00(0,0ms) 0.00(0,0ms) 0 436999.54 0.1690 [root@artisan bin]#可能是mqadmin沒能正確的連接進去!網絡抖動,這個跟底層netty的連接有關. 多重試幾次,一般都沒問題。
測試發送和消費消息
[root@artisan rocketmq-all-4.3.2-bin-release]# export NAMESRV_ADDR=192.168.18.131:9876 [root@artisan rocketmq-all-4.3.2-bin-release]# [root@artisan rocketmq-all-4.3.2-bin-release]# sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer結果截個圖:
測試消費者
[root@artisan rocketmq-all-4.3.2-bin-release]# sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer運行結果 截個圖
是不是希望有個頁面可以管理和查看集群信息呢? RocketMQ 提供了 RocketMQ Console ,下篇博文我們來看下如何通過拉取源碼來搭建一套本地的RocketMQ Console吧
雙機互為主備的配置
剛剛搭建的 是 左邊的 ,生產環境更建議使用右側的部署方式
配置的話 ,僅需要調整 broker-s.conf 中的 brokerName即可
131:
broker-s.conf
130 :
broker-s :
啟動后,打開RocketMQConsole 看下,符合部署。
RocketMQ4.3.X配置參數
請移步 RocketMQ4.3.x 史上配置最全詳解,沒有之一
總結
以上是生活随笔為你收集整理的RocketMQ-初体验RocketMQ(03)_RocketMQ多机集群部署的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: RocketMQ-初体验RocketMQ
- 下一篇: RocketMQ-初体验RocketMQ