全篇參照–《MyRocketMQ集羣部署實戰-雙master-雙slave-同步雙寫-異步刷盤(7臺機器) - tantexian的博客空間 - 開源中國社區》java
原文地址:https://my.oschina.net/tantexian/blog/703784node
本文是筆者在參考上文實踐過程當中的理解和擴充linux
符號「【】」中內容、附註5,6以及FAQ中內容均筆者所注git
如下全部機器均爲16G內存。【內存配置可修改,128M以上,筆者測試機器內存平均爲4G】github
(四NameServer、雙Mastere雙Slave、同步雙寫、異步刷盤):web
)shell
【該步驟未進行,爲生產環境下的優化操做,官網寫到該步驟一個系統只可優化一次】apache
執行下述shell腳本:vim
#!/bin/sh # Execute Only Once #當前程序運行環境用戶名 USERNAME=root #須要修改IO模式磁盤盤符 DISKNAME=sda echo 'vm.overcommit_memory=1' >> /etc/sysctl.conf echo 'vm.min_free_kbytes=5000000' >> /etc/sysctl.conf echo 'vm.drop_caches=1' >> /etc/sysctl.conf echo 'vm.zone_reclaim_mode=0' >> /etc/sysctl.conf echo 'vm.max_map_count=655360' >> /etc/sysctl.conf echo 'vm.dirty_background_ratio=50' >> /etc/sysctl.conf echo 'vm.dirty_ratio=50' >> /etc/sysctl.conf echo 'vm.page-cluster=3' >> /etc/sysctl.conf echo 'vm.dirty_writeback_centisecs=360000' >> /etc/sysctl.conf echo 'vm.swappiness=10' >> /etc/sysctl.conf cat /etc/sysctl.conf sysctl -p echo 'ulimit -n 655350' >> /etc/profile echo "$USERNAME hard nofile 655350" >> /etc/security/limits.conf #DISK=`df -k | sort -n -r -k 2 | awk -F/ 'NR==1 {gsub(/[0-9].*/,"",$3); print $3}'` #[ "$DISK" = 'cciss' ] && DISK='cciss!c0d0' echo 'deadline' > /sys/block/$DISKNAME/queue/scheduler echo "---------------------------------------------------------------" sysctl vm.overcommit_memory sysctl vm.min_free_kbytes sysctl vm.drop_caches sysctl vm.zone_reclaim_mode sysctl vm.max_map_count sysctl vm.dirty_background_ratio sysctl vm.dirty_ratio sysctl vm.page-cluster sysctl vm.dirty_writeback_centisecs sysctl vm.swappiness su - $USERNAME -c 'ulimit -n' cat /sys/block/$DISKNAME/queue/scheduler
yum install -y maven git
git clone https://git.oschina.net/tantexian/MyRocketMQ.git
【先在一個機子上安裝git、maven來編譯源碼,jdk須要安裝在7臺機子上,上一篇文章有安裝的解疑】centos
cd MyRocketMQ/ sh install.sh
(本次實驗中放置到/home目錄:)
PS:此處須要將編譯後的MyRocketMQ-bin文件分別scp或者rsync同步到其餘全部機器上去:
rsync -avzP /home/MyRocketMQ-bin/ root@10.128.31.104:/home/MyRocketMQ-bin/ rsync -avzP /home/MyRocketMQ-bin/ root@10.128.31.105:/home/MyRocketMQ-bin/ rsync -avzP /home/MyRocketMQ-bin/ root@10.128.31.106:/home/MyRocketMQ-bin/ rsync -avzP /home/MyRocketMQ-bin/ root@10.128.31.107:/home/MyRocketMQ-bin/ rsync -avzP /home/MyRocketMQ-bin/ root@10.128.31.108:/home/MyRocketMQ-bin/ rsync -avzP /home/MyRocketMQ-bin/ root@10.128.31.109:/home/MyRocketMQ-bin/
一、在主節點node103上生成祕鑰(輸入命令後一直回車便可): ssh-keygen -t rsa 二、分別將node103加入到node10四、node10五、node10六、node10七、node10八、node109的authorized_keys中 rsync -avzP /root/.ssh/id_rsa.pub root@10.128.31.104:/root/.ssh/authorized_keys rsync -avzP /root/.ssh/id_rsa.pub root@10.128.31.105:/root/.ssh/authorized_keys rsync -avzP /root/.ssh/id_rsa.pub root@10.128.31.106:/root/.ssh/authorized_keys rsync -avzP /root/.ssh/id_rsa.pub root@10.128.31.107:/root/.ssh/authorized_keys rsync -avzP /root/.ssh/id_rsa.pub root@10.128.31.108:/root/.ssh/authorized_keys rsync -avzP /root/.ssh/id_rsa.pub root@10.128.31.109:/root/.ssh/authorized_key 注:這樣之後從node103往其餘節點copy東西則再也不須要輸入密碼驗證!!!
最好檢測其餘全部node是否同步成功MyRocketMQ-bin:
【rsync比scp傳文件要慢一些】
雖然目前google已經嘗試使用openjdk代替oraclejdk:http://www.oschina.net/translate/openjdk-is-now-the-time) 仍是建議使用oracle的jdk替換掉自帶的openjdk,若不想替換則無需下續步驟。 首先卸載自帶的openjdk:
【注:經測試openjdk也可以使用,只要保證惟一jdk就行,不然會衝突】
rpm -e --nodeps java-1.7.0-openjdk-1.7.el7.x86_64 java-1.7.0-openjdk-headless-1.7.0.51-2.4.5.5.el7.x86_64
ps:若是rpm -e 下載不成功,能夠嘗試使用yum remove命令卸載。
而後再去oracle網站下載對應的jdk安裝:
若下載的爲rpm包:則使用rpm -ivh xxx 進行安裝便可!!!
vim /root/.bashrc #在該文件添加一下內容 # Set RocketMQ Environment ROCKETMQ_HOME=/home/MyRocketMQ-bin # 此處爲上述步驟中的maven編譯後文件目錄代碼 ROCKETMQ_CLASSPATH=$ROCKETMQ_HOME/lib # 此處爲rocketmq運行所依賴的jar的classpath ROCKETMQ_PATH=$ROCKETMQ_HOME/bin # 此處爲rocketmq運行bin目錄,加入到可執行命令 export ROCKETMQ_HOME ROCKETMQ_CLASSPATH ROCKETMQ_PATH # 設置環境變量 # 此處根據具體nameser集羣設置環境變量 export NAMESRV_ADDR='10.128.31.103:9876;10.128.31.104:9876;10.128.31.105:9876;10.128.31.106:9876' # Set Java Environment JAVA_HOME=/usr/java/jdk1.7.0_79 JRE_HOME=/usr/java/jdk1.7.0_79/jre PATH=.:$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$ROCKETMQ_PATH # 此處將ROCKETMQ_PATH CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$ROCKETMQ_PATH export JAVA_HOME JRE_HOME PATH CLASSPATH
【採用集羣模式時,啓動broker時,須要指定nameserver 地址集,即NAMESRV_ADDR
,包含每個nameserver集羣地址。由於nameserver之間不會進行信息同步,均經過broker定時彙報保持各節點信息「同步」】
vim /etc/hosts
同步到全部機器!!!
先附上集羣部署規劃(更多詳細請自行參考前續集羣部署圖): NameServer集羣:node103/node104/node105/node106 Master1/Slave1 : node103->node105 Master2/Slave2 : node104->node106 Producer/Consumer集羣:node107/node108/node109
(node103/node104/node105/node106分別執行如下命令):
nohup sh /home/MyRocketMQ-bin/bin/mqnamesrv &
【雙主雙備,修改相應的配置文件參數】
node103: cp /home/MyRocketMQ-bin/conf/2m-2s-sync/broker-a.properties /home/MyRocketMQ-bin/conf/2m-2s-sync/broker-master1.properties vim /home/MyRocketMQ-bin/conf/2m-2s-sync/broker-master1.properties
【同步複製方式下的主/備參數:SYNC_MASTER / SLAVE】
啓動node103 broker進程: nohup sh /home/MyRocketMQ-bin/bin/mqbroker -c /home/MyRocketMQ-bin/conf/2m-2s-sync/broker-master1.properties>bk.log
node104: cp /home/MyRocketMQ-bin/conf/2m-2s-sync/broker-a.properties /home/MyRocketMQ-bin/conf/2m-2s-sync/broker-master2.properties vim /home/MyRocketMQ-bin/conf/2m-2s-sync/broker-master2.properties
啓動node104 broker進程: nohup sh /home/MyRocketMQ-bin/bin/mqbroker -c /home/MyRocketMQ-bin/conf/2m-2s-sync/broker-master2.properties>bk.log
node105: cp /home/MyRocketMQ-bin/conf/2m-2s-sync/broker-a.properties /home/MyRocketMQ-bin/conf/2m-2s-sync/broker-slave1.properties vim /home/MyRocketMQ-bin/conf/2m-2s-sync/broker-slave1.properties
啓動node105 broker進程: sh /home/MyRocketMQ-bin/bin/mqbroker -c /home/MyRocketMQ-bin/conf/2m-2s-sync/broker-slave1.properties
node106: cp /home/MyRocketMQ-bin/conf/2m-2s-sync/broker-a.properties /home/MyRocketMQ-bin/conf/2m-2s-sync/broker-slave2.properties vim /home/MyRocketMQ-bin/conf/2m-2s-sync/broker-slave2.properties
啓動node106 broker進程: sh /home/MyRocketMQ-bin/bin/mqbroker -c /home/MyRocketMQ-bin/conf/2m-2s-sync/broker-slave2.properties
至此,NameServer/Broker集羣服務都已啓動
node107 啓動生成者: sh /home/MyRocketMQ-bin/bin/tools.sh com.alibaba.rocketmq.example.simple.Producer
node108 啓動消費者: sh /home/MyRocketMQ-bin/bin/tools.sh com.alibaba.rocketmq.example.simple.PushConsumer
PS:啓動順序總結:
1. 先啓動nameser集羣全部節點
2. 啓動Broker全部的master節點
3. 啓動Broker全部slave節點
(官方地址:https://github.com/rocketmq/rocketmq-console):
【附個war包下載地址:http://download.csdn.net/detail/howie_zhw/9580058#comment】
編譯以前須要修改config.properties文件nameser爲當前環境nameser集羣值:
sh /home/apache-tomcat-8.5.0/bin/catalina.sh run
筆者注:不方便編譯的話,直接下載war包copy到tomcat/webapps下,到自動生成的文件夾:rocketmq-console/WEB_INF/classes/config.properties
修改默認的127.0.0.1:9876 地址爲你的nameserver地址。
重啓tomcat服務,訪問 http://IP:8080/rocketmq-console/cluster/list.do 就能夠了
sh /home/MyRocketMQ-bin/bin/mqnamesrv
若是將上述全部的配置文件name統一修改成:2m2s-sync-borker.properties 則可使用一下命令啓動各節點Broker: sh /home/MyRocketMQ-bin/bin/mqbroker -c /home/MyRocketMQ-bin/conf/2m-2s-sync/2m2s-sync-borker.properties
ps aux | grep NamesrvStartup | grep -v grep | awk '{print $2}' | xargs kill -9 ps aux | grep BrokerStartup | grep -v grep | awk '{print $2}' | xargs kill -9
alias stna='nohup sh /home/MyRocketMQ-bin/bin/mqnamesrv > /var/log/rocketmq/mqnamesrv.log &' alias stbr='nohup sh /home/MyRocketMQ-bin/bin/mqbroker -c /home/MyRocketMQ-bin/conf/2m-2s-sync/2m2s-sync-borker.properties > /var/log/rocketmq/broker.log &' alias killna="ps aux | grep NamesrvStartup | grep -v grep | awk '{print $2}' | xargs kill -9" alias stpr='sh /home/MyRocketMQ-bin/bin/tools.sh com.alibaba.rocketmq.example.simple.Producer' alias stco='sh /home/MyRocketMQ-bin/bin/tools.sh com.alibaba.rocketmq.example.simple.PushConsumer' alias killbr="ps aux | grep BrokerStartup | grep -v grep | awk '{print $2}' | xargs kill -9"
vim /root/.bashrc
倘若須要kill 掉進程,不能使用jps查看進程來kill 不然會出現殭屍進程:
若是出現殭屍進程則須要使用ps -ahp 21514來查找殭屍進程的父進程,接着再kill掉。
【RocketMQ提供了「溫柔」關閉namesrv、broker服務的命令:mqshutdown】
mqbroker -m( mqbroker -p打印所有)
【下圖爲筆者測試截圖,具體信息與上文信息不符請見諒】
現象描述:
「VM warning: INFO: OS::commit_memory(0x00000006c0000000, 2147483648, 0) faild; error=’Cannot allocate memory’ (errno=12)」
解決方案:修改/RocketMQ/devnev/bin/
下的服務啓動腳本 runserver.sh
、runbroker.sh
中對於內存的限制,改爲以下示例:
JAVA_OPT="${JAVA_OPT} -server -Xms128m -Xmx128m -Xmn128m -XX:PermSize=128m -XX:MaxPermSize=128m"
tomcat啓動:進入安裝目錄
或者直接輸入tomcat命令啓動(筆者yum安裝的tomcat7.04)
tomcat start(stop)
tomcat啓動後,仍沒法訪問的問題能夠參考幾點:
問題描述:如何自定義Producer、Consumer的代碼運行,好比修改Producer的topic,發送條數,Consumer的Group name等信息
解讀:目前Producer、Consumer的啓動是經過tool.sh進行啓動,其調用的是已經封裝好的jar包,因此沒法直接修改Producer的代碼進行測試。
解決辦法:可經過編寫demo項目,導入RocketMQ的依賴包,運行測試程序Producer、Consumer進行測試,具體方案參看Myeclipse中搭建RocketMQ測試項目