文章目录
目录
参考地址:
RocketMQ环境准备
- RedHat & CentOS7
- JDK1.8+
- RocketMQ 4.3.0
搭建单Master
序号 | Ip | 用户名 | 密码 | 角色 | 模式 |
---|---|---|---|---|---|
1 | 192.168.8.246 | root | **** | nameServer1,brokerServer1 | Master1 |
修改hosts
vim /etc/hosts
192.168.8.246 rocketmq-master1
192.168.8.246 rocketmq-nameserver1
上传与解压
00:29:25
mkdir -p /opt/software && cd /opt/software/
rz -be # 上传
unzip /opt/software/rocketmq-all-4.3.0-bin-release.zip && mv rocketmq-all-4.3.0-bin-release /usr/local/apache-rocketmq
ln -s /usr/local/apache-rocketmq /usr/local/rocketmq # 建立软连接
创建存储路径
# 数据存储位置
mkdir /usr/local/rocketmq/store
# 真正存储rocketmq的数据,生产者就是发到这里
mkdir /usr/local/rocketmq/store/commitlog
# 类似数据库索引
mkdir /usr/local/rocketmq/store/consumequeue
# 快速查询rocketmq消息
mkdir /usr/local/rocketmq/store/index
单点的RocketMQ配置文件
良好习惯,备份
cp /usr/local/rocketmq/conf/2m-2s-async/broker-a.properties /usr/local/rocketmq/conf/2m-2s-async/broker-a.properties.bak
清空文件,然后黏贴下面配置进去 00:35:00
vim /usr/local/rocketmq/conf/2m-2s-async/broker-a.properties
#所属集群名字
brokerClusterName=rocketmq-cluster
#broker 名字,注意此处不同的配置文件填写的不一样
brokerName=broker-a
#0 表示 Master,>0 表示 Slave
brokerId=0
#nameServer 地址,分号分割
#namesrvAddr=rocketmq-nameserver1:9876
namesrvAddr=192.168.8.246:9876
#在发送消息时,自动创建服务器不存在的 topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建 Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口
listenPort=10911
#删除文件时间点,默认凌晨 4 点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=120
#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
#Broker 的角色
#- ASYNC_MASTER 异步复制 Master
#- SYNC_MASTER 同步双写 Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128
# 多网卡情况下必需指定,不然有可能选择其他网卡导致连接失败
brokerIP1=192.168.8.246
nameServer地址对应hosts的, 或者填写内网IP,那就可以无视hosts配置
End 00:37:03
测试
[eddie@tracker bin]# sh mqadmin clusterList -n localhost: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
rocketmq-cluster broker-a 0 192.168.8.246:10911 V4_3_0 0.00(0,0ms) 0.00(0,0ms) 0 451451.84 0.5355
修改日志配置文件
mkdir -p /usr/local/rocketmq/logs
cd /usr/local/rocketmq/conf && sed -i 's#${user.home}#/usr/local/rocketmq#g' *.xml
修改启动脚本参数
vim /usr/local/rocketmq/bin/runbroker.sh
最低配:
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn1g"
JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=2g"
vim /usr/local/rocketmq/bin/runserver.sh
最低配:
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
后台启动 NameServer
cd /usr/local/rocketmq/bin
nohup sh mqnamesrv -n 192.168.8.246:9876 &
jps
后台启动 BrokerServer A
cd /usr/local/rocketmq/bin
nohup sh mqbroker -n 192.168.8.246:9876 -c /usr/local/rocketmq/conf/2m-2s-async/broker-a.properties >/dev/null 2>&1 &
jps
以上两种方式如果不行,可以尝试
sh mqnamesrv -n rocketmq-nameserver1:9876
sh mqbroker -n rocketmq-nameserver1:9876 -c /usr/local/rocketmq/conf/2m-2s-async/broker-a.properties autoCreateTopicEnable=true
查看日志
tail -f -n 300 /usr/local/rocketmq/logs/rocketmqlogs/namesrv.log
tail -f -n 300 /usr/local/rocketmq/logs/rocketmqlogs/broker.log
这步操作可以忽略,但是刚刚时候使用了错的版本,导致一直连接不上。最后靠日志寻找到问题
如果自己开发玩下,记得关防火墙:systemctl stop firewalld.service
发送消息与接收消息 (如果一切正常就不用这一步)
# 发送消息
export NAMESRV_ADDR=192.168.8.108:9876
sh /usr/local/rocketmq/bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
# 接受消息
sh /usr/local/rocketmq/bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
RocketMQ - 控制台介绍
- RocketMQ 扩展组件
- https://github.com/apache/rocketmq-externals/tree/master
- 控制台使用:直接引入工程后,修改配置文件即可
- git clone https://github.com/apache/rocketmq-externals.git
RocketMQ - Docket
运行Docker
docker run -e "JAVA_OPTS=-Drocketmq.namesrv.addr=192.168.8.246:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" -p 8080:8080 -t styletang/rocketmq-console-ng
启动与访问
- IDEA 启动项目
- http://localhost:8080