文章首發於公衆號《程序員果果》
地址 : http://blog.itwolfed.com/blog/98java
首先再把上一接中提到的 RocketMQ 部署架構圖看一下。程序員
從圖中能夠看出,RocketMQ的服務端分爲兩塊 Name Server 和 Broker。docker
建立NameServer數據存儲路徑:shell
mkdir -p /home/rocketmq/data/namesrv/logs /home/rocketmq/data/namesrv/store
構建 NameServer 容器:apache
docker run -d \ --name rmqnamesrv \ -p 9876:9876 \ -v /home/rocketmq/data/namesrv/logs:/root/logs \ -v /home/rocketmq/data/namesrv/store:/root/store \ -e "MAX_POSSIBLE_HEAP=100000000" \ rocketmqinc/rocketmq \ sh mqnamesrv
建立Broker數據存儲路徑:bash
mkdir -p /home/rocketmq/data/broker/logs /home/rocketmq/data/broker/store /home/rocketmq/conf
在/home/rocketmq/conf 目錄下建立 broker.conf 文件,內容以下:服務器
# 所屬集羣名稱,若是節點較多能夠配置多個 brokerClusterName = DefaultCluster #broker名稱,master和slave使用相同的名稱,代表他們的主從關係 brokerName = broker-a #0表示Master,大於0表示不一樣的slave brokerId = 0 #表示幾點作消息刪除動做,默認是凌晨4點 deleteWhen = 04 #在磁盤上保留消息的時長,單位是小時 fileReservedTime = 48 #有三個值:SYNC_MASTER,ASYNC_MASTER,SLAVE;同步和異步表示Master和Slave之間同步數據的機制; brokerRole = ASYNC_MASTER #刷盤策略,取值爲:ASYNC_FLUSH,SYNC_FLUSH表示同步刷盤和異步刷盤;SYNC_FLUSH消息寫入磁盤後才返回成功狀態,ASYNC_FLUSH不須要; flushDiskType = ASYNC_FLUSH # 設置broker節點所在服務器的ip地址 brokerIP1 = 172.16.250.129
構建 Broker 容器:架構
docker run -d \ --name rmqbroker \ --link rmqnamesrv:namesrv \ -p 10911:10911 \ -p 10909:10909 \ -v /home/rocketmq/data/broker/logs:/root/logs \ -v /home/rocketmq/data/broker/store:/root/store \ -v /home/rocketmq/conf/broker.conf:/opt/rocketmq-4.4.0/conf/broker.conf \ -e "NAMESRV_ADDR=namesrv:9876" \ -e "MAX_POSSIBLE_HEAP=200000000" \ rocketmqinc/rocketmq \ sh mqbroker -c /opt/rocketmq-4.4.0/conf/broker.conf
構建rockermq-console容器:異步
docker run -d \ --name rmqadmin \ -e "JAVA_OPTS=-Drocketmq.namesrv.addr=172.16.250.129:9876 \ -Dcom.rocketmq.sendMessageWithVIPChannel=false \ -Duser.timezone='Asia/Shanghai'" \ -v /etc/localtime:/etc/localtime \ -p 9999:8080 \ pangliang/rocketmq-console-ng
訪問 http://172.16.250.129:9999/#/cluster 以下圖說明安裝成功:ide
下載地址:
https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.5.0/rocketmq-all-4.5.0-bin-release.zip
環境要求:
# 1.啓動NameServer nohup sh bin/mqnamesrv & # 2.查看啓動日誌 tail -f ~/logs/rocketmqlogs/namesrv.log
# 1.啓動Broker nohup sh bin/mqbroker -n localhost:9876 & # 2.查看啓動日誌 tail -f ~/logs/rocketmqlogs/broker.log
若啓動報內存不足啓動失敗,須要編輯以下兩個配置文件,修改JVM內存大小:
vi runbroker.sh vi runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
進入 rmqnamesrv 容器:
[root@localhost ~]# docker exec -it 95a52e07151c bash [root@95a52e07151c bin]#
# 1.設置環境變量 export NAMESRV_ADDR=172.16.250.129:9876 # 2.使用安裝包的Demo發送消息 sh tools.sh org.apache.rocketmq.example.quickstart.Producer
# 1.設置環境變量 export NAMESRV_ADDR=localhost:9876 # 2.接收消息 sh tools.sh org.apache.rocketmq.example.quickstart.Consumer