RocketMq安装与启动

官方网站

http://rocketmq.apache.org

GitHub

https://github.com/apache/rocketmq

在Linux上安装Maven

下载Maven

wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

添加阿里云镜像

修改maven/conf目录下的settings.xml

mirrors节点下添加

<mirror> 
    <id>aliyun-maven</id> 
    <mirrorOf>*</mirrorOf> 
    <name>aliyun maven</name> 
    <url>http://maven.aliyun.com/nexus/content/groups/public</url> 
</mirror>

配置maven环境变量

修改/etc/profile

export M2_HOME=/usr/local/maven
export PATH=$PATH:$M2_HOME/bin

配置java环境变量

export JAVA_HOME="/usr/java/jdk1.8.0_181-amd64"
export CLASS_PATH="$JAVA_HOME/lib"
export PATH=".$PATH:$JAVA_HOME/bin"

环境变量修完执行source /etc/profile立即生效

查看java安装目录

所有类安装所在目录

java -verbose

查看JAVA_HOME

echo $JAVA_HOME

Linux下使用Maven编译Rocket源码并安装

Rocketmq4.6+需要jdk1.8环境编译和运行

参考文章

下载源码包

rocketmq-all-4.6.1-source-release.zip

解压包并编译源码

unzip rocketmq-all-4.6.1-source-release.zip

移动文件到指定目录/usr/local/下

mv rocketmq-all-4.6.1-source-release/ /usr/local/rocketmq-all-4.6.1/

切换到/usr/local/rocketmq-all-4.6.1/目录下

cd /usr/local/rocketmq-all-4.6.1/

执行meaven编译源码命令

mvn -Prelease-all -DskipTests clean install -U

找到编译后的文件

cd distribution/target/rocketmq-4.6.1/

移动编译后的文件到指定目录下

mv rocketmq-4.6.1/ /usr/local/rocketmq-4.6.1/

切换到/usr/local/rocketmq-4.6.1/bin/目录下

cd /usr/local/rocketmq-4.6.1/bin/

创建日志文件夹

mkdir /usr/local/rocketmq-4.6.1/mylog/rocketmqlogs/

Start Name Server(注册中心)

nohup sh ./mqnamesrv > /usr/local/rocketmq-4.6.1/mylog/rocketmqlogs/namesrv.log &

查看日志

tail -f /usr/local/rocketmq-4.6.1/mylog/rocketmqlogs/namesrv.log
# 启动成功标志
# The Name Server boot success. serializeType=JSON

Start Broker(具体服务)

# -n localhost:9876指定对应的namesrv
nohup sh ./mqbroker -n localhost:9876 > /usr/local/rocketmq-4.6.1/mylog/rocketmqlogs/mqbroker.log &

# 执行出错
# Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000005c0000000, 8589934592, 0) failed; error='Cannot # # allocate memory' (errno=12)
# 可以看出是分配的内存不够用

原来,执行./mqbroker其实是执行./runbroker.sh

查看./runserver.sh./runbroker.sh启动时分配的内存

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

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

发现 runbroker.sh 分配的内存过大

修改启动时分配的内存

# runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn128m"

重新启动./mqbroker

查看日志

tail -f /usr/local/rocketmq-4.6.1/mylog/rocketmqlogs/mqbroker.log
# 启动成功标志
# The broker[dandanRoot, 192.168.1.113:10911] boot success. serializeType=JSON

发现执行成功

可能出现的另一个错误

找不到 host name,此时需要在 /etc/hosts 中配置对应的host

Send & Receive Messages(测试)

/tools.sh中添加配置

export NAMESRV_ADDR=localhost:9876

执行测试脚本

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
# 出现错误
# org.apache.rocketmq.client.exception.MQClientException: No route info of this topic: TopicTest
# 启动./mqbroker时要带上参数 -n localhost:9876,不然连不到注册中心 namesrv
# 重新启动
# nohup sh ./mqbroker -n localhost:9876 > /usr/local/rocketmq-4.6.1/mylog/rocketmqlogs/mqbroker.log &
# 发送消息成功
# SendResult [sendStatus=SEND_OK, msgId=C0A8017C00006BC7C0546460AEE203E7, offsetMsgId=C0A8017100002A9F00000000000317BF, messageQueue=MessageQueue [topic=TopicTest, brokerName=dandanRoot, queueId=2], queueOffset=249]


sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
# 接收消息成功
# ConsumeMessageThread_9 Receive New Messages: [MessageExt [queueId=3, storeSize=203, queueOffset=200, sysFlag=0, bornTimestamp=1637380057502, bornHost=/192.168.1.113:36340, storeTimestamp=1637380057502, storeHost=/192.168.1.113:10911, msgId=C0A8017100002A9F00000000000279F2, commitLogOffset=162290, bodyCRC=265672385, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=250, CONSUME_START_TIME=1637380061726, UNIQ_KEY=C0A8017C00006BC7C0546460AD9E0320, CLUSTER=DefaultCluster, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 56, 48, 48], transactionId='null'}]] 

Shutdown Servers

sh bin/mqshutdown broker

sh bin/mqshutdown namesrv

控制台rocketmq-console编译安装

下载

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

下载地址

得到安装包 rocketmq-externals-master.zip

中文指南

https://github.com/apache/rocketmq-externals/blob/master/rocketmq-console/doc/1_0_0/UserGuide_CN.md

上传到服务器并解压缩

unzip rocketmq-externals-master.zip

得到 rocketmq-externals-master

编译

进入rocketmq-console目录

执行编译

mvn clean package -Dmaven.test.skip=true

启动

编译成功后在rocketmq-console/target目录下执行rocketmq-console-ng-1.0.1.jar

启动时,直接动态添加nameserver地址或编辑application.properties添加属性

java -jar rocketmq-console-ng-1.0.1.jar --rocketmq.config.namesrvAddr=127.0.0.1:9876

启动成功后访问服务器8080端口即可
添加--rocketmq.config.namesrvAddr=127.0.0.1:9876命令的替代方案,在console的页面中,在opt的NameSvrAddrList中添加192.168.1.113:9876,按enter键,按UPDATE按钮即可

pom.xml依赖

 <dependency>
        <groupId>org.apache.rocketmq</groupId>
        <artifactId>rocketmq-client</artifactId>
        <version>4.6.1</version>
 </dependency>

安装启动常见错误

编译时包无法在mirror上找到 提示502错误

原因:网络不好或maven仓库服务器出错

重试即可,或者欢迎镜像仓库

发送失败提示connect to null failed

 ./tools.sh org.apache.rocketmq.example.quickstart.Producer
22:49:02.470 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework
RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.PlatformDependent0).
RocketMQLog:WARN Please initialize the logger system properly.
java.lang.IllegalStateException: org.apache.rocketmq.remoting.exception.RemotingConnectException: connect to
 null failed

原因:不知道nameserver在哪儿

tools脚本中添加

export NAMESRV_ADDR=localhost:9876

启动broker失败 Cannot allocate memory

原因:jvm启动初始化内存分配大于物理内存

[root@node-113b bin]# ./mqbroker -n localhost:9876
Java HotSpot(TM) 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:
# /usr/local/rocketmq/bin/hs_err_pid1997.log

修改启动脚本中的jvm参数

runbroker.sh broker

runserver.sh nameserver

默认数值给的都很大,改小即可

JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=100m"

启动broker成功但提示:Failed to obtain the host name

[root@node-113b bin]# ./mqbroker -n localhost:9876
22:30:42.307 [main] ERROR RocketmqCommon - Failed to obtain the host name
java.net.UnknownHostException: node-113b: node-113b: No address associated with hostname
	at java.net.InetAddress.getLocalHost(InetAddress.java:1505) ~[na:1.8.0_181]
	at org.apache.rocketmq.common.BrokerConfig.localHostName(BrokerConfig.java:189) [rocketmq-common-4.6
.1.jar:4.6.1]	at org.apache.rocketmq.common.BrokerConfig.<init>(BrokerConfig.java:38) [rocketmq-common-4.6.1.jar:4
.6.1]	at org.apache.rocketmq.broker.BrokerStartup.createBrokerController(BrokerStartup.java:110) [rocketmq
-broker-4.6.1.jar:4.6.1]	at org.apache.rocketmq.broker.BrokerStartup.main(BrokerStartup.java:58) [rocketmq-broker-4.6.1.jar:4
.6.1]Caused by: java.net.UnknownHostException: node-113b: No address associated with hostname
	at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[na:1.8.0_181]
	at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928) ~[na:1.8.0_181]
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323) ~[na:1.8.0_181]
	at java.net.InetAddress.getLocalHost(InetAddress.java:1500) ~[na:1.8.0_181]
	... 4 common frames omitted
The broker[DEFAULT_BROKER, 192.168.150.213:10911] boot success. serializeType=JSON and name server is localh
ost:9876

原因:无法解析当前的主机名

hosts里添加映射即可

192.168.150.213 node-113b

错误:Caused by: org.apache.rocketmq.remoting.exception.RemotingConnectException: connect to 172.17.0.1:10911 failed

# 外网连接不到指定ip
在broker.conf中配置
brokerIP1=192.168.1.113
namesrvAddr=192.168.1.113:9876

# 关闭启动mqname服务
sh bin/mqshutdown namesrv
nohup sh bin/mqnamesrv &
 
# 关闭启动mqbroker配置
sh bin/mqshutdown broker
nohup sh bin/mqbroker -c conf/broker.conf &

参考文章:https://blog.csdn.net/qq_40202111/article/details/106668494https://blog.csdn.net/qq_40202111/article/details/106668494

控制台rocketmq-console编译安装docker版

参考链接:https://rocketmq-1.gitbook.io/rocketmq-connector/rocketmq-connect/rocketmq-console/an-zhuang-shi-yong

获取Docker镜像

docker pull styletang/rocketmq-console-ng

运行

docker run -e "JAVA_OPTS=-Drocketmq.namesrv.addr=127.0.0.1:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" -p 9080:8080 -t styletang/rocketmq-console-ng

访问

# 使用自己的ip
# 9080是远程访问的端口
http://192.168.1.113:9080/

linux日期校准

安装ntpdate

yum install ntpdate

ntpdate ntp1.aliyun.com
posted @ 2021-11-20 14:55  龙宇在天  阅读(1530)  评论(0编辑  收藏  举报
//右侧添加目录 //增加页面点击显示24字社会主义核心价值观