一、下载

wget https://archive.apache.org/dist/rocketmq/4.6.0/rocketmq-all-4.6.0-bin-release.zip
unzip rocketmq-all-4.6.0-bin-release.zip
mv rocketmq-all-4.6.0-bin-release.zip  /data/rocketmq
# tree rocketmq
rocketmq-all-4.6.0-bin-release
├── LICENSE
├── NOTICE
├── README.md
├── benchmark
│   ├── consumer.sh
│   ├── producer.sh
│   ├── runclass.sh
│   └── tproducer.sh
├── bin
│   ├── README.md
│   ├── cachedog.sh
│   ├── cleancache.sh
│   ├── cleancache.v1.sh
│   ├── dledger
│   │   └── fast-try.sh
│   ├── mqadmin
│   ├── mqadmin.cmd
│   ├── mqbroker
│   ├── mqbroker.cmd
│   ├── mqbroker.numanode0
│   ├── mqbroker.numanode1
│   ├── mqbroker.numanode2
│   ├── mqbroker.numanode3
│   ├── mqnamesrv
│   ├── mqnamesrv.cmd
│   ├── mqshutdown
│   ├── mqshutdown.cmd
│   ├── os.sh
│   ├── play.cmd
│   ├── play.sh
│   ├── runbroker.cmd
│   ├── runbroker.sh
│   ├── runserver.cmd
│   ├── runserver.sh
│   ├── setcache.sh
│   ├── startfsrv.sh
│   ├── tools.cmd
│   └── tools.sh
├── conf
│   ├── 2m-2s-async
│   │   ├── broker-a-s.properties
│   │   ├── broker-a.properties
│   │   ├── broker-b-s.properties
│   │   └── broker-b.properties
│   ├── 2m-2s-sync
│   │   ├── broker-a-s.properties
│   │   ├── broker-a.properties
│   │   ├── broker-b-s.properties
│   │   └── broker-b.properties
│   ├── 2m-noslave
│   │   ├── broker-a.properties
│   │   ├── broker-b.properties
│   │   └── broker-trace.properties
│   ├── broker.conf
│   ├── dledger
│   │   ├── broker-n0.conf
│   │   ├── broker-n1.conf
│   │   └── broker-n2.conf
│   ├── logback_broker.xml
│   ├── logback_namesrv.xml
│   ├── logback_tools.xml
│   ├── plain_acl.yml
│   └── tools.yml
└── lib
    ├── commons-beanutils-1.9.2.jar
    ├── commons-cli-1.2.jar
    ├── commons-codec-1.9.jar
    ├── commons-collections-3.2.2.jar
    ├── commons-digester-1.8.1.jar
    ├── commons-lang3-3.4.jar
    ├── commons-logging-1.2.jar
    ├── commons-validator-1.6.jar
    ├── dledger-0.1.jar
    ├── fastjson-1.2.61.jar
    ├── guava-19.0.jar
    ├── javassist-3.20.0-GA.jar
    ├── jcommander-1.72.jar
    ├── jna-4.2.2.jar
    ├── logback-classic-1.0.13.jar
    ├── logback-core-1.0.13.jar
    ├── netty-all-4.0.42.Final.jar
    ├── netty-tcnative-boringssl-static-1.1.33.Fork26.jar
    ├── openmessaging-api-0.3.1-alpha.jar
    ├── rocketmq-acl-4.6.0.jar
    ├── rocketmq-broker-4.6.0.jar
    ├── rocketmq-client-4.6.0.jar
    ├── rocketmq-common-4.6.0.jar
    ├── rocketmq-example-4.6.0.jar
    ├── rocketmq-filter-4.6.0.jar
    ├── rocketmq-logging-4.6.0.jar
    ├── rocketmq-namesrv-4.6.0.jar
    ├── rocketmq-openmessaging-4.6.0.jar
    ├── rocketmq-remoting-4.6.0.jar
    ├── rocketmq-srvutil-4.6.0.jar
    ├── rocketmq-store-4.6.0.jar
    ├── rocketmq-tools-4.6.0.jar
    ├── slf4j-api-1.7.7.jar
    └── snakeyaml-1.19.jar

9 directories, 89 files

二、集群配置

注意:需要关闭防火墙和selinux

服务器 ip 安装的服务 配置文件
node1 10.3.55.134 Broker,NameServer /data/rocketmq/conf/2m-noslave/broker-a.properties
node2 10.3.55.135 Broker,NameServer /data/rocketmq/conf/2m-noslave/broker-b.properties
node3 10.3.55.136 Broker,NameServer /data/rocketmq/conf/2m-noslave/broker-c.properties

由于是三主配置,所以配置文件修改如下:

Node1:

brokerIP1=10.3.55.134
brokerIP2=10.3.55.134
brokerClusterName=rocketmq-cluster
brokerName=broker-a
brokerId=0
namesrvAddr=10.3.55.134:9876;10.3.55.135:9876;10.3.55.136:9876
defaultTopicQueueNums=4
deleteWhen=04
fileReservedTime=120
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
listenPort=10911
storePathRootDir=/data/rocketmq/store-a
messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88

Node2:

brokerIP1=10.3.55.135
brokerIP2=10.3.55.135
brokerClusterName=rocketmq-cluster
brokerName=broker-b
brokerId=1
namesrvAddr=10.3.55.134:9876;10.3.55.135:9876;10.3.55.136:9876
defaultTopicQueueNums=4
deleteWhen=04
fileReservedTime=120
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
listenPort=10911
storePathRootDir=/data/rocketmq/store-b
messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88

Node3:

brokerIP1=10.3.55.136
brokerIP2=10.3.55.136
brokerClusterName=rocketmq-cluster
brokerName=broker-c
brokerId=2
namesrvAddr=10.3.55.134:9876;10.3.55.135:9876;10.3.55.136:9876
defaultTopicQueueNums=4
deleteWhen=04
fileReservedTime=120
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
listenPort=10911
storePathRootDir=/data/rocketmq/store-c
messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88

参数说明:

参数名 默认值 说明
listenPort 10911 接受客户端连接的监听端口
namesrvAddr null nameServer 地址
brokerIP1 网卡的 InetAddress 当前 broker 监听的 IP
brokerIP2 跟 brokerIP1 一样 存在主从 broker 时,如果在 broker 主节点上配置了 brokerIP2 属性,broker 从节点会连接主节点配置的 brokerIP2 进行同步
brokerName null broker 的名称
brokerClusterName DefaultCluster 本 broker 所属的 Cluser 名称
brokerId 0 broker id, 0 表示 master, 其他的正整数表示 slave
storePathCommitLog $HOME/store/commitlog/ 存储 commit log 的路径
storePathConsumerQueue $HOME/store/consumequeue/ 存储 consume queue 的路径
mappedFileSizeCommitLog 1024 * 1024 * 1024(1G) commit log 的映射文件大小
deleteWhen 04 在每天的什么时间删除已经超过文件保留时间的 commit log
fileReservedTime 72 以小时计算的文件保留时间
brokerRole ASYNC_MASTER SYNC_MASTER/ASYNC_MASTER/SLAVE
flushDiskType ASYNC_FLUSH SYNC_FLUSH/ASYNC_FLUSH SYNC_FLUSH 模式下的 broker 保证在收到确认生产者之前将消息刷盘。ASYNC_FLUSH 模式下的 broker 则利用刷盘一组消息的模式,可以取得更好的性能。
enableDLegerCommitLog true 是否启动 DLedger
dLegerGroup RaftNode00 DLedger Raft Group的名字,建议和 brokerName 保持一致
dLegerPeers n0-127.0.0.1:40911;n1-127.0.0.1:40912;n2-127.0.0.1:40913 DLedger Group 内各节点的端口信息,同一个 Group 内的各个节点配置必须要保证一致
dLegerSelfId n0 节点 id, 必须属于 dLegerPeers 中的一个;同 Group 内各个节点要唯一
sendMessageThreadPoolNums 16 发送线程个数,建议配置成 Cpu 核数

三、集群启动

# node1
nohup sh bin/mqnamesrv > nohubNameserv &
nohup sh bin/mqbroker  > nohubBroker -c conf/2m-noslave/broker-a.properties &

# node2
nohup sh bin/mqnamesrv > nohubNameserv &
nohup sh bin/mqbroker  > nohubBroker -c conf/2m-noslave/broker-b.properties &

# node3
nohup sh bin/mqnamesrv > nohubNameserv &
nohup sh bin/mqbroker  > nohubBroker -c conf/2m-noslave/broker-c.properties &

四、查看集群状态

[root@localhost rocketmq]# sh bin/mqadmin clusterList -n 127.0.0.1:9876
RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.PlatformDependent0).
RocketMQLog:WARN Please initialize the logger system properly.
#Cluster Name     #Broker Name            #BID  #Addr                  #Version                #InTPS(LOAD)       #OutTPS(LOAD) #PCWait(ms) #Hour #SPACE
rocketmq-cluster  broker-a                0     10.3.55.134:10911      V4_6_0                   0.00(0,0ms)         0.00(0,0ms)          0 457977.21 -1.0000
rocketmq-cluster  broker-b                0     10.3.55.135:10911      V4_6_0                   0.00(0,0ms)         0.00(0,0ms)          0 457977.21 -1.0000
rocketmq-cluster  broker-c                0     10.3.55.136:10911      V4_6_0                   0.00(0,0ms)         0.00(0,0ms)          0 457977.21 -1.0000

如果执行上面的命令出现以下错误

RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.PlatformDependent0).
RocketMQLog:WARN Please initialize the logger system properly.
org.apache.rocketmq.tools.command.SubCommandException: ClusterListSubCommand command failed
	at org.apache.rocketmq.tools.command.cluster.ClusterListSubCommand.execute(ClusterListSubCommand.java:93)
	at org.apache.rocketmq.tools.command.MQAdminStartup.main0(MQAdminStartup.java:139)
	at org.apache.rocketmq.tools.command.MQAdminStartup.main(MQAdminStartup.java:90)
Caused by: org.apache.rocketmq.acl.common.AclException: [10015:signature-failed] unable to calculate a request signature. error=[10015:signature-failed] unable to calculate a request signature. error=Algorithm HmacSHA1 not available
	at org.apache.rocketmq.acl.common.AclSigner.signAndBase64Encode(AclSigner.java:84)
	at org.apache.rocketmq.acl.common.AclSigner.calSignature(AclSigner.java:73)
	at org.apache.rocketmq.acl.common.AclSigner.calSignature(AclSigner.java:68)
	at org.apache.rocketmq.acl.common.AclUtils.calSignature(AclUtils.java:69)
	at org.apache.rocketmq.acl.common.AclClientRPCHook.doBeforeRequest(AclClientRPCHook.java:44)
	at org.apache.rocketmq.remoting.netty.NettyRemotingAbstract.doBeforeRpcHooks(NettyRemotingAbstract.java:172)
	at org.apache.rocketmq.remoting.netty.NettyRemotingClient.invokeSync(NettyRemotingClient.java:368)
	at org.apache.rocketmq.client.impl.MQClientAPIImpl.getBrokerClusterInfo(MQClientAPIImpl.java:1337)
	at org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl.examineBrokerClusterInfo(DefaultMQAdminExtImpl.java:306)
	at org.apache.rocketmq.tools.admin.DefaultMQAdminExt.examineBrokerClusterInfo(DefaultMQAdminExt.java:251)
	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
Caused by: org.apache.rocketmq.acl.common.AclException: [10015:signature-failed] unable to calculate a request signature. error=Algorithm HmacSHA1 not available
	at org.apache.rocketmq.acl.common.AclSigner.sign(AclSigner.java:63)
	at org.apache.rocketmq.acl.common.AclSigner.signAndBase64Encode(AclSigner.java:79)
	... 13 more
Caused by: java.security.NoSuchAlgorithmException: Algorithm HmacSHA1 not available
	at javax.crypto.Mac.getInstance(Mac.java:181)
	at org.apache.rocketmq.acl.common.AclSigner.sign(AclSigner.java:57)
	... 14 more

解决方案:

确认自己的$JAVA_HOME/lib/ext目录下存在sunjce_provider.jar文件

打开/data/rocketmq/bin/tools.sh

#===========================================================================================
# JVM Configuration
#===========================================================================================
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m"
#JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${BASE_DIR}/lib:${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext"
# 修改为以下内容
JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${BASE_DIR}/lib:${JAVA_HOME}/jre/lib/ext:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64/jre/lib/ext"
JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"

启动内存不够

修改 bin/runbroker.shbin/runserver.sh 中的

JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g

将参数调低 (可以改为别的值)

JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m"