RocketMQ安装(单机)

如果服务器内存紧张  可以缩小到300m

官网:RocketMQ · 官方网站 | RocketMQ

需要服务器先有JDK环境

下载二进制的

解压

unzip rocketmq-all-5.3.0-bin-release.zip 

cd rocketmq-all-5.3.0-bin-release/

pwd

复制下路径 /usr/local/develop/rocketmq-all-5.3.0-bin-release

配置环境变量

vim /etc/profile

export JAVA_HOME=/usr/local/develop/jdk1.8.0_191
export ROCKETMQ_HOME=/usr/local/develop/rocketmq-all-5.3.0-bin-release

export PATH=$JAVA_HOME/bin:$ROCKETMQ_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib

# nameserver注册中心可以配置多个;隔开
export NAMESRV_ADDR=127.0.0.1:9876

让环境变量生效

source /etc/profile

下面启动nameserver注册中心  和 broke

RcoketMQ默认预设的JVM内存是4G,也是RocketMQ的最佳配置,如果内存不够,需要修改下runserver.sh

cd /usr/local/develop/rocketmq-all-5.3.0-bin-release/bin

vim runserver.sh

设置成512m

启动 nameserver

nohup ./mqnamesrv &      有时候 nohup ./mqnamesrv -n 172.16.253.2:9876 & 也一样的 -n后面的IP就是意思通过这个IP可以找到我的意思

最好用

nohup ./mqnamesrv > namesrv.log 2>&1 &    不然下次执行nohup    nohup.out 覆盖

tail -f nohup.out                                      tail -f namesrv.log

关闭nameserver两种方式   

1.ps -ef|grep mp

kill -9 16740

2.脚本关闭

./mqshutdown namesrv

启动 broke服务

Broke脚本是runbroker.sh  默认预设内存是8G  

vim runbroker.sh

另外还需要修改broke的配置文件

vim /usr/local/develop/rocketmq-all-5.3.0-bin-release/conf/broker.conf

注释

额外加上  enablePropertyFilter=true

# 集群名称
brokerClusterName = DefaultCluster

# Broker 名称,集群内唯一
brokerName = broker-a

# Broker ID, 0 表示主节点
brokerId = 0

# 删除过期文件的时间(每天凌晨4点)
deleteWhen = 04

# 文件保留时间(小时)
fileReservedTime = 48

# Broker 角色(异步主节点)
brokerRole = ASYNC_MASTER

# 异步刷盘模式
flushDiskType = ASYNC_FLUSH

# 允许自动创建 Topic
autoCreateTopicEnable=true

# NameServer 地址,多个地址用分号分隔
namesrvAddr=127.0.0.1:9876
# 启用 ACL  这样就需要配置plain_acl.yml
#aclEnable=true
#这是启用 SQL92 过滤的关键配置
enablePropertyFilter=true

指定配置文件启动  其实不指定好像默认也是用的这个配置

nohup ./mqbroker -c ../conf/broker.conf &  或者 nohup ./mqbroker -c ../conf/broker.conf  -n 127.0.0.1:9876 &   意思这个broker注册到本机的9876端口的nameserver上面  其实-c ../conf/broker.conf可以不指定  默认就是  如果是集群 IP就是可以访问到nameserver的IP

最好用

nohup ./mqbroker -c ../conf/broker.conf > broker.log 2>&1 &      不然下次执行nohup    nohup.out 覆盖

tail -f nohup.out                     tail -f broker.log

测试MQ发送消息

export NAMESRV_ADDR='127.0.0.1:9876'      指定nameserver地址

./tools.sh org.apache.rocketmq.example.quickstart.Producer        测试会发送1000条数据

回车

意思内存不足

./tools.sh -Xms256m -Xmx256m org.apache.rocketmq.example.quickstart.Producer

测试接收消息

export NAMESRV_ADDR='localhost:9876'
./tools.sh org.apache.rocketmq.example.quickstart.Consumer

同样是内存不足  可怜兮兮

./tools.sh -Xms256m -Xmx256m org.apache.rocketmq.example.quickstart.Consumer

按ctrl+c退出

关闭最好先关闭broke

sh ./mqshutdown broker       说明   ./mqshutdown broker   需要有执行权限

关闭nameserver

sh ./mqshutdown namesrv

ACL访问控制列表

conf/broker.conf中配置    aclEnable=true

# 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
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#  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 = DefaultCluster
#brokerName = broker-a
#brokerId = 0
#deleteWhen = 04
#fileReservedTime = 48
#brokerRole = ASYNC_MASTER
#flushDiskType = ASYNC_FLUSH
# 集群名称
brokerClusterName = DefaultCluster

# Broker 名称,集群内唯一
brokerName = broker-a

# Broker ID, 0 表示主节点
brokerId = 0

# 删除过期文件的时间(每天凌晨4点)
deleteWhen = 04

# 文件保留时间(小时)
fileReservedTime = 48

# Broker 角色(异步主节点)
brokerRole = ASYNC_MASTER

# 异步刷盘模式
flushDiskType = ASYNC_FLUSH

# 允许自动创建 Topic
autoCreateTopicEnable=true

# NameServer 地址,多个地址用分号分隔
namesrvAddr=127.0.0.1:9876
# 启用 ACL  这样就需要配置plain_acl.yml
aclEnable=true
#这是启用 SQL92 过滤的关键配置
enablePropertyFilter=true

开启aclEnable=true之后

plain_acl.yml

# 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
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#  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.

# 全局白名单地址
#globalWhiteRemoteAddresses:
#  - 10.10.103.*
#  - 192.168.0.*

# 账户列表
#accounts:
#  - accessKey: RocketMQ # 访问密钥
#    secretKey: 12345678 # 秘密密钥
#    whiteRemoteAddress: # 允许访问的远程地址
#    admin: false # 是否为管理员
#    defaultTopicPerm: DENY # 默认主题权限(DENY、PUB 或 SUB)
#    defaultGroupPerm: SUB # 默认消费组权限(DENY、PUB 或 SUB)
#    topicPerms: # 特定主题的权限
#      - topicA=DENY # 拒绝访问 topicA
#      - topicB=PUB|SUB # 允许发布和订阅 topicB
#      - topicC=SUB # 只允许订阅 topicC
#    groupPerms: # 特定消费组的权限
#      # 消费组应该转换为重试主题
#      - groupA=DENY # 拒绝访问 groupA
#      - groupB=PUB|SUB # 允许发布和订阅 groupB
#      - groupC=SUB # 只允许订阅 groupC

#  - accessKey: rocketmq2 # 访问密钥
#    secretKey: 12345678 # 秘密密钥
#    whiteRemoteAddress: 192.168.1.* # 允许访问的远程地址
#    # 如果是管理员账户,它可以访问所有资源
#    admin: true # 是否为管理员

# 全局白名单地址
globalWhiteRemoteAddresses:
# 账户列表
accounts:
  - accessKey: xxxxxx # 管理员访问密钥
    secretKey: xxxxxxx # 管理员秘密密钥
    whiteRemoteAddress: # 允许访问的远程地址
    admin: true # 设置为管理员账户
    defaultTopicPerm: PUB # 默认主题权限(允许发布和创建主题)DENY(拒绝)
    defaultGroupPerm: SUB # 默认消费组权限(允许订阅)DENY(拒绝)

    
 

生产者

//访问权限
public static RPCHook getAclRPCHook(){
    return new AclClientRPCHook(new SessionCredentials("xxxxxx","xxxxxx"));
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hrui0706

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值