docke安装rocketmq

该文指导如何从拉取官方Docker镜像开始,构建RocketMQ的镜像,包括安装Maven,配置环境变量,修改RocketMQDashboard的配置,处理Java版本问题,以及使用docker-compose部署单机版RocketMQ,包括Broker和Namesrv服务。
摘要由CSDN通过智能技术生成
#拉取官方的docker地址
git clone https://github.com/apache/rocketmq-docker.git
#构建镜像
cd image-build
sh build-image.sh 4.7.1 centos

版本对应可以查看官方进行匹配

#安装maven

http://maven.apache.org/download.cgi

#上传文件,解压
tar -zxvf apache-maven-3.6.3-bin.tar.gz
#编辑环境变量
vi /etc/profile
#在文件最后追加以下内容

export MAVEN_HOME=/usr/local/apache-maven-3.6.3
export PATH=$MAVEN_HOME/bin:$PATH
#环境变量生效
source /etc/profile
#查看版本
mvn -v 
#增加国内打包源
vim /usr/local/apache-maven-3.6.3/conf/settings.xml

#在<mirrors>里追加以下内容
<mirror> 
      <id>alimaven</id> 
      <name>aliyun maven</name>   
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url> 
      <mirrorOf>central</mirrorOf> 
 </mirror>

// 构建dashboard的镜像。
git clone https://github.com/apache/rocketmq-dashboard
cd rocketmq-dashboard
#注释目录下的插件pom.xml中的frontend-maven-plugin和maven-antrun-plugin再进行打包
#注意,如果单节点docker部署,则需要进到rocketmq-dashboard项目目录进行修改src/main/resources/application.yml文件的ip,因为默认是127.0.0.1会指向docker本身ip,导致找不到reckermq服务从而报错

mvn clean package -Dmaven.test.skip=true docker:build #打包程序并做成docker镜像
#如果报找不到java8的错误则需要进行以下命令
sudo yum install java-1.8.0-openjdk
sudo alternatives --config java
#选择需要的Java,一般是*后面的数字,一般为1
#查看镜像是否都构建完成
docker images

RockerMQ 单机部署

#创建rocketmq的数据和日志路径
mkdir -p /root/rocketmq/data/namesrv/logs
chmod 777  /root/rocketmq/data/namesrv/logs
mkdir -p /root/rocketmq/data/namesrv/store
chmod 777  /root/rocketmq/data/namesrv/store

#创建broker的数据和日志路径
mkdir -p /root/rocketmq/data/broker/logs
mkdir -p /root/rocketmq/data/broker/store
mkdir -p /root/rocketmq/etc/broker
chmod 777 /root/rocketmq/data/broker/logs
chmod 777 /root/rocketmq/data/broker/store
chmod 777 /root/rocketmq/etc/broker
#Broker配置文件创建
vi /root/rocketmq/etc/broker/broker.conf

#输入以下内容

brokerClusterName = mxsm-docker
brokerName = mxsm-docker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# Docker环境需要设置成宿主机IP
#brokerIP1 = {docker宿主机IP}
brokerIP1 = 192.168.2.226
#安装docker-compose命令(有则不进行安装)
curl -SL https://github.com/docker/compose/releases/download/v2.7.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose

#赋予权限
chmod +x /usr/local/bin/docker-compose

#编辑文件
chmod 777  /root/rocketmq/etc/broker/broker.conf
cd  /usr/local/bin/
vi docker-compose.yml
#输入以下内容,我这里的 docker-compose为2

version: '2'
services:
  #Service for nameserver
  namesrv:
    image: apacherocketmq/rocketmq:4.7.1
    container_name: rocketmq-namesrv
    ports:
      - 9876:9876
    environment:
      - JAVA_OPT_EXT=-server -Xms256m -Xmx256m -Xmn256m
    volumes:
      - /root/rocketmq/data/namesrv/logs:/root/logs
    command: sh mqnamesrv
 
  #Service for broker
  broker:
    image: apacherocketmq/rocketmq:4.7.1
    container_name: rocketmq-broker
    links:
      - namesrv
    depends_on:
      - namesrv
    ports:
      - 10909:10909
      - 10911:10911
      - 10912:10912
    environment:
      - NAMESRV_ADDR=namesrv:9876
      - JAVA_OPT_EXT=-server -Xms512m -Xmx512m -Xmn256m
    volumes:
      - /root/rocketmq/data/broker/logs:/home/rocketmq/logs
      - /root/rocketmq/data/broker/store:/home/rocketmq/store
      - /root/rocketmq/etc/broker/broker.conf:/home/rocketmq/conf/broker.conf
    command: sh mqbroker -c /home/rocketmq/conf/broker.conf
 
  #Service for rocketmq-dashboard
  dashboard:
    image: apache/rocketmq-dashboard:1.0.0-centos
    container_name: rocketmq-dashboard
    ports:
      - 8080:8080
    links:
      - namesrv
    depends_on:
      - namesrv
    environment:
      - NAMESRV_ADDR=namesrv:9876

docker-compose -f ./docker-compose.yml up
// A code block
var foo = 'bar';
// A code block
var foo = 'bar';
// A code block
var foo = 'bar';
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值