阿某云:centos 7,47.*.*.*(172.*.*.*),在安全组策略开启8000-9000之间的端口访问权限。
注意一定要开放安全组端口,否则无法访问console控制台
mkdir -p /usr/local/rocketmq/logs/nameserver-1
mkdir -p /usr/local/rocketmq/logs/nameserver-2
mkdir -p /usr/local/rocketmq/logs/broker-master-1
mkdir -p /usr/local/rocketmq/logs/broker-master-2
mkdir -p /usr/local/rocketmq/logs/broker-slave-1
mkdir -p /usr/local/rocketmq/logs/broker-slave-2
mkdir -p /usr/local/rocketmq/store/nameserver-1
mkdir -p /usr/local/rocketmq/store/nameserver-2
mkdir -p /usr/local/rocketmq/store/broker-master-1
mkdir -p /usr/local/rocketmq/store/broker-master-2
mkdir -p /usr/local/rocketmq/store/broker-slave-1
mkdir -p /usr/local/rocketmq/store/broker-slave-2
mkdir -p /usr/local/rocketmq/conf/broker-master-1
mkdir -p /usr/local/rocketmq/conf/broker-master-2
mkdir -p /usr/local/rocketmq/conf/broker-slave-1
mkdir -p /usr/local/rocketmq/conf/broker-slave-2
nameserver镜像
docker pull foxiswho/rocketmq:server-4.3.2
broker镜像
docker pull foxiswho/rocketmq:broker-4.3.2
rocketmq-console镜像
docker pull styletang/rocketmq-console-ng
docker create -p 8201:9876 --name rmq-nameserver-1 \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
-e "JAVA_OPTS=-Duser.home=/opt" \
-v /usr/local/rocketmq/logs/nameserver-1:/opt/logs \
-v /usr/local/rocketmq/store/nameserver-1:/opt/store \
foxiswho/rocketmq:server-4.3.2
docker create -p 8202:9876 --name rmq-nameserver-2 \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
-e "JAVA_OPTS=-Duser.home=/opt" \
-v /usr/local/rocketmq/logs/nameserver-2:/opt/logs \
-v /usr/local/rocketmq/store/nameserver-2:/opt/store \
foxiswho/rocketmq:server-4.3.2
docker create --net host --name rmq-master-1 \
-e "JAVA_OPTS=-Duser.home=/opt" \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
-v /usr/local/rocketmq/conf/broker-master-1/broker.conf:/etc/rocketmq/broker.conf \
-v /usr/local/rocketmq/logs/broker-master-1:/opt/logs \
-v /usr/local/rocketmq/store/broker-master-1:/opt/store \
foxiswho/rocketmq:broker-4.3.2
docker create --net host --name rmq-master-2 \
-e "JAVA_OPTS=-Duser.home=/opt" \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
-v /usr/local/rocketmq/conf/broker-master-2/broker.conf:/etc/rocketmq/broker.conf \
-v /usr/local/rocketmq/logs/broker-master-2:/opt/logs \
-v /usr/local/rocketmq/store/broker-master-2:/opt/store \
foxiswho/rocketmq:broker-4.3.2
docker create --net host --name rmq-slave-1 \
-e "JAVA_OPTS=-Duser.home=/opt" \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
-v /usr/local/rocketmq/conf/broker-slave-1/broker.conf:/etc/rocketmq/broker.conf \
-v /usr/local/rocketmq/logs/broker-slave-1:/opt/logs \
-v /usr/local/rocketmq/store/broker-slave-1:/opt/store \
foxiswho/rocketmq:broker-4.3.2
docker create --net host --name rmq-slave-2 \
-e "JAVA_OPTS=-Duser.home=/opt" \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
-v /usr/local/rocketmq/conf/broker-slave-2/broker.conf:/etc/rocketmq/broker.conf \
-v /usr/local/rocketmq/logs/broker-slave-2:/opt/logs \
-v /usr/local/rocketmq/store/broker-slave-2:/opt/store \
foxiswho/rocketmq:broker-4.3.2
注意:
1.brokerId 从节点错误,主节点是0,从节点是1
2.主从复制模式:brokerRole,总共3种模式,如果是从节点 该值是 SLAVE
3.刷盘机制:flushDiskType=ASYNC_FLUSH,异步刷盘 同步刷盘
如何选择:主从复制选择同步复制保证消息不丢失,异步刷盘保证效率
cat > /usr/local/rocketmq/conf/broker-master-1/broker.conf << EOF
listenPort=8111
brokerIP1=47.103.*.*
brokerClusterName=DefaultCluster
brokerName=broker-m1
brokerRole=SYNC_MASTER
brokerId=0
deleteWhen=04
fileReservedTime=48
flushDiskType=ASYNC_FLUSH
namesrvAddr=47.103.*.*:8201;47.103.*.*:8202
EOF
cat > /usr/local/rocketmq/conf/broker-master-2/broker.conf << EOF
listenPort=8211
brokerIP1=47.103.*.*
brokerClusterName=DefaultCluster
brokerName=broker-m2
brokerRole=SYNC_MASTER
brokerId=0
deleteWhen=04
fileReservedTime=48
flushDiskType=ASYNC_FLUSH
namesrvAddr=47.103.*.*:8201;47.103.*.*:8202
EOF
cat > /usr/local/rocketmq/conf/broker-slave-1/broker.conf << EOF
listenPort=8115
brokerIP1=47.103.*.*
brokerClusterName=DefaultCluster
brokerName=broker-s1
brokerRole=SLAVE
brokerId=1
deleteWhen=04
fileReservedTime=48
flushDiskType=ASYNC_FLUSH
namesrvAddr=47.103.*.*:8201;47.103.*.*:8202
EOF
cat > /usr/local/rocketmq/conf/broker-slave-2/broker.conf << EOF
listenPort=8215
brokerIP1=47.103.*.*
brokerClusterName=DefaultCluster
brokerName=broker-s2
brokerRole=SLAVE
brokerId=1
deleteWhen=04
fileReservedTime=48
flushDiskType=ASYNC_FLUSH
namesrvAddr=47.103.*.*:8201;47.103.*.*:8202
EOF
先启动nameserver
docker start rmq-nameserver-1 rmq-nameserver-2
启动broker
docker start rmq-master-1 rmq-master-2 rmq-slave-1 rmq-slave-2
启动rocketmq-console
docker run -dit --name rocketmq-console-ng -e "JAVA_OPTS=-Drocketmq.namesrv.addr=47.103.*.*:8201;47.103.*.*:8202 -Dcom.rocketmq.sendMessageWithVIPChannel=false" -p 8203:8080 styletang/rocketmq-console-ng
http://47.103.*.*:8203/#/cluster
原因:启动broker容器,挂载目睹写错了,如下图位置写反了,写成了
/usr/local/rocketmq/broker-master-1/conf
1.docker ps -a 查看所有创建的容器,包含未启动的
2.docker stop containerID 停止broker容器
3.docker rm -f containerID 删除容器
4.重新创建容器,执行步骤4
未开放安全组
原因:配置文件中配置的naneserver端口不对
参考:
https://www.cnblogs.com/qdhxhz/p/11094624.html
https://www.cnblogs.com/zhou-920644981/p/14569126.html
http://www.mydlq.club/article/96/