一、CentOS 7.9 安装 rocketmq-4.9.2
地址:
- https://rocketmq.apache.org
- https://github.com/apache/rocketmq
- https://archive.apache.org/dist/rocketmq/4.9.2/rocketmq-all-4.9.2-bin-release.zip
二、下载RocketMQ
wget https://archive.apache.org/dist/rocketmq/4.9.2/rocketmq-all-4.9.2-bin-release.zip
安装解压工具
yum install -y unzip zip
解压
unzip rocketmq-all-4.9.2-bin-release.zip -d /opt/
进入文件夹
cd /opt/rocketmq-4.9.2
三、配置环境变量
将rocketmq服务加入环境变量
vim /etc/profile
export PATH=$PATH:/opt/rocketmq-4.9.2/bin
# 使配置文件生效
source /etc/profile
四、按需修改启动内存
vim runserver.sh
vim runbroker.sh
vim tools.sh
五、创建目录
创建日志目录
mkdir -p /opt/rocketmq-4.9.2/logs
六、启动NameServer
cd /opt/rocketmq-4.9.2/bin
nohup sh mqnamesrv > /opt/rocketmq-4.9.2/logs/mqnamesrv.log 2>&1 &
验证是否启动OK:
tail -f /opt/rocketmq-4.9.2/logs/mqnamesrv.log
# 输出
nohup: ignoring input
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.
Java HotSpot(TM) 64-Bit Server VM warning: MaxNewSize (262144k) is equal to or greater than the entire heap (262144k). A new max generation size of 262080k will be used.
The Name Server boot success. serializeType=JSON
如果成功启动,能看到类似如下的日志
The Name Server boot success. …
七、启动Broker
/opt/rocketmq-4.9.2/bin
nohup sh mqbroker -n 127.0.0.1:9876 > /opt/rocketmq-4.9.2/logs/mqbroker.log 2>&1 &
验证是否启动OK
tail -f /opt/rocketmq-4.9.2/logs/mqbroker.log
# 输出
nohup: ignoring input
The broker[ecs-65685, 192.168.0.98:10911] boot success. serializeType=JSON and name server is 127.0.0.1:9876
如果启动成功,能看到类似如下的日志:
The broker[itmuchcomdeMacBook-Pro.local, 192.168.43.197:10911] boot success. serializeType=JSON and name server is localhost:9876
八、测试
在发送/接收消息之前,需要告诉客户名称服务器的位置。
RocketMQ 提供了多种方法来实现这一点。为了简单起见,使用环境变量NAMESRV_ADDR
# 开启两个端口,都执行一下命令
export NAMESRV_ADDR=localhost:9876
发送消息
# Producer 端口一执行
sh /opt/rocketmq-4.9.2/bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
接收消息
# Consumer 端口二执行
sh /opt/rocketmq-4.9.2/bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
九、安装RocketMQ控制台
1 编译源码方式
前置环境
-
64bit OS, Linux/Unix/Mac is recommended
-
64bit JDK 1.8+
-
Maven 3.2.x
2 下载源码
https://github.com/apache/rocketmq-dashboard
git clone https://github.com/apache/rocketmq-dashboard.git
3 在启动之前先修改下端口,默认的8080 已占用,一定要先修改端口,在进行编译。
vim src/main/resources/application.yml
4 Maven spring-boot 方式启动
mvn spring-boot:run
5 或者 使用Maven先build成jar包,再java -jar方式启动
mvn clean package -Dmaven.test.skip=true
java -jar target/rocketmq-dashboard-1.0.1-SNAPSHOT.jar
访问控制台:http://IP:8082
十、防火墙开启端口
# 关闭防火墙
systemctl stop firewalld
# 开通端口
firewall-cmd --zone=public --add-port=8082/tcp --permanent
firewall-cmd --zone=public --add-port=9876/tcp --permanent
firewall-cmd --zone=public --add-port=10911/tcp --permanent
# 配置立即生效
firewall-cmd --reload
# 重启防火墙生效
systemctl restart firewalld
云主机需配置安全组
在入方向规则,都允许放行
-
8082:RocketMQ 控制台
-
9876:nameserver 中的端口
-
10911:broker 的端口