Docker 기반 RocketMQ 구축

15684 단어 RocketMQDocker
문서 목록
  • 1, Dockerfile-centos 파일 만들기
  • 사용자 정의 RocketMQ 시작 스크립트
  • 구축 미러 지정 ROCKETMQVERSION
  • 2, 두 개의 메인 디스크가 비동기적으로 브러시를 제거하고broker 설정
  • broker-a.conf
  • broker-a-s.conf
  • broker-b.conf
  • broker-b-s.conf
  • 3, docker-Compose 만들기yml
  • 4,nameServer,broker,rocketmq-console-ng
  • 실행
  • 5, 원본 다운로드
  • 글 끝에 완전한 원본 다운로드가 있으니 참고하여 실천해 보십시오.
    1. Dockerfile-centos 파일 만들기
    #
    # Licensed to the Apache Software Foundation (ASF) under one or more
    # contributor license agreements.  See the NOTICE file distributed with
    # this work for additional information regarding copyright ownership.
    # The ASF licenses this file to You under the Apache License, Version 2.0
    # (the "License"); you may not use this file except in compliance with
    # the License.  You may obtain a copy of the License at
    #
    #      http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    #
    
    FROM centos:7
    
    RUN yum install -y java-1.8.0-openjdk-devel.x86_64 unzip gettext nmap-ncat openssl, which gnupg, telnet \
     && yum clean all -y
    
    # FROM openjdk:8-jdk
    # RUN apt-get update && apt-get install -y --no-install-recommends \
    #		bash libapr1 unzip telnet wget gnupg ca-certificates \
    #	&& rm -rf /var/lib/apt/lists/*
    
    ARG user=rocketmq
    ARG group=rocketmq
    ARG uid=3000
    ARG gid=3000
    
    # RocketMQ is run with user `rocketmq`, uid = 3000
    # If you bind mount a volume from the host or a data container,
    # ensure you use the same uid
    RUN groupadd -g ${gid} ${group} \
        && useradd -u ${uid} -g ${gid} -m -s /bin/bash ${user}
    
    ARG version
    
    # Rocketmq version
    ENV ROCKETMQ_VERSION ${version}
    
    # Rocketmq home
    ENV ROCKETMQ_HOME  /home/rocketmq/rocketmq-${ROCKETMQ_VERSION}
    
    WORKDIR  ${ROCKETMQ_HOME}
    
    RUN set -eux; \
        curl https://mirrors.tuna.tsinghua.edu.cn/apache/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip -o rocketmq.zip; \
        curl https://dist.apache.org/repos/dist/release/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip.asc -o rocketmq.zip.asc; \
        #https://www.apache.org/dist/rocketmq/KEYS
    	curl https://www.apache.org/dist/rocketmq/KEYS -o KEYS; \
    	\
    	gpg --import KEYS; \
        gpg --batch --verify rocketmq.zip.asc rocketmq.zip ; \
        unzip rocketmq.zip ; \
    	mv rocketmq-all*/* . ; \
    	rmdir rocketmq-all*  ; \
    	rm rocketmq.zip rocketmq.zip.asc KEYS
    
    # add scripts
    COPY scripts/ ${ROCKETMQ_HOME}/bin/
    
    RUN chown -R ${uid}:${gid} ${ROCKETMQ_HOME}
    
    # expose namesrv port
    EXPOSE 9876
    
    # add customized scripts for namesrv
    RUN mv ${ROCKETMQ_HOME}/bin/runserver-customize.sh ${ROCKETMQ_HOME}/bin/runserver.sh \
     && chmod a+x ${ROCKETMQ_HOME}/bin/runserver.sh \
     && chmod a+x ${ROCKETMQ_HOME}/bin/mqnamesrv
    
    # expose broker ports
    EXPOSE 10909 10911 10912
    
    # add customized scripts for broker
    RUN mv ${ROCKETMQ_HOME}/bin/runbroker-customize.sh ${ROCKETMQ_HOME}/bin/runbroker.sh \
     && chmod a+x ${ROCKETMQ_HOME}/bin/runbroker.sh \
     && chmod a+x ${ROCKETMQ_HOME}/bin/mqbroker
    
    # export Java options
    RUN export JAVA_OPT=" -Duser.home=/opt"
    
    # Add ${JAVA_HOME}/lib/ext as java.ext.dirs
    RUN sed -i 's/${JAVA_HOME}\/jre\/lib\/ext/${JAVA_HOME}\/jre\/lib\/ext:${JAVA_HOME}\/lib\/ext/' ${ROCKETMQ_HOME}/bin/tools.sh
    
    USER ${user}
    
    WORKDIR ${ROCKETMQ_HOME}/bin
    

    사용자 정의 RocketMQ 시작 스크립트
    runserver-customize.sh、runbroker-customize.sh 구덩이 밟기 방지, 시동 타임즈 메모리 부족 방지
    #!/bin/bash
    
    # Licensed to the Apache Software Foundation (ASF) under one or more
    # contributor license agreements.  See the NOTICE file distributed with
    # this work for additional information regarding copyright ownership.
    # The ASF licenses this file to You under the Apache License, Version 2.0
    # (the "License"); you may not use this file except in compliance with
    # the License.  You may obtain a copy of the License at
    #
    #     http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    
    #===========================================================================================
    # Java Environment Setting
    #===========================================================================================
    error_exit ()
    {
        echo "ERROR: $1 !!"
        exit 1
    }
    
    find_java_home()
    {
        case "`uname`" in
            Darwin)
                JAVA_HOME=$(/usr/libexec/java_home)
            ;;
            *)
                JAVA_HOME=$(dirname $(dirname $(readlink -f $(which javac))))
            ;;
        esac
    }
    
    find_java_home
    
    [ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
    [ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
    [ ! -e "$JAVA_HOME/bin/java" ] && error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)!"
    
    export JAVA_HOME
    export JAVA="$JAVA_HOME/bin/java"
    export BASE_DIR=$(dirname $0)/..
    export CLASSPATH=.:${BASE_DIR}/conf:${CLASSPATH}
    
    #===========================================================================================
    # JVM Configuration
    #===========================================================================================
    calculate_heap_sizes()
    {
        case "`uname`" in
            Linux)
                system_memory_in_mb=`free -m| sed -n '2p' | awk '{print $2}'`
                system_cpu_cores=`egrep -c 'processor([[:space:]]+):.*' /proc/cpuinfo`
            ;;
            FreeBSD)
                system_memory_in_bytes=`sysctl hw.physmem | awk '{print $2}'`
                system_memory_in_mb=`expr $system_memory_in_bytes / 1024 / 1024`
                system_cpu_cores=`sysctl hw.ncpu | awk '{print $2}'`
            ;;
            SunOS)
                system_memory_in_mb=`prtconf | awk '/Memory size:/ {print $3}'`
                system_cpu_cores=`psrinfo | wc -l`
            ;;
            Darwin)
                system_memory_in_bytes=`sysctl hw.memsize | awk '{print $2}'`
                system_memory_in_mb=`expr $system_memory_in_bytes / 1024 / 1024`
                system_cpu_cores=`sysctl hw.ncpu | awk '{print $2}'`
            ;;
            *)
                # assume reasonable defaults for e.g. a modern desktop or
                # cheap server
                system_memory_in_mb="2048"
                system_cpu_cores="2"
            ;;
        esac
    
        # some systems like the raspberry pi don't report cores, use at least 1
        if [ "$system_cpu_cores" -lt "1" ]
        then
            system_cpu_cores="1"
        fi
    
        # set max heap size based on the following
        # max(min(1/2 ram, 1024MB), min(1/4 ram, 8GB))
        # calculate 1/2 ram and cap to 1024MB
        # calculate 1/4 ram and cap to 8192MB
        # pick the max
        half_system_memory_in_mb=`expr $system_memory_in_mb / 2`
        quarter_system_memory_in_mb=`expr $half_system_memory_in_mb / 2`
        if [ "$half_system_memory_in_mb" -gt "1024" ]
        then
            half_system_memory_in_mb="1024"
        fi
        if [ "$quarter_system_memory_in_mb" -gt "8192" ]
        then
            quarter_system_memory_in_mb="8192"
        fi
        if [ "$half_system_memory_in_mb" -gt "$quarter_system_memory_in_mb" ]
        then
            max_heap_size_in_mb="$half_system_memory_in_mb"
        else
            max_heap_size_in_mb="$quarter_system_memory_in_mb"
        fi
        MAX_HEAP_SIZE="${max_heap_size_in_mb}M"
    
        # Young gen: min(max_sensible_per_modern_cpu_core * num_cores, 1/4 * heap size)
        max_sensible_yg_per_core_in_mb="100"
        max_sensible_yg_in_mb=`expr $max_sensible_yg_per_core_in_mb "*" $system_cpu_cores`
    
        desired_yg_in_mb=`expr $max_heap_size_in_mb / 4`
    
        if [ "$desired_yg_in_mb" -gt "$max_sensible_yg_in_mb" ]
        then
            HEAP_NEWSIZE="${max_sensible_yg_in_mb}M"
        else
            HEAP_NEWSIZE="${desired_yg_in_mb}M"
        fi
    }
    
    calculate_heap_sizes
    
    # Dynamically calculate parameters, for reference.
    #Xms=$MAX_HEAP_SIZE
    #Xmx=$MAX_HEAP_SIZE
    #Xmn=$HEAP_NEWSIZE
    #MaxDirectMemorySize=$MAX_HEAP_SIZE
    Xms=128m
    Xmx=128m
    Xmn=128m
    MaxDirectMemorySize=128m
    # Set for `JAVA_OPT`.
    JAVA_OPT="${JAVA_OPT} -server -Xms${Xms} -Xmx${Xmx} -Xmn${Xmn}"
    JAVA_OPT="${JAVA_OPT} -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -XX:SoftRefLRUPolicyMSPerMB=0 -XX:SurvivorRatio=8"
    JAVA_OPT="${JAVA_OPT} -verbose:gc -Xloggc:/dev/shm/mq_gc_%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy"
    JAVA_OPT="${JAVA_OPT} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m"
    JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow"
    JAVA_OPT="${JAVA_OPT} -XX:+AlwaysPreTouch"
    JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=${MaxDirectMemorySize}"
    JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages -XX:-UseBiasedLocking"
    JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib"
    #JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n"
    JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
    JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"
    
    numactl --interleave=all pwd > /dev/null 2>&1
    if [ $? -eq 0 ]
    then
    	if [ -z "$RMQ_NUMA_NODE" ] ; then
    		numactl --interleave=all $JAVA ${JAVA_OPT} $@
    	else
    		numactl --cpunodebind=$RMQ_NUMA_NODE --membind=$RMQ_NUMA_NODE $JAVA ${JAVA_OPT} $@
    	fi
    else
    	$JAVA ${JAVA_OPT} $@
    fi
    

    미러링 구축 지정 ROCKETMQVERSION
    docker build --no-cache -f Dockerfile-centos -t rocketmqinc/rocketmq:${ROCKETMQ_VERSION} --build-arg version=${ROCKETMQ_VERSION} .
    

    2, 두 주 두 비동기적으로 브러시 디스크 지우기,broker 설정
    broker-a.conf
    brokerClusterName=DefaultCluster
    brokerName=broker-a
    brokerId=0
    deleteWhen=04
    fileReservedTime=48
    brokerRole=ASYNC_MASTER
    flushDiskType=ASYNC_FLUSH
    
    # Host node's dns-name or ip
    brokerIP1=172.16.218.144
    
    # Optional config different value rather than default ports.
    # Caution: changing default ports need to update port mapping setting (-p) in start-broker.sh
    listenPort=10911
    #haListenPort=10912
    

    broker-a-s.conf
    brokerClusterName=DefaultCluster
    brokerName=broker-a
    brokerId=1
    deleteWhen=04
    fileReservedTime=48
    brokerRole=SLAVE
    flushDiskType=ASYNC_FLUSH
    
    
    #Slave host dns-name/ip
    brokerIP1=172.16.218.144
    #with Master's BroperIP1
    brokerIP2=172.16.218.144
    #         broker,      ,           
    listenPort=12911
    

    broker-b.conf
    brokerClusterName=DefaultCluster
    brokerName=broker-b
    brokerId=0
    deleteWhen=04
    fileReservedTime=48
    brokerRole=ASYNC_MASTER
    flushDiskType=ASYNC_FLUSH
    
    # Host node's dns-name or ip
    brokerIP1=172.16.218.144
    
    # Optional config different value rather than default ports.
    # Caution: changing default ports need to update port mapping setting (-p) in start-broker.sh
    #         broker,      ,           
    listenPort=11911
    #haListenPort=10912
    

    broker-b-s.conf
    brokerClusterName=DefaultCluster
    brokerName=broker-b
    brokerId=1
    deleteWhen=04
    fileReservedTime=48
    brokerRole=SLAVE
    flushDiskType=ASYNC_FLUSH
    
    
    #Slave host dns-name/ip
    brokerIP1=172.16.218.144
    #with Master's BroperIP1
    brokerIP2=172.16.218.144
    #         broker,      ,           
    listenPort=13911
    

    3. docker-Compose를 만듭니다.yml
    version: '3'
    services:
      namesrv:
        image: rocketmqinc/rocketmq:4.6.0
        container_name: rmqnamesrv
        ports:
          - 9876:9876
        volumes:
          - ./data/namesrv/logs:/home/rocketmq/logs
        command: sh mqnamesrv
        networks:
          rocketmq:
            ipv4_address: 172.23.0.2
            aliases:
              - namesrv
    
      broker-a:
        image: rocketmqinc/rocketmq:4.6.0
        container_name: rmqbroker-a
        links:
          - namesrv
        ports:
          - 10909:10909
          - 10911:10911
          - 10912:10912
        environment:
          - NAMESRV_ADDR=namesrv:9876
        volumes:
          - ./data1/broker/logs:/home/rocketmq/logs
          - ./data1/broker/store:/home/rocketmq/store
          - ./data1/broker/conf/broker-a.conf:/home/rocketmq/rocketmq-4.6.0/conf/broker-a.conf
        command: sh mqbroker -c ../conf/broker-a.conf
        networks:
          rocketmq:
            ipv4_address: 172.23.0.3
            aliases:
              - broker-a
    
      broker-b:
        image: rocketmqinc/rocketmq:4.6.0
        container_name: rmqbroker-b
        links:
          - namesrv
        ports:
          - 11909:10909
          - 11911:11911
          - 11912:10912
        environment:
          - NAMESRV_ADDR=namesrv:9876
        volumes:
          - ./data2/broker/logs:/home/rocketmq/logs
          - ./data2/broker/store:/home/rocketmq/store
          - ./data2/broker/conf/broker-b.conf:/home/rocketmq/rocketmq-4.6.0/conf/broker-b.conf
        command: sh mqbroker -c ../conf/broker-b.conf
        networks:
          rocketmq:
            ipv4_address: 172.23.0.4
            aliases:
            - broker-b
    
      broker-a-s:
        image: rocketmqinc/rocketmq:4.6.0
        container_name: rmqbroker-a-s
        links:
          - namesrv
        ports:
          - 12909:10909
          - 12911:12911
          - 12912:10912
        environment:
          - NAMESRV_ADDR=namesrv:9876
        volumes:
          - ./data3/broker/logs:/home/rocketmq/logs
          - ./data3/broker/store:/home/rocketmq/store
          - ./data3/broker/conf/broker-a-s.conf:/home/rocketmq/rocketmq-4.6.0/conf/broker-a-s.conf
        command: sh mqbroker -c ../conf/broker-a-s.conf
        networks:
          rocketmq:
            ipv4_address: 172.23.0.5
            aliases:
            - broker-a-s
    
      broker-b-s:
        image: rocketmqinc/rocketmq:4.6.0
        container_name: rmqbroker-b-s
        links:
          - namesrv
        ports:
          - 13909:10909
          - 13911:13911
          - 13912:10912
        environment:
          - NAMESRV_ADDR=namesrv:9876
        volumes:
          - ./data4/broker/logs:/home/rocketmq/logs
          - ./data4/broker/store:/home/rocketmq/store
          - ./data4/broker/conf/broker-b-s.conf:/home/rocketmq/rocketmq-4.6.0/conf/broker-b-s.conf
        command: sh mqbroker -c ../conf/broker-b-s.conf
        networks:
          rocketmq:
            ipv4_address: 172.23.0.6
            aliases:
            - broker-b-s
    
      rocketmq-console:
        image: styletang/rocketmq-console-ng
        container_name: rocketmq-console-ng
        links:
          - namesrv
        ports:
          - 8090:8080
        environment:
          - JAVA_OPTS=-Drocketmq.namesrv.addr=172.16.218.144:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false
        command: sh -c java JAVA_OPTS -jar /app.jar
        networks:
          rocketmq:
            ipv4_address: 172.23.0.7
            aliases:
            - rocketmq-console
    
    networks:
      rocketmq:
        driver: bridge
        ipam:
          driver: default
          config:
            - subnet: 172.23.0.0/16
    

    4、nameServer,broker,rocketmq-console-ng 실행
    docker-compose -f ./docker-compose/docker-compose.yml up -d
    

    5. 원본 다운로드
    이것은 원본 주소이니 여러분들은 참고하여 실천해 보십시오.https://github.com/baojingyu/docker-rocketmq/좋아하는 친구가 작은 별을 찍어요.

    좋은 웹페이지 즐겨찾기