在各种bug与爆炸的情况下, 终于把环境搭建好了, 特此记录
配置环境变量
在 /etc/profile中进行修改
修改完立刻生效
source /etc/profile
执行完后只是在当前窗口可见, 要修改完毕还是要重启电脑
在这里面写的环境变量可以通过
Echo $JAVA_HOME
Echo $ROCKETMQ_HOME
获取对应位置
在host中添加信息
# rocketnameserver
192.168.33.130 rocketmq-nameserver1
192.168.33.131 rocketmq-nameserver2
# rocket broker
192.168.33.130 rocketmq-master1
192.168.33.130 rocketmq-slave2
192.168.33.131 rocketmq-master2
192.168.33.131 rocketmq-slave1
然后重置网卡
systemctl restart NetworkManager
注意网上大多数的重置命令已经过时, 在ubuntu18版本后全部只支持使用systemctl restart NetworkManager命令重置网卡
然后检查并关闭防火墙
sudo ufw status
显示未活动就是没有启动
开发时也不需要启动…
添加store存储目录
就是设置commitlog的存储位置
还有其他消息存储位置
根目录下自定义路径即可
192.168.33.130的虚拟机
sudo mkdir -p /usr/local/rocketmq/store/broker-a
sudo mkdir -p /usr/local/rocketmq/store/broker-a/commitlog
sudo mkdir -p /usr/local/rocketmq/store/broker-a/consumequeue
sudo mkdir -p /usr/local/rocketmq/store/broker-a/index
sudo mkdir -p /usr/local/rocketmq/store/broker-b-s
sudo mkdir -p /usr/local/rocketmq/store/broker-b-s/commitlog
sudo mkdir -p /usr/local/rocketmq/store/broker-b-s/consumequeue
sudo mkdir -p /usr/local/rocketmq/store/broker-b-s/index
192.168.33.131的虚拟机
sudo mkdir -p /usr/local/rocketmq/store/broker-b
sudo mkdir -p /usr/local/rocketmq/store/broker-b/commitlog
sudo mkdir -p /usr/local/rocketmq/store/broker-b/consumequeue
sudo mkdir -p /usr/local/rocketmq/store/broker-b/index
sudo mkdir -p /usr/local/rocketmq/store/broker-a-s
sudo mkdir -p /usr/local/rocketmq/store/broker-a-s/commitlog
sudo mkdir -p /usr/local/rocketmq/store/broker-a-s/consumequeue
sudo mkdir -p /usr/local/rocketmq/store/broker-a-s/index
环境配置
在/usr/local/rocketmq/rocketmq-all-4.9.0-bin-release/conf的properties文件中进行配置
192.168.33.130的虚拟机a
broker_a.properties
# 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=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端口
listenPort=10910
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#nameServer地址,分号分割
namesrvAddr=192.168.33.130:9876;192.168.33.131:9876
#存储路径
storePathRootDir=/usr/local/rocketmq/store/broker-a
#commitLog 存储路径
storePathCommitLog=/usr/local/rocketmq/store/broker-a/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/usr/local/rocketmq/store/broker-a/consumequeue
#消息索引存储路径
storePathIndex=/usr/local/rocketmq/store/broker-a/index
broker_b_s.properties
# 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-b
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端口
listenPort=10921
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#nameServer地址,分号分割
namesrvAddr=192.168.33.130:9876;192.168.33.131:9876
#存储路径
storePathRootDir=/usr/local/rocketmq/store/broker-b-s
#commitLog 存储路径
storePathCommitLog=/usr/local/rocketmq/store/broker-b-s/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/usr/local/rocketmq/store/broker-b-s/consumequeue
#消息索引存储路径
storePathIndex=/usr/local/rocketmq/store/broker-b-s/index
192.168.33.131的虚拟机b
broker_b.properties
# 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-b
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端口
listenPort=10920
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#nameServer地址,分号分割
namesrvAddr=192.168.33.130:9876;192.168.33.131:9876
#存储路径
storePathRootDir=/usr/local/rocketmq/store/broker-b
#commitLog 存储路径
storePathCommitLog=/usr/local/rocketmq/store/broker-b/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/usr/local/rocketmq/store/broker-b/consumequeue
#消息索引存储路径
storePathIndex=/usr/local/rocketmq/store/broker-b/index
broker_a_s.properties
# 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=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端口
listenPort=10911
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#nameServer地址,分号分割
namesrvAddr=192.168.33.130:9876;192.168.33.131:9876
#存储路径
storePathRootDir=/usr/local/rocketmq/store/broker-a-s
#commitLog 存储路径
storePathCommitLog=/usr/local/rocketmq/store/broker-a-s/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/usr/local/rocketmq/store/broker-a-s/consumequeue
#消息索引存储路径
storePathIndex=/usr/local/rocketmq/store/broker-a-s/index
启动
分别启动nameserver
cd /usr/local/rocketmq/rocketmq-all-4.9.0-bin-release/bin
nohup sh mqnamesrv &
启动第一个服务器 192.168.33.130
Broker-a
cd /usr/local/rocketmq/rocketmq-all-4.9.0-bin-release/bin
nohup sh mqbroker -c /usr/local/rocketmq/rocketmq-all-4.9.0-bin-release/conf/2m-2s-sync/broker-a.properties &
Broker-b-s
cd /usr/local/rocketmq/rocketmq-all-4.9.0-bin-release/bin
nohup sh mqbroker -c /usr/local/rocketmq/rocketmq-all-4.9.0-bin-release/conf/2m-2s-sync/broker-b-s.properties &
启动第二个服务器 192.168.33.131
Broker-b
cd /usr/local/rocketmq/rocketmq-all-4.9.0-bin-release/bin
nohup sh mqbroker -c /usr/local/rocketmq/rocketmq-all-4.9.0-bin-release/conf/2m-2s-sync/broker-b.properties &
Broker-a-s
cd /usr/local/rocketmq/rocketmq-all-4.9.0-bin-release/bin
nohup sh mqbroker -c /usr/local/rocketmq/rocketmq-all-4.9.0-bin-release/conf/2m-2s-sync/broker-a-s.properties &
通过jps查看是否启动
# 查看nameServer日志
tail -500f ~/logs/rocketmqlogs/namesrv.log
# 查看broker日志
tail -500f ~/logs/rocketmqlogs/broker.log
也可以直接使用命令jps
问题解决
启动nameserver正常, 但是broker启动报错:
java.io.FileNotFoundException: /usr/local/rocketmq/store/broker-a/config/consumerFilter.json.tmp (没有那个文件或目录)
原因是权限不够, 给目录/usr/local/rocketmq/store 直接设置成 全部读写, 777权限
sudo chmod -R 777 store/
配置权限后即可启动成功
测试完成关闭
sh mqshutdown broker
sh mqshutdown namesrv