RocketMQ是一款分布式、队列模型的消息中间件,具有以下特点
在WMWare虚拟机下实现,实现两台IP和资源的服务主机,IP分别是 192.168.1.12,192.168.1.13,分别在这两台机器的hosts文件中添加。
vim /etc/hosts
192.168.1.12 rocketmq-nameserver1
192.168.1.12 rocketmq-master1
192.168.1.13 rocketmq-nameserver2
192.168.1.13 rocketmq-master2
复制代码
分别将alibaba-rocketmq-x.x.x.tar.gz使用rz命令上传到两台机器,也可以直接官网在线下载。
将RocketMq解压到/usr/local目录下:
root@localhost local]
复制代码
建立alibaba-rocketmq到rocketmq软连接,如下:
[root@localhost local]
复制代码
[root@localhost local]
[root@localhost local]
[root@localhost local]
[root@localhost local]
复制代码
分别配置两台机器的broker-a.properties和broker-b.properties文件
[root@localhost local]
brokerClusterName=rocketmq-cluster
brokerName=broker-a
brokerId=0
namesrvAddr=rocketmq-nameserver1:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10911
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
storePathRootDir= /usr/local/rocketmq/store
storePathCommitLog= /usr/local/rocketmq/store/commitlog
storePathConsumeQueue=/usr/local/rocketmq/store/consumequeue
storePathIndex=/usr/local/rocketmq/store/index
storeCheckpoint=/usr/local/rocketmq/store/checkpoint
abortFile=/usr/local/rocketmq/store/abort
maxMessageSize=65536
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
复制代码
[root rocketmq]# cd /usr/local/rocketmq/bin/
[root bin]# nohup sh mqnamesrv &
复制代码
cd /usr/local/rocketmq/bin
[root bin]# nohup sh mqbroker -c /usr/local/rocketmq/conf/2m-noslave/broker-a.properties >/dev/null 2>&1 &
[root bin]# tail -f -n 500 /usr/local/rocketmq/logs/rocketmqlogs/broker.log
复制代码
首先下载rocketmq-console.war和tomcat(地址github.com/apache/rock…
修改config.properties文件
rocketmq.namesrv.addr=192.168.1.12:9876
throwDone=true
复制代码
启动Tomcat,访问 http://192.168.1.128:8080/rocketmq-console
export NAMESRV_ADDR=192.168.169.128:9876\;192.168.169.129:9876
bash tools.sh com.alibaba.rocketmq.example.quickstart.Producer
bash tools.sh com.alibaba.rocketmq.example.quickstart.Consumer
复制代码
[]
[]
复制代码
如果是centos7以上使用
systemctl stop firewalld.service
复制代码
updateTopic -b 192.168.0.1:10911 -c RocketMq-Cluster -n 192.168.0.1:9876;192.168.0.2:9876 -t order-topic
复制代码
deleteTopic -c RocketMq-Cluster -n 192.168.0.1:9876;192.168.0.2:9876 -t order-topic
复制代码
订阅组名称
updateSubGroup -b 192.168.0.1:10911 -c RocketMq-Cluster -g subGroupName -n 192.168.0.1:9876;192.168.0.2:9876
复制代码
deleteSubGroup -b 192.168.0.1:10911 -c RocketMq-Cluster -g subGroupName -n 192.168.0.1:9876;192.168.0.2:9876
复制代码
某些配置文件broker运行的时候可以动态修改,-k broker配置文件的key -v value
updateBrokerConfig -b 192.168.0.1:10911 -c RocketMq-Cluster -n 192.168.0.1:9876;192.168.0.2:9876 -k deleteWhen -v 05
复制代码
updateTopicPerm -b 192.168.0.1:10911 -c RocketMq-Cluster -n 192.168.0.1:9876;192.168.0.2:9876 -t order-topic
复制代码
TopicRoute -b 192.168.0.1:10911 -c RocketMq-Cluster -n 192.168.0.1:9876;192.168.0.2:9876 -t order-topic
复制代码
TopicList -n 192.168.0.1:9876;192.168.0.2:9876
复制代码
TopicStats -t order_topic -n 192.168.0.1:9876;192.168.0.2:9876
复制代码
printMsg -t order_topic -n 192.168.0.1:9876;192.168.0.2:9876
复制代码
queryMsgById -i msgId -n -n 192.168.0.1:9876;192.168.0.2:9876
复制代码
clusterList -n 192.168.0.1:9876;192.168.0.2:9876
复制代码
如果没有安装中文语言包,出现乱码了,可以通过
[root@localhost local]
复制代码
可以修改两台机器的日志配置文件并且把conf目录下所有xml文件中的${user.home}替换为/usr/local/rocketmq
[root@localhost rocketmq]# mkdir -p /usr/local/rocketmq/logs
[root@localhost rocketmq]# cd /usr/local/rocketmq/conf && sed -i 's#${user.home}#/usr/local/rocketmq#g' *.xml
复制代码
分别修改两台机器的rocketmq启动脚本
[root rocketmq]# vim /usr/local/rocketmq/bin/runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn800g -XX:PermSize=128m -XX:MaxPermSize=320m"
JAVA_OPT="${JAVA_OPT} -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 -XX:+DisableExplicitGC"
JAVA_OPT="${JAVA_OPT} -verbose:gc -Xloggc:${HOME}/rmq_bk_gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps"
JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow"
JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${BASE_DIR}/lib"
#JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n"
JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"
复制代码