说明:
我的阿里云是centos 7
jdk 1.8.0_192-b12(安装教程参照:https://www.cnblogs.com/kingsonfu/p/9801556.html)
maven apache-maven-3.6.1(安装教程参照:https://www.cnblogs.com/yangyuke1994/p/10592055.html)
- 安装jdk,配置环境变量
- 安装maven,配置环境变量
- 下载部署RocketMQ
新建rocketmq目录(/usr/local),
下载依赖 wget http://mirror.bit.edu.cn/apache/rocketmq/4.7.0/rocketmq-all-4.7.0-source-release.zip(版本可能不同导致网页不存在,先访问这个替换版本 =》http://mirror.bit.edu.cn/apache/rocketmq/)
解压 unzip rocketmq-all-4.5.2-source-release.zip
如果提示 -bash: unzip: command not found,说明没有找到命令,安装unzip即可 yum install -y unzip zip
进入 rocketmq-all-4.7.0-source-release - 启动namesrv
修改runserver.sh的默认内存,/usr/local/rocketmq-all-4.7.0-source-release/bin
#这是RocketMQ默认值
JAVA_OPT="KaTeX parse error: Expected 'EOF', got '#' at position 91: …paceSize=320m" #̲这是修改后的值 JAVA_OP…{JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
启动服务 nohup sh mqnamesrv > /dev/null 2>&1 &
查看namesrv服务日志,确认是否成功启动,默认日志路径 /root/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
- 启动broker
修改broker启动脚本的默认内存配置
#这是默认值
JAVA_OPT="KaTeX parse error: Expected 'EOF', got '#' at position 42: …-Xmx8g -Xmn4g" #̲这是修改后的值 JAVA_OP…{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 - 特别注意:
nameserver端口默认为 9876
broker监听端口默认为 10911
这两个端口务必一定要在阿里云安全组里对外暴露
关闭namesrv服务 sh mqshutdown namesrv,关闭broker服务 sh mqshutdown broker - 安装 rocketmq-console 控制台
第一步:下载rocketmq-console。
链接:https://pan.baidu.com/s/1EyD2Djx7YZo1XU3e_P0D5w
提取码:56a7
第二步:将下载的zip上传到服务器(我放在rocketmq目录下),将其解压,并且修改vim application.properties 中的 rocketmq.config.namesrvAddr=namesrv服务地址(ip1:port;ip2:port)
第三步:编译rocketmq-console
编译命令:mvn clean package -Dmaven.test.skip=true(注意:不要直接使用mvn package,会提示很多错误,在rocketmq-console的目录下执行),编译成功后,在rocketmq-console目录下会生成一个目录:target目录,该目录下有启动rocketmq界面的jar文件
第四部:启动web(usr/local/rocketmq-externals-master/rocketmq-console/target目录下)
java -jar rocketmq-console-ng-1.0.0.jar 启动 —当终端断了该服务就会停止
nohup java -jar rocketmq-console-ng-1.0.0.jar >>/usr/logs/log.out 2>&1 & 后台启动 --当终端断了也不会停止服务
第五步:记得开放阿里云服务器的8080端口