centos下安装rocketmq4.6.1
1.前提条件
2. 下载rocket源码
wget -O rocketmq-release-4.6.1.zip https://codeload.github.com/apache/rocketmq/zip/release-4.6.1
3.解压缩
unzip rocketmq-release-4.6.1.zip -d /opt/myprogram/rocketmq
4. 编译源码
cd /opt/myprogram/rocketmq/rocketmq-release-4.6.1
mvn -Prelease-all -DskipTests clean install -U
mvn参数说明 (-Pxxx 激活 id 为 xxx的profile (如有多个,用逗号隔开) -Dxxx=yyy 指定Java全局属性; -U 强制更新snapshot类型的插件或依赖库(否则maven一天只会更新一次snapshot依赖))
编译等待中....
编译结果
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ rocketmq-distribution --- [INFO] Installing /opt/myprogram/rocketmq/rocketmq-release-4.6.1/distribution/pom.xml to /root/.m2/repository/org/apache/rocketmq/rocketmq-distribution/4.6.1/rocketmq-distribution-4.6.1.pom [INFO] Installing /opt/myprogram/rocketmq/rocketmq-release-4.6.1/distribution/target/rocketmq-4.6.1.tar.gz to /root/.m2/repository/org/apache/rocketmq/rocketmq-distribution/4.6.1/rocketmq-distribution-4.6.1.tar.gz [INFO] Installing /opt/myprogram/rocketmq/rocketmq-release-4.6.1/distribution/target/rocketmq-4.6.1.zip to /root/.m2/repository/org/apache/rocketmq/rocketmq-distribution/4.6.1/rocketmq-distribution-4.6.1.zip [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary for Apache RocketMQ 4.6.1 4.6.1: [INFO] [INFO] Apache RocketMQ 4.6.1 .............................. SUCCESS [ 16.273 s] [INFO] rocketmq-logging 4.6.1 ............................. SUCCESS [ 8.712 s] [INFO] rocketmq-remoting 4.6.1 ............................ SUCCESS [ 4.748 s] [INFO] rocketmq-common 4.6.1 .............................. SUCCESS [ 9.049 s] [INFO] rocketmq-client 4.6.1 .............................. SUCCESS [ 13.836 s] [INFO] rocketmq-store 4.6.1 ............................... SUCCESS [ 6.803 s] [INFO] rocketmq-srvutil 4.6.1 ............................. SUCCESS [ 1.659 s] [INFO] rocketmq-filter 4.6.1 .............................. SUCCESS [ 3.536 s] [INFO] rocketmq-acl 4.6.1 ................................. SUCCESS [ 2.983 s] [INFO] rocketmq-broker 4.6.1 .............................. SUCCESS [ 6.795 s] [INFO] rocketmq-tools 4.6.1 ............................... SUCCESS [ 4.952 s] [INFO] rocketmq-namesrv 4.6.1 ............................. SUCCESS [ 1.891 s] [INFO] rocketmq-logappender 4.6.1 ......................... SUCCESS [ 1.838 s] [INFO] rocketmq-openmessaging 4.6.1 ....................... SUCCESS [ 2.061 s] [INFO] rocketmq-example 4.6.1 ............................. SUCCESS [ 2.673 s] [INFO] rocketmq-test 4.6.1 ................................ SUCCESS [ 3.626 s] [INFO] rocketmq-distribution 4.6.1 ........................ SUCCESS [ 16.986 s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 01:49 min [INFO] Finished at: 2020-12-30T15:27:45+08:00 [INFO] ------------------------------------------------------------------------
5. 进入编译好的bin目录
[root@VM-0-7-centos bin]# cd /opt/myprogram/rocketmq/rocketmq-release-4.6.1/distribution/target/rocketmq-4.6.1/rocketmq-4.6.1/bin [root@VM-0-7-centos bin]# ls cachedog.sh cleancache.v1.sh mqadmin mqbroker mqbroker.numanode0 mqbroker.numanode2 mqnamesrv mqshutdown os.sh play.sh runbroker.cmd runserver.cmd setcache.sh tools.cmd cleancache.sh dledger mqadmin.cmd mqbroker.cmd mqbroker.numanode1 mqbroker.numanode3 mqnamesrv.cmd mqshutdown.cmd play.cmd README.md runbroker.sh runserver.sh startfsrv.sh tools.sh
6. 启动nameserver
注意,这里直接启动,如果服务器内存比较小, 会报内存不够. 需要先修改配置, 踩坑参考
./mqnamesrv
7. 修改nameserver启动参数
vi /opt/myprogram/rocketmq/rocketmq-release-4.6.1/distribution/target/rocketmq-4.6.1/rocketmq-4.6.1/bin/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=128m"
8. 修改broker启动参数
vi /opt/myprogram/rocketmq/rocketmq-release-4.6.1/distribution/target/rocketmq-4.6.1/rocketmq-4.6.1/bin/runbroker.sh
原内容
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"
修改后内容(可根据实际情况调整)
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"
9.启动nameserver
[root@VM-0-7-centos bin]# ./mqnamesrv Java HotSpot(TM) 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 Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release. The Name Server boot success. serializeType=JSON
10.启动broker
[root@VM-0-7-centos bin]# ./mqbroker -n 127.0.0.1:9876 The broker[VM-0-7-centos, 172.17.0.1:10911] boot success. serializeType=JSON and name server is 127.0.0.1:9876
或者
nohup sh mqbroker -n 127.0.0.1:9876 autoCreateTopicEnable=true > ~/logs/rocketmqlogs/broker.log 2>&1 &
11. java代码
rocketmq使用java发送与接受消息
12.踩坑记录
整合RocketMq提示RemotingTooMuchRequestException: sendDefaultImpl call timeout
org.apache.rocketmq.client.exception.MQClientException: No route info of this topic, TopicTest异常解决
13. 如果是用云服务器
conf/broker.conf增加配置
vi /opt/myprogram/rocketmq/rocketmq-release-4.6.1/distribution/target/rocketmq-4.6.1/rocketmq-4.6.1/conf/broker.conf
增加配置
namesrvAddr = 云服务器公网IP:9876 brokerIP1 = 云服务器公网IP
需要用下面命令启动
nohup sh mqbroker -n 127.0.0.1:9876 -c ../conf/broker.conf autoCreateTopicEnable=true > ~/logs/rocketmqlogs/broker.log 2>&1 &