docker環境安裝rocketmq叢集
公司要上GPS資料平臺,中介軟體領導決策用rocketmq叢集,以前都是用的rabbitmq,據說rocketmq效能更加好,所以進行搭建學習
伺服器環境:centos7 ,連上阿里映象源
安裝使用者:root,關閉防火牆
1.安裝docker
yum -y install docker //安裝docker
systemctl start docker //啟動docker
systemctl status docker//檢視狀態
systemctl enable docker.service //開機自啟
其他docker 基本命令
docker pull xxx
docker run xxx
docker ps -a
docker start xxx
docker stop xxx
docker restart xxx
docker rm xxx
2安裝docker Compose
sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose //新增許可權
docker-compose --version //檢視版本
3.安裝dokcker管理面板portainer 漢化版本
docker pull portainer/portainer-ce
wget https://imnks.com/usr/uploads/2021/11/portainer-ce-2.9.2-public-cn-1101.zip
unzip portainer-ce-2.9.2-public-cn-1101.zip
docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data -v /root/public:/public portainer/portainer-ce
瀏覽器輸入IP:9000
如果無法進入管理面板,提示許可權不足,進行如下設定
修改/etc/selinux/config 檔案
將SELINUX=enforcing改為SELINUX=disabled
4.安裝rocketmq叢集和管理工具
建立指令碼:vi rocketmq.yml
指令碼如下-----------------------------------
#rocketmq叢集
version: '3.3'
services:
rocketmq-namesrv-1:
image: rocketmqinc/rocketmq-namesrv:4.5.0-alpine-uid
container_name: rocketmq-namesrv-1
ports:
- 9876:9876
volumes:
- /usr/local/bin/atp/rocketmq/logs/nameserver1:/home/rocketmq/logs/rocketmqlogs
command: sh mqnamesrv
networks:
- rocketmq
rocketmq-namesrv-2:
image: rocketmqinc/rocketmq-namesrv:4.5.0-alpine-uid
container_name: rocketmq-namesrv-2
ports:
- 9877:9876
volumes:
- /usr/local/bin/atp/rocketmq/logs/nameserver2:/home/rocketmq/logs/rocketmqlogs
command: sh mqnamesrv
networks:
- rocketmq
rocketmq-broker-1:
image: rocketmqinc/rocketmq-broker:4.5.0-alpine-uid
container_name: rocketmq-broker-1
ports:
- 10911:10911
volumes:
- /usr/local/bin/atp/rocketmq/logs/broker1:/home/rocketmq/logs/rocketmqlogs
#- /usr/local/bin/atp/rocketmq/store/broker1:/home/rocketmq/store
- /usr/local/bin/atp/rocketmq/conf/broker1/broker.conf:/home/rocketmq/rocketmq-4.5.0/conf/broker.conf
environment:
TZ: Asia/Shanghai
NAMESRV_ADDR: "rocketmq-namesrv-1:9876;rocketmq-namesrv-2:9876"
JAVA_OPTS: "-Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
command: sh mqbroker -c /home/rocketmq/rocketmq-4.5.0/conf/broker.conf autoCreateTopicEnable=true &
depends_on:
- rocketmq-namesrv-1
- rocketmq-namesrv-2
networks:
- rocketmq
rocketmq-broker-2:
image: rocketmqinc/rocketmq-broker:4.5.0-alpine-uid
container_name: rocketmq-broker-2
ports:
- 10912:10911
volumes:
- /usr/local/bin/atp/rocketmq/logs/broker2:/home/rocketmq/logs/rocketmqlogs
#- /usr/local/bin/atp/rocketmq/store/broker2:/home/rocketmq/store
- /usr/local/bin/atp/rocketmq/conf/broker2/broker.conf:/home/rocketmq/rocketmq-4.5.0/conf/broker.conf
environment:
TZ: Asia/Shanghai
NAMESRV_ADDR: "rocketmq-namesrv-1:9876;rocketmq-namesrv-2:9876"
JAVA_OPTS: " -Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
command: sh mqbroker -c /home/rocketmq/rocketmq-4.5.0/conf/broker.conf autoCreateTopicEnable=true &
depends_on:
- rocketmq-namesrv-1
- rocketmq-namesrv-2
networks:
- rocketmq
rocketmq-broker-3:
image: rocketmqinc/rocketmq-broker:4.5.0-alpine-uid
container_name: rocketmq-broker-3
ports:
- 10913:10911
volumes:
- /usr/local/bin/atp/rocketmq/logs/broker3:/home/rocketmq/logs/rocketmqlogs
#- /usr/local/bin/atp/rocketmq/store/broker3:/home/rocketmq/store
- /usr/local/bin/atp/rocketmq/conf/broker3/broker.conf:/home/rocketmq/rocketmq-4.5.0/conf/broker.conf
environment:
TZ: Asia/Shanghai
NAMESRV_ADDR: "rocketmq-namesrv-1:9876;rocketmq-namesrv-2:9876"
JAVA_OPTS: " -Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
command: sh mqbroker -c /home/rocketmq/rocketmq-4.5.0/conf/broker.conf autoCreateTopicEnable=true &
depends_on:
- rocketmq-namesrv-1
- rocketmq-namesrv-2
networks:
- rocketmq
rocketmq-console:
image: styletang/rocketmq-console-ng
container_name: rocketmq-console
ports:
- 9090:8080
environment:
JAVA_OPTS: -Drocketmq.namesrv.addr=rocketmq-namesrv-1:9876;rocketmq-namesrv-2:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false
networks:
- rocketmq
depends_on:
- rocketmq-broker-1
- rocketmq-broker-2
- rocketmq-broker-3
networks:
rocketmq:
driver: bridge
---------------------------------------------------------------------------------------------------------------------------
建立資料夾
mkdir -p /usr/local/bin/atp/rocketmq/conf/broker1
mkdir -p /usr/local/bin/atp/rocketmq/conf/broker2
mkdir -p /usr/local/bin/atp/rocketmq/conf/broker3
vi /usr/local/bin/atp/rocketmq/conf/broker3/broker.conf
建立broker.conf
brokerClusterName = DefaultCluster
#broker名稱
brokerName = rocketmq-broker-1
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
啟動叢集:
docker-compose -f rocketmq.yml -p rocketmq up -d
訪問控制檯:http//ip:9090