您可以捐助,支持我们的公益事业。

1元 10元 50元





认证码:  验证码,看不清楚?请点击刷新验证码 必填



  求知 文章 文库 Lib 视频 iPerson 课程 认证 咨询 工具 讲座 Modeler   Code  
会员   
 
   
 
 
     
   
 订阅
  捐助
分布式消息队列RocketMQ部署与监控
 
作者:workming 来源:CSDN 发布于: 2015-04-08
  9153  次浏览      16
 

一、RocketMQ简介

RocketMQ是一款分布式、队列模型的消息中间件,具有以下特点:

1、支持严格的消息顺序;

2、支持Topic与Queue两种模式;

3、亿级消息堆积能力;

4、比较友好的分布式特性;

5、同时支持Push与Pull方式消费消息;

本文采用双Master的架构模式。

二、服务器分布

1、相关说明

2、hosts信息添加

# vim /etc/hosts
10.217.121.123 mqnameserver1
10.217.122.31 mqnameserver2
10.217.121.123 rocketmq-master1
10.217.122.31 rocketmq-master2

3、系统环境

CentOS 6.30

4、总体架构

wKioL1PuQE3DcTjUAAE4E08WEfw644.jpg

三、RocketMQ安装与配置

1、JDK安装

http://download.oracle.com/otn-pub/java/jdk/7u65-b17/jdk-7u65-linux-x64.tar.gz
# tar xvzf jdk-7u65-linux-x64.gz -C /usr/local
# rm -f jdk-7u65-linux-x64.gz
# cd /usr/local && ln -s jdk1.7.0_65 jdk
# cd /usr/local/bin && ln -s /usr/local/jdk/bin/java

2、RocketMQ安装

https://github.com/alibaba/RocketMQ/releases
# tar xvzf alibaba-rocketmq-3.1.7.tar.gz -C /usr/local
# mv alibaba-rocketmq alibaba-rocketmq-3.1.7
# ln -s alibaba-rocketmq-3.1.7 rocketmq
# rm alibaba-rocketmq-3.1.7.tar.gz
# ll /usr/local

3、环境变量设置

# vim /etc/profile
export PATH=$PATH:/usr/local/bin


export JAVA_HOME=/usr/local/jdk
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin


export ROCKETMQ_HOME=/usr/local/rocketmq
export PATH=$PATH::$ROCKETMQ_HOME/bin


# source /etc/profile
# cd /usr/local/rocketmq/bin && sh os.sh
》

4、主机名设置

(1)、Master1服务器

# vim /etc/hosts
10.217.121.123  mqnameserver1
10.217.122.31    mqnameserver2
10.217.121.123  rocketmq-master1
10.217.122.31    rocketmq-master2


# sed -i  '/HOSTNAME/d' /etc/sysconfig/network
# echo 'HOSTNAME=rocketmq-master1'  >> /etc/sysconfig/network
# hostname rocketmq-master1

(2)、Master2服务器

# vim /etc/hosts
10.217.121.123  mqnameserver1
10.217.122.31    mqnameserver2
10.217.121.123  rocketmq-master1
10.217.122.31    rocketmq-master2


# sed -i  '/HOSTNAME/d' /etc/sysconfig/network
# echo 'HOSTNAME=rocketmq-master2'  >> /etc/sysconfig/network
# hostname rocketmq-master2

5、RocketMQ配置

(1)、Master1服务器

# vim /usr/local/rocketmq/conf/2m-noslave/broker-a.properties
brokerClusterName=AdpMqCluster
brokerName=broker-a
brokerId=0
namesrvAddr=mqnameserver1:9876;mqnameserver2:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10911
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=50000000
destroyMapedFileIntervalForcibly=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88


storePathRootDir=/data/rocketmq/store
storePathCommitLog=/data/rocketmq/store/commitlog


maxMessageSize=65536


flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000


brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH


checkTransactionMessageEnable=false


sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128

(2)、Master2服务器

# vim /usr/local/rocketmq/conf/2m-noslave/broker-b.properties
brokerClusterName=AdpMqCluster
brokerName=broker-b
brokerId=1
namesrvAddr=mqnameserver1:9876;mqnameserver2:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10911
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=50000000
destroyMapedFileIntervalForcibly=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88


storePathRootDir=/data/rocketmq/store
storePathCommitLog=/data/rocketmq/store/commitlog


maxMessageSize=65536


flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000


brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH


checkTransactionMessageEnable=false


sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128

(3)、runbroker.sh参数调整

runbroker.sh需要根据内存大小进行适当地调整

JAVA_OPT_1="-server-Xms80g -Xmx80g -Xmn20g -XX:PermSize=1g -XX:MaxPermSize=1g"

6、服务启动

# mkdir -p /data/rocketmq/store/commitlog  /data/logs
# cd /usr/local/rocketmq/conf && sed -i 's#${user.home}#/data#g' *.xml

(1)、启动NameServer【master1、master2】

# cd /usr/local/rocketmq/bin
# nohup sh mqnamesrv &

(2)、启动BrokerServer A【master1】

# cd /usr/local/rocketmq/bin
# nohup sh mqbro ker -c ../conf/2m-noslave/broker-a.properties >/dev/null 2>&1 &

(3)、启动BrokerServer B【master2】

# cd /usr/local/rocketmq/bin
# nohup sh mqbroker -c ../conf/2m-noslave/broker-b.properties  >/dev/null 2>&1 &
# netstat -ntlp
# jps

四、RocketMQ服务健康监控

1、依赖组件安装

# yum -y install nmap

2、nameserver监控

# vim /data/scripts/check_nameserver_health.sh

#!/bin/sh 
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin

SRV_PORT="9876" ## 端口号
SRV_PROT="tcp" ## 协议类型
SRV_NAME="rocketmq_nameserver" ## 服务名

## 是否已正确扫描
SCAN_FLAG=0

for ETH_NAME in `/sbin/ifconfig | grep eth1 | awk '{print $1}'`
do
ETH1_ADDR=`/sbin/ifconfig ${ETH_NAME} | awk -F ':' '/inet addr/{print $2}' | sed 's/[a-zA-Z ]//g'`
[[ -z "${ETH1_ADDR}" ]] && continue || break
done

TMP_SRV_PROT=`echo ${SRV_PROT} | tr '[A-Z]' '[a-z]'`

if [[ "${TMP_SRV_PROT}" == "tcp" ]]; then
PROT_OPT="S"
elif [[ "${TMP_SRV_PROT}" == "udp" ]]; then
PROT_OPT="U"
else
echo "未知的协议类型!" && exit1
fi

## 最多扫描3次,成功一次即可,以避免网络抖动而导致误判
for ((i=0; i<3; i++)); do
RETVAL=`/usr/bin/nmap -n -s${PROT_OPT} -p ${SRV_PORT} ${ETH1_ADDR} | grep open`
[[ -n "${RETVAL}" ]] && SCAN_FLAG=1;break || sleep 10
done

if [[ ${SCAN_FLAG} -ne 1 ]]; then
[[ -n `ps aux | grep java | grep namesrv` ]] && kill -9 `ps aux | grep java | awk '/namesrv/{print $2}'`
cd /usr/local/rocketmq/bin && nohup sh mqnamesrv &
fi

3、brokerserver监控

# vim /data/scripts/check_brokerserver_health.sh

#!/bin/sh 
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin

SRV_PORT="10911" ## 端口号
SRV_PROT="tcp" ## 协议类型
SRV_NAME="rocketmq_brokerserver" ## 服务名

## 是否已正确扫描
SCAN_FLAG=0

for ETH_NAME in `/sbin/ifconfig | grep eth1 | awk '{print $1}'`
do
ETH1_ADDR=`/sbin/ifconfig ${ETH_NAME} | awk -F ':' '/inet addr/{print $2}' | sed 's/[a-zA-Z ]//g'`
[[ -z "${ETH1_ADDR}" ]] && continue || break
done

TMP_SRV_PROT=`echo ${SRV_PROT} | tr '[A-Z]' '[a-z]'`

if [[ "${TMP_SRV_PROT}" == "tcp" ]]; then
PROT_OPT="S"
elif [[ "${TMP_SRV_PROT}" == "udp" ]]; then
PROT_OPT="U"
else
echo "未知的协议类型!" && exit1
fi

## 最多扫描3次,成功一次即可,以避免网络抖动而导致误判
for ((i=0; i<3; i++)); do
RETVAL=`/usr/bin/nmap -n -s${PROT_OPT} -p ${SRV_PORT} ${ETH1_ADDR} | grep open`
[[ -n "${RETVAL}" ]] && SCAN_FLAG=1;break || sleep 10
done

if [[ ${SCAN_FLAG} -ne 1 ]]; then
[[ -n `ps aux | grep java | grep broker` ]] && kill -9 `ps aux | grep java | awk '/broker/{print $2}'`
cd /usr/local/rocketmq/bin && nohup sh mqbroker -c ../conf/2m-noslave/broker-a.properties &
fi

以上红色标注部分,在master2上的名称为“broker-b.properties”

4、crontab信息添加

# touch /var/run/check_rocketmq_nameserver.lock
# touch /var/run/check_rocketmq_brokerserver.lock 


# echo 'touch /var/run/check_rocketmq_nameserver.lock' >> /etc/rc.d/rc.local 
# echo 'touch /var/run/check_rocketmq_brokerserver.lock' >> /etc/rc.d/rc.local

# crontab -e
*/2 * * * * (flock --timeout=0 /var/run/check_rocketmq_nameserver.lock 
/data/scripts/check_nameserver_health.sh >/dev/null 2>&1)

*/2 * * * * (flock --timeout=0 /var/run/check_rocketmq_brokerserver.lock 
/data/scripts/check_brokerserver_health.sh >/dev/null 2>&1)
   
9153 次浏览       16
相关文章

企业架构、TOGAF与ArchiMate概览
架构师之路-如何做好业务建模?
大型网站电商网站架构案例和技术架构的示例
完整的Archimate视点指南(包括示例)
相关文档

数据中台技术架构方法论与实践
适用ArchiMate、EA 和 iSpace进行企业架构建模
Zachman企业架构框架简介
企业架构让SOA落地
相关课程

云平台与微服务架构设计
中台战略、中台建设与数字商业
亿级用户高并发、高可用系统架构
高可用分布式架构设计与实践
最新课程计划
信息架构建模(基于UML+EA)3-21[北京]
软件架构设计师 3-21[北京]
图数据库与知识图谱 3-25[北京]
业务架构设计 4-11[北京]
SysML和EA系统设计与建模 4-22[北京]
DoDAF规范、模型与实例 5-23[北京]

专家视角看IT与架构
软件架构设计
面向服务体系架构和业务组件
人人网移动开发架构
架构腐化之谜
谈平台即服务PaaS


面向应用的架构设计实践
单元测试+重构+设计模式
软件架构师—高级实践
软件架构设计方法、案例与实践
嵌入式软件架构设计—高级实践
SOA体系结构实践


锐安科技 软件架构设计方法
成都 嵌入式软件架构设计
上海汽车 嵌入式软件架构设计
北京 软件架构设计
上海 软件架构设计案例与实践
北京 架构设计方法案例与实践
深圳 架构设计方法案例与实践
嵌入式软件架构设计—高级实践
更多...