RocketMQ的安装

下载
单机版安装
1、解压 unzip rocketmq-all-4.9.0-bin-release.zip,并复制到/usr/local/rocketmq
2、启动 nameserver
nohup sh /usr/local/rocketmq/bin/mqnamesrv > /var/log/rocketmq/namesrv.log &
3、启动broker
nohup sh /usr/local/rocketmq/bin/mqbroker -n localhost:9876 autoCreateTopicEnable=true > /var/log/rocketmq/broker.log &
4、如果启动broker报G1GC异常,则把runbroker.sh中G1GC相关的那一行注释掉
5、关闭
sh mqshutdown broker
sh mqshutdown namesrv
6、调优
runserver.sh和runbroker.sh中有关于jvm内存调优的地方,可以进行调整
7、jps可以验证nameserver和broker是否启动
集群版部署
1、几种集群模式
>.单Master模式
这种方式风险较大,一旦Broker重启或者宕机时,会导致整个服务不可用。不建议线上环境使用,可以用于本地测试。
>.多Master模式
一个集群无Slave,全是Master,例如2个Master或者3个Master,这种模式的优缺点如下:
优点:配置简单,单个Master宕机或重启维护对应用无影响,在磁盘配置为RAID10时,即使机器宕机不可恢复情况下,由于RAID10磁盘非常可靠,消息也不会丢(异步刷盘丢失少量消息,同步刷盘一条不丢),性能最高;
缺点:单台机器宕机期间,这台机器上未被消费的消息在机器恢复之前不可订阅,消息实时性会受到影响。
>.多Master多Slave模式-异步复制
每个Master配置一个Slave,有多对Master-Slave,HA采用异步复制方式,主备有短暂消息延迟(毫秒级),这种模式的优缺点如下:
优点:即使磁盘损坏,消息丢失的非常少,且消息实时性不会受影响,同时Master宕机后,消费者仍然可以从Slave消费,而且此过程对应用透明,不需要人工干预,性能同多Master模式几乎一样;
缺点:Master宕机,磁盘损坏情况下会丢失少量消息。
>.多Master多Slave模式-同步双写
每个Master配置一个Slave,有多对Master-Slave,HA采用同步双写方式,即只有主备都写成功,才向应用返回成功,这种模式的优缺点如下:
优点:数据与服务都无单点故障,Master宕机情况下,消息无延迟,服务可用性与数据可用性都非常高;
缺点:性能比异步复制模式略低(大约低10%左右),发送单个消息的RT会略高,且目前版本在主节点宕机后,备机不能自动切换为主机。
本文采用 多Master多Slave模式-异步复制 模式
注释:nameserver在单机版已经启动,此处下文不在赘述
2、确定部署方式,三台服务器,互为主从
10.14.12.17  broker-a-master broker-c-slave
10.14.12.18  broker-b-master broker-a-slave
10.14.12.19  broker-c-master broker-b-slave
说明:rocketmq的conf目录自带集群部署方式的配置文件样例,可以进行修改
3、创建目录
/usr/local/rocketmq/conf/cluster
/var/lib/rocketmq/store-a等,根据具体节点进行创建
4、创建配置文件
主节点:broker-a.properties
# 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
#
#
# 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=ty-rocket-mq-cluster
#broker名字,同一主从要一致
brokerName=broker-a
#0 表示 Master,>0 表示 Slave
brokerId=0
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时,现改为120小时
fileReservedTime=120
#Broker 的角色,ASYNC_MASTER=异步复制Master,SYNC_MASTER=同步双写Master,SLAVE=slave节点
brokerRole=ASYNC_MASTER
#刷盘方式,ASYNC_FLUSH=异步刷盘,SYNC_FLUSH=同步刷盘
flushDiskType=SYNC_FLUSH
#Broker 对外服务的监听端口
listenPort=10911
#nameServer地址,这里nameserver是单台,如果nameserver是多台集群的话,就用分号分割(即namesrvAddr=ip1:port1;ip2:port2;ip3:port3)
namesrvAddr=192.168.12.17:9876;192.168.12.18:9876;192.168.12.19:9876
#每个topic对应队列的数量,默认为4,实际应参考consumer实例的数量,值过小不利于consumer负载均衡
defaultTopicQueueNums=8
#是否允许 Broker 自动创建Topic,生产建议关闭
autoCreateTopicEnable=false
#是否允许 Broker 自动创建订阅组,生产建议关闭
autoCreateSubscriptionGroup=false
#设置BrokerIP
brokerIP1=192.168.12.17
#存储路径
storePathRootDir=/var/lib/rocketmq/store-a
#commitLog 存储路径
storePathCommitLog=/var/lib/rocketmq/store-a/commitlog
#消费队列存储路径存储路径
storePathConsumerQueue=/var/lib/rocketmq/store-a/consumequeue
#消息索引存储路径
storePathIndex=/var/lib/rocketmq/store-a/index
#checkpoint 文件存储路径
storeCheckpoint=/var/lib/rocketmq/store-a/checkpoint
#abort 文件存储路径
abortFile=/var/lib/rocketmq/store-a/abort
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
从节点:broker-c-s.properties
# 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
#
#
# 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=ty-rocket-mq-cluster
#broker名字,同一主从要一致
brokerName=broker-c
#0 表示 Master,>0 表示 Slave
brokerId=1
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时,此处改为120小时
fileReservedTime=120
#Broker 的角色,ASYNC_MASTER=异步复制Master,SYNC_MASTER=同步双写Master,SLAVE=slave节点
brokerRole=SLAVE
#刷盘方式,ASYNC_FLUSH=异步刷盘,SYNC_FLUSH=同步刷盘
flushDiskType=SYNC_FLUSH
#Broker 对外服务的监听端口
listenPort=10921
#nameServer地址,这里nameserver是单台,如果nameserver是多台集群的话,就用分号分割(即namesrvAddr=ip1:port1;ip2:port2;ip3:port3)
namesrvAddr=192.168.12.17:9876;192.168.12.18:9876;192.168.12.19:9876
#每个topic对应队列的数量,默认为4,实际应参考consumer实例的数量,值过小不利于consumer负载均衡
defaultTopicQueueNums=8
#是否允许 Broker 自动创建Topic,生产建议关闭
autoCreateTopicEnable=false
#是否允许 Broker 自动创建订阅组,生产建议关闭
autoCreateSubscriptionGroup=false
#设置BrokerIP
brokerIP1=192.168.12.17
#存储路径
storePathRootDir=/var/lib/rocketmq/store-c
#commitLog 存储路径
storePathCommitLog=/var/lib/rocketmq/store-c/commitlog
#消费队列存储路径存储路径
storePathConsumerQueue=/var/lib/rocketmq/store-c/consumequeue
#消息索引存储路径
storePathIndex=/var/lib/rocketmq/store-c/index
#checkpoint 文件存储路径
storeCheckpoint=/var/lib/rocketmq/store-c/checkpoint
#abort 文件存储路径
abortFile=/var/lib/rocketmq/store-c/abort
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
5、启动
依次启动各个broker
nohup sh mqbroker -c broker-a.properties &
6、查看集群情况
sh mqadmin clusterList -n "192.168.12.17:9876"
或者
sh mqadmin clusterList --namesrvAddr=192.168.12.17:9876
创建topic
./mqadmin updateTopic -n localhost:9876 -b localhost:10911 -t tx-mq-TOPIC
sh mqadmin updateTopic -n 10.0.3.234:9876;10.0.3.235:9876 -c EcsCluster -t asset_advance_repay
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值