您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“分布式消息隊(duì)列RocketMQ如何部署與監(jiān)控”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“分布式消息隊(duì)列RocketMQ如何部署與監(jiān)控”這篇文章吧。
一、RocketMQ簡(jiǎn)介
RocketMQ是一款分布式、隊(duì)列模型的消息中間件,具有以下特點(diǎn):
1、支持嚴(yán)格的消息順序;
2、支持Topic與Queue兩種模式;
3、億級(jí)消息堆積能力;
4、比較友好的分布式特性;
5、同時(shí)支持Push與Pull方式消費(fèi)消息;
本文采用雙Master的架構(gòu)模式。
二、服務(wù)器分布
1、相關(guān)說(shuō)明
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、系統(tǒng)環(huán)境
CentOS 6.30
4、總體架構(gòu)
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、環(huán)境變量設(shè)置
# 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、主機(jī)名設(shè)置
(1)、Master1服務(wù)器
# 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服務(wù)器
# 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服務(wù)器
# 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服務(wù)器
# 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參數(shù)調(diào)整
runbroker.sh需要根據(jù)內(nèi)存大小進(jìn)行適當(dāng)?shù)卣{(diào)整
JAVA_OPT_1="-server-Xms80g -Xmx80g -Xmn20g -XX:PermSize=1g -XX:MaxPermSize=1g" |
6、服務(wù)啟動(dòng)
# mkdir -p /data/rocketmq/store/commitlog /data/logs # cd /usr/local/rocketmq/conf && sed -i 's#${user.home}#/data#g' *.xml |
(1)、啟動(dòng)NameServer【master1、master2】
# cd /usr/local/rocketmq/bin # nohup sh mqnamesrv & |
(2)、啟動(dòng)BrokerServer A【master1】
# cd /usr/local/rocketmq/bin # nohup sh mqbro ker -c ../conf/2m-noslave/broker-a.properties >/dev/null 2>&1 & |
(3)、啟動(dòng)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服務(wù)健康監(jiān)控
1、依賴組件安裝
# yum -y install nmap |
2、nameserver監(jiān)控
# 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" ## 端口號(hào) SRV_PROT="tcp" ## 協(xié)議類型 SRV_NAME="rocketmq_nameserver" ## 服務(wù)名 ## 是否已正確掃描 SCAN_FLAG=0 for ETH_NAME in `/sbin/ifconfig | grep eth2 | 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 "未知的協(xié)議類型!" && exit1 fi ## 最多掃描3次,成功一次即可,以避免網(wǎng)絡(luò)抖動(dòng)而導(dǎo)致誤判 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監(jiān)控
# 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" ## 端口號(hào) SRV_PROT="tcp" ## 協(xié)議類型 SRV_NAME="rocketmq_brokerserver" ## 服務(wù)名 ## 是否已正確掃描 SCAN_FLAG=0 for ETH_NAME in `/sbin/ifconfig | grep eth2 | 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 "未知的協(xié)議類型!" && exit1 fi ## 最多掃描3次,成功一次即可,以避免網(wǎng)絡(luò)抖動(dòng)而導(dǎo)致誤判 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 |
以上紅色標(biāo)注部分,在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) |
以上是“分布式消息隊(duì)列RocketMQ如何部署與監(jiān)控”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。