==========================================================================================java
1、RocketMQ簡介linux
==========================================================================================git
RocketMQ是一款分佈式、隊列模型的消息中間件,具備如下特色:github
一、支持嚴格的消息順序;vim
二、支持Topic與Queue兩種模式;服務器
三、億級消息堆積能力;網絡
四、比較友好的分佈式特性;架構
五、同時支持Push與Pull方式消費消息;oracle
==========================================================================================tcp
2、服務器分佈
==========================================================================================
1、相關說明
IP地址 |
主機名 |
機型 |
角色 |
架構模式 |
10.217.121.123 |
rocketmq-master1 |
128G內存 |
nameserver、brokerserver |
Master1(雙Master模式) |
10.217.122.31 |
rocketmq-master2 |
128G內存 |
nameserver、brokerserver |
Master2(雙Master模式) |
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.3
4、整體架構
==========================================================================================
3、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 &
# nohup sh mqnamesrv >/var/log/ns.log & # nohup sh mqbroker -c ../conf/2m-noslave/broker-a.properties > /var/log/mq.log 2>&1 &
(2)、啓動BrokerServer A【master1】
# cd /usr/local/rocketmq/bin
# nohup sh mqbroker -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
==========================================================================================
4、RocketMQ服務健康監控
==========================================================================================
1、依賴組件安裝
# yum -y install nmap
2、nameserver監控
# vim /data/scripts/check_nameserver_health.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
3、brokerserver監控
# vim /data/scripts/check_brokerserver_health.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
【注意】
以上紅色標註部分,在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)