centos7下安装RocketMQ

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/vipbupafeng/article/details/80287788

rocketmq依赖jdk,jdk安装参考:https://blog.csdn.net/vipbupafeng/article/details/80276557

1、下载apache最新rocketmq二进制压缩文件

下载地址:https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.2.0/rocketmq-all-4.2.0-bin-release.zip

在线下载:wget https://mirrors.tuna.tsinghua.edu.cn/apache/rocketmq/4.2.0/rocketmq-all-4.2.0-bin-release.zip

2、解压安装

解压:unzip -d /dirname rocketmq-all-4.2.0-bin-release.zip

3、环境变量

nameserver环境变量:vi /etc/profile

添加:export NAMESRV_ADDR=127.0.0.1:9876

source /etc/profile

4、启动

bin目录,启动nameserver和broker:

nohup sh mqnamesrv &

nohup sh mqbroker -n localhost:9876 &

查看进程:jps

启动broker时会卡顿,因为虚拟机内存和broker配置内存跟不上。

设置:给虚拟机预留1g的内存,这样启动时不太会卡:虚拟机设2g,nameserver和broker共用1g

清理缓存:echo 3 > /proc/sys/vm/drop_caches

5、启动失败

查看启动日志:cat nohup.out

启动失败: Native memory allocation (malloc) failed to allocate 8589934592 bytes for committing reserved memory.

因为nameserver和broker的默认配置内存超过虚拟机的内存,需根据宿主机配置调整虚拟机内存,并调整nameserver和broker的默认内存配置。

bin目录:

vi runserver.sh 

vi runbroker.sh

修改结果:

runserver.sh

runbroker.sh

6、启动成功后警告

bin目录:

vi mqadmin.xml  

vi mqbroker.xml  

vi mqnamesrv.xml  

vi mqfiltersrv.xml

删除红色部分:

vi tools.cmd

vi tools.sh

vi ../benchmark/runclass.sh

删除红色部分:

7、查看日志

启动成功后查看mq动态日志:

tail -f ~/logs/rocketmqlogs/namesrv.log

tail -f ~/logs/rocketmqlogs/broker.log

8、调试过程中的问题

代码是基于springboot的简单示例

配置正确情况下,启动后尝试发布消息,仍报远程mq服务器topic不存在异常。

检查linux防火墙:service firewalld status

因centos7默认使用firewalld防火墙,而不是iptables,卸载firewalld,再安装iptables

步骤:

卸载firewalld:yum remove firewalld

安装iptables:yum install iptables-services

查看防火墙状态:service iptables status

停止防火墙:service iptables stop

启动防火墙:service iptables start

设为开机不启动:systemctl disable iptables.service

设为开机启动:systemctl enable iptables.service

如果要开启防火墙,则需要开放特定端口,例:开放3306端口

编辑:vi /etc/sysconfig/iptables

添加配置:-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

重启防火墙使配置生效:systemctl restart iptables.service

其它相关命令:

查看防火墙规则:iptables -L

清空防火墙规则:iptables -F

保存使操作生效:/etc/sysconfig/iptables save

停止防火墙:/etc/sysconfig/iptables stop

9、关闭服务

sh mqshutdown namesrv

sh mqshutdown broker

或者通过jps查看进程,使用kill -9 pid结束进程(有时会看不见进程,但是服务仍在运行,建议用mqshutdown关闭服务)。

猜你喜欢

转载自blog.csdn.net/vipbupafeng/article/details/80287788