首先介绍一下RocketMq依赖的必备环境:
1.JDK1.8安装完成,配置环境变量:JDK1.8安装
2.Maven3.6.3安装完成,配置环境变量;
一、下载并解压缩RocketMq
- 下载压缩包:
wget http://mirror.bit.edu.cn/apache/rocketmq/4.7.1/rocketmq-all-4.7.1-bin-release.zip
- 解压缩:
unzip rocketmq-all-4.7.1-bin-release.zip
注意:如果unzip命令不能使用,则需要安装;
yum install unzip #提示输入时,请输入y;
解压缩后文件夹名字过长,大家可以选择重命名:
mv rocketmq-all-4.7.1-bin-release rocketmq-4.7.1-bin
二、安装:
- 创建自定义存储目录:
在rocketmq-4.7.1-bin文件夹下创建logs,store文件夹。
在store下创建commitlog、consumequeue和index文件夹。
logs:主要用于存储RocketMQ日志目录;
store:主要用于存储RocketMQ数据文件目录;
commitlog:主要用于存储RocketMQ消息信息;
consumequeue、index:主要用于存储消息的索引数据;
- 修改运行内存:
RocketMQ默认的虚拟机内存较大,启动Broker如果因为内存不足失败,避免后面启动失败,溪源选择先修改其内存大小,一般阿里云服务器是满足不了默认内存。
主要编辑如下两个配置文件,修改JVM内存大小。
切换到/bin目录下:
# 编辑runbroker.sh和runserver.sh修改默认JVM大小
vi runbroker.sh
vi runserver.sh
参考设置:注意这里是m为单位
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn8g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
修改后如图:
runbroker.sh
原:JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn8g"
修改后如图:
- xml文件路径修改:
cd /opt/software/rocketmq/rocketmq-4.7.1-bin/conf以自己安装目录为准,切换到/conf目录下;
把该文件夹下xml文件,里的{user.home}替换成 /opt/software/rocketmq/rocketmq-4.7.1-bin;
sed -i 's#${user.home}# /opt/software/rocketmq/rocketmq-4.7.1-bin#g' *.xml
- 修改broker.conf配置
cd /opt/software/rocketmq/rocketmq-4.7.1-bin/conf
vi broker.conf
namesrvAddr={你自己的阿里云服务器外网IP或者内网IP}:9876
brokerIP1={你自己的阿里云服务器外网IP}
brokerName=james
brokerClusterName=DefaultCluster
brokerId=0
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
- 开放端口和阿里云服务入网规则:
firewall-cmd --zone=public --add-port=9876/tcp --permanent
firewall-cmd --zone=public --add-port=10911/tcp --permanent
firewall-cmd --reload # 配置立即生效
阿里云配置入网规则:
三、启动:
启动之前一定要切换到rocketmq安装目录下bin
- 启动NameServer
# 1.启动NameServer
[root@izbp14najjyuhkvm4qbic7z bin]# nohup sh mqnamesrv &
[1] 7164
[root@izbp14najjyuhkvm4qbic7z bin]# nohup: ignoring input and appending output to ‘nohup.out’
启动日志
[root@izbp14najjyuhkvm4qbic7z bin]# tail -f nohup.out
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
- 启动Broker
# 1.启动Broker,9876是NameServer应用的端口号,与nameserver建立连接
[root@izbp14najjyuhkvm4qbic7z bin]# nohup sh bin/mqbroker -n localhost:9876
启动日志
[root@izbp14najjyuhkvm4qbic7z bin]# tail -f nohup.out
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
- 输入 jps 命令,查看Java进程
#说明 NamesrvStartup,BrokerStartup两个服务启动成功
21251 Jps
21175 BrokerStartup
20989 NamesrvStartup
- 关闭RocketMQ
# 1.关闭NameServer
sh bin/mqshutdown namesrv
# 2.关闭Broker
sh bin/mqshutdown broker
转载:https://blog.csdn.net/xuan_lu/article/details/107722655