1.安装JDK

需要先卸载系统默认的OPENJDK,安装 JDK1.8 64位的版本。

卸载open-jdk

rpm -qa|grep java

查到open jdk的安装。

使用命令

rpm -e --nodeps ***

卸载。

安装 jdk1.8 

tar -zxvf jdk-8u191-linux-x64.tar.gz 解压JDK

编辑 

/etc/profile 

在最后增加配置 

export JAVA_HOME=/work/jdk1.8.0_191
export PATH=$JAVA_HOME/bin:$PATH

rocketmq 集群搭建

1.部署架构

我们有两台节点

IP为 10.87.134.74,10.87.134.75,两台机器均运行NAMESERVER.

在74 上部署BROKER A MASTER,BROKER B SLAVE

在75 上部署BROKER A SLAVE,BROKER B MASTER

 

 

2.修改内存配置

在默认情况下 rocketmq 配置运行内存比较大,如果机器内存不够可以做些调整。

编辑 bin 目录下的runbroker.sh文件

JAVA_OPT="${JAVA_OPT} -server -Xms2g -Xmx2g -Xmn1g"

编辑 bin 目录下的 runserver.sh 文件

JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

3.准备集群配置文件

 

我们安装的主从异步模式

程序解压后在conf 有如下的配置文件

编辑节点74 的配置文件

编辑broker-a.properties 内容:

brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH

listenPort=6001
autoCreateTopicEnable=true
namesrvAddr=10.87.134.74:9876;10.87.134.75:9876
storePathRootDir=/work/rocketmq-4.5.1/store/broker-a
storePathCommitLog=/work/rocketmq-4.5.1/store/broker-a/commitlog
storePathConsumeQueue=/work/rocketmq-4.5.1/store/broker-a/consumequeue
storePathIndex=/work/rocketmq-4.5.1/store/broker-a/index
storeCheckpoint=/work/rocketmq-4.5.1/store/broker-a/checkpoint
abortFile=/work/rocketmq-4.5.1/store/broker-a/abort

编辑broker-b-s.properties 文件内容

brokerClusterName=DefaultCluster
brokerName=broker-b
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH

listenPort=7001
autoCreateTopicEnable=true

namesrvAddr=10.87.134.74:9876;10.87.134.75:9876
storePathRootDir=/work/rocketmq-4.5.1/store/broker-b
storePathCommitLog=/work/rocketmq-4.5.1/store/broker-b/commitlog
storePathConsumeQueue=/work/rocketmq-4.5.1/store/broker-b/consumequeue
storePathIndex=/work/rocketmq-4.5.1/store/broker-b/index
storeCheckpoint=/work/rocketmq-4.5.1/store/broker-b/checkpoint
abortFile=/work/rocketmq-4.5.1/store/broker-b/abort

编辑75 配置文件

编辑 broker-b.properties 文件

terName=DefaultCluster
brokerName=broker-b
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH

listenPort=7001
autoCreateTopicEnable=true

namesrvAddr=10.87.134.74:9876;10.87.134.75:9876
storePathRootDir=/work/rocketmq-4.5.1/store/broker-b
storePathCommitLog=/work/rocketmq-4.5.1/store/broker-b/commitlog
storePathConsumeQueue=/work/rocketmq-4.5.1/store/broker-b/consumequeue
storePathIndex=/work/rocketmq-4.5.1/store/broker-b/index
storeCheckpoint=/work/rocketmq-4.5.1/store/broker-b/checkpoint
abortFile=/work/rocketmq-4.5.1/store/broker-b/abort                            

编辑 broker-a-s.properties 文件

brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH


listenPort=6001
autoCreateTopicEnable=true

namesrvAddr=10.87.134.74:9876;10.87.134.75:9876

storePathRootDir=/work/rocketmq-4.5.1/store/broker-a
storePathCommitLog=/work/rocketmq-4.5.1/store/broker-a/commitlog
storePathConsumeQueue=/work/rocketmq-4.5.1/store/broker-a/consumequeue
storePathIndex=/work/rocketmq-4.5.1/store/broker-a/index
storeCheckpoint=/work/rocketmq-4.5.1/store/broker-a/checkpoint
abortFile=/work/rocketmq-4.5.1/store/broker-a/abort
listenPort:是broker 对外监听的端口。

我们需要创建以下的目录:
store/broker-a
store/broker-a/commitlog
store/broker-a/consumequeue
store/broker-a/index 目录

在两个节点上分别创建 broker-a,broker-b的目录。

4.启动rocketmq ,并检查是否正确。

1.启动nameserver
在两个节点上分别执行:
nohup sh /work/rocketmq-4.5.1/bin/mqnamesrv >/work/rocketmq-4.5.1/logs/mqnamesrv.log 2>&1 &
2.按照下面的顺序执行

  1.启动broker-a (节点1)
    nohup sh /work/rocketmq-4.5.1/bin/mqbroker -c /work/rocketmq-4.5.1/conf/2m2sasync/broker-a.properties > /work/rocketmq-4.5.1/logs/broker-a.log 2>&1 &

  2.启动broker-a-s (节点2)
    nohup sh /work/rocketmq-4.5.1/bin/mqbroker -c /work/rocketmq-4.5.1/conf/2m2sasync/broker-a-s.properties > /work/rocketmq-4.5.1/logs/broker-a-s.log 2>&1 &

  3.启动broker-b (节点2)
    nohup sh /work/rocketmq-4.5.1/bin/mqbroker -c /work/rocketmq-4.5.1/conf/2m2sasync/broker-b.properties > /work/rocketmq-4.5.1/logs/broker-b.log 2>&1 &

  4.启动broker-b-s (节点1)
    nohup sh /work/rocketmq-4.5.1/bin/mqbroker -c /work/rocketmq-4.5.1/conf/2m2sasync/broker-b-s.properties > /work/rocketmq-4.5.1/logs/broker-b-s.log 2>&1 &

   3. 查看节点配置是否正确

         执行命令 ./bin/mqadmin clusterList -n 10.87.134.75:9876

   

  出现4个这样的配置说明,大功告成了。

 

5.注意事项

故障1

在启动 broker 时报如下错误。

ERROR: Please set the JAVA_HOME variable in your environment, We need java(x64)! !!

解决办法:

注释上面三行,增加 JAVA_HOME即可。

 

 



 
 

 

posted on 2019-07-15 17:57  自由港  阅读(1314)  评论(0编辑  收藏  举报