问题
由于甲方预算有限,需要手动在linux上面安装RocketMQ单机版,(嗯,单机版,你没听错)
步骤
添加用户和用户组
bash
sudo useradd --system --home /usr/local/rocketmq --shell /sbin/nologin --comment "rocketmq user" --user-group rocketmq
手动安装RocketMQ二进制包
bash
# 下载二进制安装包
wget https://dist.apache.org/repos/dist/release/rocketmq/5.2.0/rocketmq-all-5.2.0-bin-release.zip
# 解压到/usr/local/ 目录下面
sudo unzip -d /usr/local/ rocketmq-all-5.2.0-bin-release.zip
# 修改解压文件夹名称为rocketmq
sudo mv /usr/local/rocketmq-all-5.2.0-bin-release/ /usr/local/rocketmq/
# 修改安装目录文件夹与文件权限
# 授权文件夹拥有者为rocketmq用户
sudo chown -R rocketmq /usr/local/rocketmq
# 授权文件夹用户组为rocketmq
sudo chgrp -R rocketmq /usr/local/rocketmq
SysV 配置文件
新建nameserver配置文件:
bash
sudo vim /usr/lib/systemd/system/rocketmq.service
内容:
bash
[Unit]
Description=RocketMQ 5.2.0 - nameserver
After=network.target
[Service]
User=rocketmq
Group=rocketmq
Type=simple
ExecStart=/usr/local/rocketmq/bin/mqnamesrv
ExecStop=/usr/local/rocketmq/bin/mqshutdown namesrv
[Install]
WantedBy=multi-user.target
新建Broker+Proxy配置文件:
bash
sudo vim /usr/lib/systemd/system/mqbroker.service
内容:
bash
[Unit]
Description=RocketMQ 5.2.0 - Broker+Proxy
After=network.target
[Service]
User=rocketmq
Group=rocketmq
Type=simple
ExecStart=/usr/local/rocketmq/bin/mqbroker -n localhost:9876 --enable-proxy
ExecStop=/usr/local/rocketmq/bin/mqshutdown broker
[Install]
WantedBy=multi-user.target
重载SysV配置:
bash
sudo systemctl daemon-reload
安装Java
bash
sudo dnf install java-17-amazon-corretto
启动nameserver服务
bash
sudo systemctl start rocketmq.service
查看启动状态:
bash
sudo systemctl status rocketmq.service
启动状态如下:
bash
● rocketmq.service - RocketMQ 5.2.0 - nameserver
Loaded: loaded (/usr/lib/systemd/system/rocketmq.service; disabled; preset: disabled)
Active: active (running) since Fri 2024-03-29 10:10:58 UTC; 3s ago
Main PID: 81442 (mqnamesrv)
Tasks: 39 (limit: 18641)
Memory: 180.7M
CPU: 4.906s
CGroup: /system.slice/rocketmq.service
├─81442 /bin/sh /usr/local/rocketmq/bin/mqnamesrv
├─81446 sh /usr/local/rocketmq/bin/runserver.sh -Drmq.logback.configurationFile=/usr/local/rocketmq/conf/rmq.namesrv.logback.xml org.apache.rocketmq.namesrv.NamesrvStartup
└─81475 /bin/java -server -Xms4g -Xmx4g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -XX:SoftRef>
Mar 29 10:10:58 ip-172-34-131-187.ec2.internal systemd[1]: Started rocketmq.service - RocketMQ 5.2.0 - nameserver.
Mar 29 10:10:58 ip-172-34-131-187.ec2.internal mqnamesrv[81451]: which: no javac in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
Mar 29 10:10:58 ip-172-34-131-187.ec2.internal mqnamesrv[81450]: readlink: missing operand
Mar 29 10:10:58 ip-172-34-131-187.ec2.internal mqnamesrv[81450]: Try 'readlink --help' for more information.
Mar 29 10:10:58 ip-172-34-131-187.ec2.internal mqnamesrv[81449]: dirname: missing operand
Mar 29 10:10:58 ip-172-34-131-187.ec2.internal mqnamesrv[81449]: Try 'dirname --help' for more information.
Mar 29 10:10:58 ip-172-34-131-187.ec2.internal mqnamesrv[81448]: dirname: missing operand
Mar 29 10:10:58 ip-172-34-131-187.ec2.internal mqnamesrv[81448]: Try 'dirname --help' for more information.
Mar 29 10:11:00 ip-172-34-131-187.ec2.internal mqnamesrv[81475]: The Name Server boot success. serializeType=JSON, address 0.0.0.0:9876
启动Broker+Proxy服务
bash
sudo systemctl start mqbroker.service
总结
生产环境千万别这样玩,这是个单机版。主要是演示SysV的配置。