阿里云安装RocketMQ

    1. 安装jdk,配置环境变量

    2. 安装maven,配置环境变量

    3. 下载部署RocketMQ

      • 新建rocketmq目录,下载依赖 wget http://mirror.bit.edu.cn/apache/rocketmq/4.5.2/rocketmq-all-4.5.2-source-release.zip
      • 解压 unzip rocketmq-all-4.5.2-source-release.zip
      • 如果提示 -bash: unzip: command not found,说明没有找到命令,安装unzip即可 yum install -y unzip zip
      • 进入 rocketmq-all-4.5.2-source-release 目录构建项目 mvn -Prelease-all -DskipTests clean install -U 构建过程比较耗时,需要下载很多依赖)
        [INFO] ------------------------------------------------------------------------
        [INFO] Reactor Summary for Apache RocketMQ 4.5.2 4.5.2:
        [INFO]
        [INFO] Apache RocketMQ 4.5.2 .............................. SUCCESS [16:08 min]
        [INFO] rocketmq-logging 4.5.2 ............................. SUCCESS [02:33 min]
        [INFO] rocketmq-remoting 4.5.2 ............................ SUCCESS [04:01 min]
        [INFO] rocketmq-common 4.5.2 .............................. SUCCESS [  4.037 s]
        [INFO] rocketmq-client 4.5.2 .............................. SUCCESS [02:15 min]
        [INFO] rocketmq-store 4.5.2 ............................... SUCCESS [01:46 min]
        [INFO] rocketmq-srvutil 4.5.2 ............................. SUCCESS [  0.453 s]
        [INFO] rocketmq-filter 4.5.2 .............................. SUCCESS [01:46 min]
        [INFO] rocketmq-acl 4.5.2 ................................. SUCCESS [  4.938 s]
        [INFO] rocketmq-broker 4.5.2 .............................. SUCCESS [  7.455 s]
        [INFO] rocketmq-tools 4.5.2 ............................... SUCCESS [  2.229 s]
        [INFO] rocketmq-namesrv 4.5.2 ............................. SUCCESS [  1.095 s]
        [INFO] rocketmq-logappender 4.5.2 ......................... SUCCESS [  3.447 s]
        [INFO] rocketmq-openmessaging 4.5.2 ....................... SUCCESS [  2.441 s]
        [INFO] rocketmq-example 4.5.2 ............................. SUCCESS [  1.075 s]
        [INFO] rocketmq-test 4.5.2 ................................ SUCCESS [  5.868 s]
        [INFO] rocketmq-distribution 4.5.2 ........................ SUCCESS [11:18 min]
        [INFO] ------------------------------------------------------------------------
        [INFO] BUILD SUCCESS
        [INFO] ------------------------------------------------------------------------
    4. 启动namesrv

      • 修改runserver.sh的默认内存(如果是土豪配置,可以忽略) /rocketmq/rocketmq-all-4.5.2-source-release/distribution/target/rocketmq-4.5.2/rocketmq-4.5.2/bin
        #这是RocketMQ默认值
        JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
        
        #这是修改后的值
        JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
      • 启动服务 nohup sh mqnamesrv > /dev/null 2>&1 &
      • 查看namesrv服务日志,确认是否成功启动,默认日志路径 ${user.home}/logs/rocketmqlogs/namesrv.log,如下所示表明启动成功
        2019-08-28 10:42:11 INFO main - tls.client.authServer = false
        2019-08-28 10:42:11 INFO main - tls.client.trustCertPath = null
        2019-08-28 10:42:12 INFO main - Using OpenSSL provider
        2019-08-28 10:42:12 INFO main - SSLContext created for server
        2019-08-28 10:42:12 INFO main - Try to start service thread:FileWatchService started:false lastThread:null
        2019-08-28 10:42:12 INFO main - The Name Server boot success. serializeType=JSON 2019-08-28 10:42:12 INFO FileWatchService - FileWatchService service started 2019-08-28 10:42:12 INFO NettyEventExecutor - NettyEventExecutor service started
    5. 启动broker

      • 修改broker启动脚本的默认内存配置
        #这是默认值
        JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"
        
        #这是修改后的值
        JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512g"
      • 创建broker.conf配置文件,内容如下

        namesrvAddr={你自己的阿里云服务器外网IP或者内网IP}:9876
        brokerIP1={你自己的阿里云服务器外网IP}
        brokerName=james
        brokerClusterName=DefaultCluster
        brokerId=0
        autoCreateTopicEnable=true
        autoCreateSubscriptionGroup=true
      • 启动服务 nohup sh mqbroker -c broker.conf> /dev/null 2>&1 &

      • 查看broker启动日志    
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_192]
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_192]
            at java.lang.Thread.run(Thread.java:748) [na:1.8.0_192]
        2019-08-28 11:04:35 INFO TransactionalMessageCheckService - create new topic TopicConfig [topicName=RMQ_SYS_TRANS_HALF_TOPIC, readQueueNums=1, writeQueueNums=1, perm=RW-, topicFilterType=SINGLE_TAG, topicSysFlag=0, order=false]
        2019-08-28 11:04:38 WARN brokerOutApi_thread_4 - registerBroker Exception, 你的阿里云服务器IP:9876
        org.apache.rocketmq.remoting.exception.RemotingConnectException: connect to <你的阿里云服务器IP:9876> failed
            at org.apache.rocketmq.remoting.netty.NettyRemotingClient.invokeOneway(NettyRemotingClient.java:556) ~[rocketmq-remoting-4.5.2.jar:4.5.2]
            at org.apache.rocketmq.broker.out.BrokerOuterAPI.registerBroker(BrokerOuterAPI.java:187) ~[rocketmq-broker-4.5.2.jar:4.5.2]
            at org.apache.rocketmq.broker.out.BrokerOuterAPI.access$000(BrokerOuterAPI.java:61) ~[rocketmq-broker-4.5.2.jar:4.5.2]
            at org.apache.rocketmq.broker.out.BrokerOuterAPI$1.run(BrokerOuterAPI.java:150) ~[rocketmq-broker-4.5.2.jar:4.5.2]
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_192]
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_192]
            at java.lang.Thread.run(Thread.java:748) [na:1.8.0_192]
      • 出现上面这种情况,首先去阿里云上检查是否对外暴露了9876端口,如果没有,在阿里云上添加对外暴露9876端口(安全组 -> 配置规则 -> 添加安全组规则)
      • 添加完毕,后重启broker服务,提示如下,就说明启动成功
        2019-08-28 11:10:54 INFO PullRequestHoldService - PullRequestHoldService service started
        2019-08-28 11:10:54 INFO brokerOutApi_thread_1 - register broker[0]to name server 你的阿里云服务器IP:9876 OK
        2019-08-28 11:10:54 INFO main - The broker[james, 47.105.147.14:10911] boot success. serializeType=JSON and name server is 你的阿里云服务器IP:9876
      • 输入 jps 命令,查看Java进程
        #说明 NamesrvStartup,BrokerStartup两个服务启动成功
        21251 Jps
        21175 BrokerStartup
        20989 NamesrvStartup
    6. 特别注意:

      • nameserver端口默认为 9876
      • broker监听端口默认为 10911
      • 这两个端口务必一定要在阿里云安全组里对外暴露
    7. 关闭namesrv服务 sh mqshutdown namesrv,关闭broker服务 sh mqshutdown broker

    8. 安装 rocketmq-console 控制台

      • https://github.com/apache/rocketmq-externals.git

      • 选择 rocketmq-console 模块中加入maven,修改resources目录下的application.properties文件
        server.contextPath=
        server.port=8080
        
        ### SSL setting
        #server.ssl.key-store=classpath:rmqcngkeystore.jks
        #server.ssl.key-store-password=rocketmq
        #server.ssl.keyStoreType=PKCS12
        #server.ssl.keyAlias=rmqcngkey
        
        #spring.application.index=true
        spring.application.name=rocketmq-console
        spring.http.encoding.charset=UTF-8
        spring.http.encoding.enabled=true
        spring.http.encoding.force=true
        logging.config=classpath:logback.xml
        #if this value is empty,use env value rocketmq.config.namesrvAddr  NAMESRV_ADDR | now, you can set it in ops page.default localhost:9876
        rocketmq.config.namesrvAddr=你的阿里云服务器IP:9876
        #if you use rocketmq version < 3.5.8, rocketmq.config.isVIPChannel should be false.default true
        rocketmq.config.isVIPChannel=false
        #rocketmq-console's data path:dashboard/monitor
        rocketmq.config.dataPath=/tmp/rocketmq-console/data
        #set it false if you don't want use dashboard.default true
        rocketmq.config.enableDashBoardCollect=true
        #set the message track trace topic if you don't want use the default one
        rocketmq.config.msgTrackTopicName=james
        rocketmq.config.ticketKey=ticket
        
        #Must create userInfo file: ${rocketmq.config.dataPath}/users.properties if the login is required
        rocketmq.config.loginRequired=false
posted @ 2019-08-27 23:21  KingJames、  阅读(2620)  评论(0编辑  收藏  举报