20210329 0. RocketMQ 安装 - 拉勾教育

环境信息

  • Java 版本:1.8
  • CentOS 7
  • RocketMQ 4.8.0

安装过程

  1. 将压缩文件解压到 /rocketmq 目录

  2. 启动 NameServer

    # bin 目录下
    ./mqnamesrv
    OpenJDK 64-Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release
    OpenJDK 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
    OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000006c0000000, 2147483648, 0) failed; error='Cannot allocate memory' (errno=12)
    #
    # There is insufficient memory for the Java Runtime Environment to continue.
    # Native memory allocation (mmap) failed to map 2147483648 bytes for committing reserved memory.
    # An error report file with more information is saved as:
    # /rocketmq/rocketmq-all-4.8.0-bin-release/bin/hs_err_pid3019.log
    

    原因:虚拟机内存不足,需要调整 JVM 启动参数

    #	runserver.sh
    # JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
    JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=160m"
    

    调整参数后启动成功

    # 查看 NameServer 日志,日志默认生成在 ~/logs
    tail -f ~/logs/rocketmqlogs/namesrv.log
    
  3. 启动 Broker

    [root@hwjlinux bin]# ./mqbroker -n localhost:9876
    OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
    OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000005c0000000, 8589934592, 0) failed; error='Cannot allocate memory' (errno=12)
    #
    # There is insufficient memory for the Java Runtime Environment to continue.
    # Native memory allocation (mmap) failed to map 8589934592 bytes for committing reserved memory.
    # An error report file with more information is saved as:
    # /rocketmq/rocketmq-all-4.8.0-bin-release/bin/hs_err_pid3529.log
    

    原因:虚拟机内存不足,需要调整 JVM 启动参数

    # runbroker.sh
    # JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"
    JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"
    

    修改后再次启动成功

    使用 -c 指定配置文件

  4. 调整 /etc/profile 内容

    #	/etc/profile 内增加内容
    export ROCKET_HOME=/rocketmq/rocketmq-all-4.8.0-bin-release
    export PATH=$PATH:$ROCKET_HOME/bin
    
    #	使配置生效
    source /etc/profile
    
  5. 关闭 RocketMQ

    # 1.关闭NameServer
    mqshutdown namesrv
    # 2.关闭Broker
    mqshutdown broker
    

RocketMQ 环境测试

  1. 修改 tool.sh

    # JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m"
    JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=64m"
    
  2. 先启动消费者,等待接收消息

    # 1.设置环境变量
    export NAMESRV_ADDR=localhost:9876
    # 2.接收消息
    tools.sh org.apache.rocketmq.example.quickstart.Consumer
    
  3. 后启动生产者,发送消息

    # 1.设置环境变量
    export NAMESRV_ADDR=localhost:9876
    # 2.使用安装包的Demo发送消息
    tools.sh org.apache.rocketmq.example.quickstart.Producer
    
posted @ 2021-03-29 16:54  流星<。)#)))≦  阅读(204)  评论(0编辑  收藏  举报