0.设置host(多(三台机器)master)

192.168.0.223 rocketmq-nameserver223
 192.168.0.223 rocketmq-master223
 192.168.0.224 rocketmq-nameserver224
 192.168.0.224 rocketmq-master224
 192.168.0.225 rocketmq-nameserver225
 192.168.0.225 rocketmq-master225

1.安装jdk:

2.源码安装和非源码安装的区别是,非源码安装不需要要maven,直接通过编译包:
把rocketmq-all-4.2.0-bin-release.zip文件上传到/usr/local/rocketmq-source/rocketmq-all-4.2.0/distribution/target

3.解压到apache-rocketmq目录下:
unzip rocketmq-all-4.2.0-bin-release.zip -d apache-rocketmq

4.修改/usr/local/rocketmq-source/rocketmq-all-4.2.0/distribution/target/apache-rocketmq/bin
目录下runbroker.sh和runserver.sh中java启动内存改小点,不然启动不了,因为这两个服务的默认内存是4g和4g

修改配置文件,broker-c.properties没有就复制一个

vi /usr/local/rocketmq-source/rocketmq-all-4.2.0/distribution/target/apache-rocketmq/conf/2m-noslave/broker-a.properties
 vi /usr/local/rocketmq-source/rocketmq-all-4.2.0/distribution/target/apache-rocketmq/conf/2m-noslave/broker-b.properties
 vi /usr/local/rocketmq-source/rocketmq-all-4.2.0/distribution/target/apache-rocketmq/conf/2m-noslave/broker-c.properties


用下面替换原有文件的内容(只需要修改对应的broker-a|b|c)
########################################################
#所属集群名字

brokerClusterName=DefaultCluster
#broder名字,注意这里不同的配置文件配置不一样
 brokerName=broker-a#0表示master,>0表示slave
 brokerId=0#nameServer地址,分号分隔
 namesrvAddr=rocketmq-nameserver223:9876;rocketmq-nameserver224:9876;rocketmq-nameserver225:9876#发送消息时自动撞见服务器不存在的topic,默认创建的队列数
 defaultTopicQueueNums=4#是否允许broker自动创建Topic,建议线下开启,线上关闭
 autoCreateTopicEnable=true#是否允许broker自动创建订阅组,建议线下开启,线上关闭
 autoCreateSubscriptionGroup=true#broker对外服务的监听端口
 listenPort=10911#删除文件时间点,默认凌晨4点
 deleteWhen=04#文件默认保留时间,默认48小时
 fileReservedTime=48#borker角色:ASYNC_MASTER-异步复制master;SYNC_MASTER-同步双写master;SLAVE
 brokerRole=ASYNC_MASTER#刷盘方式:ASYNC_FLUSH-异步刷盘,SYNC_FLUSH同步刷盘
 flushDiskType=ASYNC_FLUSH#commitLog每个文件的大小默认1G
 mapedFileSizeCommitLog=1073741824#ConsumeQueue每个文件默认存30W条,根据业务情况调整
 mapedFileSizeConsumeQueue=300000
 #destroyMapedFileIntervalForcibly=120000
 #redeleteHangedFileInterval=120000#检测物理文件磁盘空间
 diskMaxUsedSpaceRatio=88#存储路径
 #storePathRootDir=/usr/local/rocketmq/store#commitLog 存储路径
 #storePathCommitLog=/usr/local/rocketmq/store/commitlog#消费队列存储路径存储路径
 #storePathConsumeQueue=/usr/local/rocketmq/store/consumequeue#消息索引存储路径
 #storePathIndex=/usr/local/rocketmq/store/index#checkpoint 文件存储路径
 #storeCheckpoint=/usr/local/rocketmq/store/checkpoint#abort 文件存储路径
 #abortFile=/usr/local/rocketmq/store/abort#限制的消息大小
 maxMessageSize=65536
 #flushCommitLogLeastPages=4
 #flushConsumeQueueLeastPages=2
 #flushCommitLogThoroughInterval=10000
 #flushConsumeQueueThoroughInterval=60000

########################################################

4.Start Name Server(先启动所有的nameServer然后在启动borker,如果停止的话顺序需要反过来)

nohup sh /usr/local/rocketmq-source/rocketmq-all-4.2.0/distribution/target/apache-rocketmq/bin/mqnamesrv &
 tail -f ~/logs/rocketmqlogs/namesrv.log
 结果The Name Server boot success...
 停止命令:
 sh /usr/local/rocketmq-source/rocketmq-all-4.2.0/distribution/target/apache-rocketmq/bin/mqshutdown namesrv5.Start Broker(三个机器启动borker分别指定a|b|c配置文件)
 nohup sh /usr/local/rocketmq-source/rocketmq-all-4.2.0/distribution/target/apache-rocketmq/bin/mqbroker -c /usr/local/rocketmq-source/rocketmq-all-4.2.0/distribution/target/apache-rocketmq/conf/2m-noslave/broker-a.properties &
 tail -f ~/logs/rocketmqlogs/broker.log 
 结果The broker[%s, 172.30.30.233:10911] boot success...
 停止命令:
 sh /usr/local/rocketmq-source/rocketmq-all-4.2.0/distribution/target/apache-rocketmq/bin/mqshutdown broker设置开机启动
 vi /etc/rc.local
 su - root -c 'nohup sh /usr/local/rocketmq-source/rocketmq-all-4.2.0/distribution/target/apache-rocketmq/bin/mqnamesrv &'
 su - root -c 'nohup sh /usr/local/rocketmq-source/rocketmq-all-4.2.0/distribution/target/apache-rocketmq/bin/mqbroker -n localhost:9876 &'配置环境变量:
 vi /etc/profileexport ROCKETMQ_HOME=/usr/local/rocketmq-source/rocketmq-all-4.2.0/distribution/target/apache-rocketmq
 PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$ROCKETMQ_HOME/bin:$PATH
 export NAMESRV_ADDR=192.168.0.XXX:9876source /etc/profile
5.5放开9876端口,以及下面管控台需要用到的12581端口
 vi /etc/sysconfig/iptables
 -A INPUT -m state --state NEW -m tcp -p tcp --dport 12581 -j ACCEPT
 -A INPUT -m state --state NEW -m tcp -p tcp --dport 9876 -j ACCEPT
 -A INPUT -m state --state NEW -m tcp -p tcp --dport 10911 -j ACCEPT
 -A INPUT -m state --state NEW -m tcp -p tcp --dport 10909 -j ACCEPTservice iptables restart

6.安装控制台(界面)
上传rocketmq-console-ng-1.0.0.jar到上面其中一台服务器的/home/rocket-mq-console目录中
进入目录执行(如果有源码可以修改配置文件在打包,通过以下命令运行):

nohup java -jar /home/rocket-mq-console/rocketmq-console-ng-1.0.0.jar &
设置开机启动
 vi /etc/rc.local
 su - root -c 'nohup java -jar /home/rocket-mq-console/rocketmq-console-ng-1.0.0.jar &'

备注:有时候可能会出现有新加进去的节点接收不到消息,尝试下关闭其他节点,剩下新节点后是否能接收到消息

通过jps命令可以查看其对应的java进程

6.如何清空rocketMQ数据:
停止nameserver和broker服务:先停止broker再停止nameserver
然后清空store目录,然后在新建对应的目录,默认在用户根目录下,如/root/store

cd /root
 cp -r store store_backup
 rm -rf store
 mkdir store
 mkdir store/commitlog
 mkdir store/consumequeue
 mkdir store/index