【RocketMQ】安装教程
1. 下载地址
RocketMQ · 官方网站 | RocketMQ (apache.org)
按照下图所示下载
2. 解压
将下载好的压缩包,放置在/home/ziggszhao/app目录下,输入下面的命令解压压缩包
unzip rocketmq-all-4.9.4-bin-release.zip
3. 修改broker.conf配置文件
cd /home/ziggszhao/app/rocketmq/conf
vim broker.conf
修改后内容如下:
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# Broker 对外服务的监听端口
listenPort=10911
# 是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
# 是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
# nameServer地址,分号分割
namesrvAddr=localhost:19876
# 开启对SQL语法的支持(默认没有开启)
enablePropertyFilter=true
# 存储路径
storePathRootDir=/home/ziggszhao/app/rocketmq/store/broker-a
# commitLog 存储路径
storePathCommitLog=/home/ziggszhao/app/rocketmq/store/broker-a/commitlog
# 消费队列存储路径存储路径
storePathConsumeQueue=/home/ziggszhao/app/rocketmq/store/broker-a/consumequeue
# 消息索引存储路径
storePathIndex=/home/ziggszhao/app/rocketmq/store/broker-a/index
# checkpoint 文件存储路径
storeCheckpoint=/home/ziggszhao/app/rocketmq/store/broker-a/checkpoint
# abort 文件存储路径
abortFile=/home/ziggszhao/app/rocketmq/store/broker-a/abort
4. 修改 runserver.sh和runbroker.sh参数
################### NameServer ###################
# 1.修改runserver.sh,将jvm启动参数改小,原因是服务器小的话,启动不成功或服务器宕机.默认值是 4G大小
## JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
vim bin/runserver.sh
# 1.1.修改内容如下。
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
# 2.启动 mqnamesrv
nohup /opt/rocketmq/bin/mqnamesrv &
# 3.查看 NameServer启动日志(家目录下)
tail -f ~/logs/rocketmqlogs/namesrv.log
# 4.关闭 mqnamesrv
/opt/rocketmq/bin/mqshutdown namesrv
################### Broker ###################
# 1.修改runbroker.sh,把内存调小,默认是8G
## JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g"
vim bin/runbroker.sh
# 1.1.修改内容如下。
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g"
# 2.启动 broker
nohup sh /opt/rocketmq/bin/mqbroker -c /opt/rocketmq/conf/broker.conf &
# 3.查看 Broker 启动日志
tail -f ~/logs/rocketmqlogs/broker.log
# 4.关闭 broker
/opt/rocketmq/bin/mqshutdown broker
5. 修改启动端口
5.1 修改nameserver端口启动
有时候不想使用默认的9876端口,就需要修改为想要的。在conf目录下,添加namesrv.conf文件,添上如下一行
listenPort=9092
启动namesrv:需要指定配置文件启动
执行:
./mqnamesrv -c ../conf/namesrv.conf
5.2 修改broker端口
在conf目录下broker.conf文件,添上如下几行
# Broker 对外服务的监听端口
listenPort=10911
# nameServer地址,分号分割
namesrvAddr=localhost:9876
启动broker:需要指定配置文件启动
执行:
./mqbroker -c ../conf/broker.conf
6. RocketMQ图形化管理控制台
下载RocketMq-Dashboard源码
Git地址:https://github.com/apache/rocketmq-dashboard
修改项目启动端口
修改namesrv地址
在解压目录 cmd执行
mvn clean package '-Dmaven.test.skip=true'
如果报下面的错误
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.11.3:install-node-and-yarn (install node and yarn) on project rocketmq-dashboard: Could not download Yarn: Could not download <https://github.com/yarnpkg/yarn/releases/download/v1.22.10/yarn-v1.22.10.tar.gz:> Connect to github.com:443 [github.com/20.205.243.166] failed: Connection timed out: connect -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] <http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException>
在浏览器/下载器上,访问https://github.com/yarnpkg/yarn/releases/download/v1.22.10/yarn-v1.22.10.tar.gz,手动下载, 然后去掉前面的v,放到maven仓库目录下repository\com\github\eirslett\yarn\1.22.10
如果报这个错误
Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.11.3:yarn (yarn install) on project rocketmq-dashboard: Failed to run task: ‘yarn install’ failed. org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
把pom.xml中的frontend-maven-plugin和maven-antrun-plugin注释掉,就是下面这个样子
然后先进入frontend目录,yarn install一下项目
如果报下面的错误
主要原因是powershell的执行策略阻止了此次操作,解决方案如下: 当前目录下运行命令,获取当前执行策略:
get-ExecutionPolicy
显示Restricted则表示受限。
解决方案:
当前项目节点下输入此命令符:
set-ExecutionPolicy -Scope CurrentUser
再输入RemoteSigned
进行查看是否有更改成RemoteSigned就可以啦
再输入:get-ExecutionPolicy
再启动 yarn install就可以啦!!
yarn install后,就可以输入打包了
7. systemd开机启动脚本
mqnamesrv.service
[Unit]
Description=mqnamesrv
After = network.target
[Service]
Type = simple
#定义启动进程时执行的命令。/bin/bash必须有,不然会报错
ExecStart=/home/ziggszhao/app/rocketmq/bin/mqnamesrv -c /home/ziggszhao/app/rocketmq/conf/namesrv.conf &
#定义关闭进程时执行的命令。
ExecStop=/home/ziggszhao/app/rocketmq/bin/mqshutdown namesrv
#是否分配独立空间
PrivateTmp=true
[Install]
WantedBy = multi-user.target
mqbroker.service
[Unit]
Description=mqbroker
After = network.target
[Service]
Type = simple
#定义启动进程时执行的命令。/bin/bash必须有,不然会报错
ExecStart=/home/ziggszhao/app/rocketmq/bin/mqbroker -c /home/ziggszhao/app/rocketmq/conf/broker.conf &
#定义关闭进程时执行的命令。
ExecStop=/home/ziggszhao/app/rocketmq/bin/mqshutdown broker
#是否分配独立空间
PrivateTmp=true
[Install]
WantedBy = multi-user.target
rocketmqdashboard.service
[Unit]
Description=rocketmqdashboard
After = network.target
[Service]
Type = simple
#定义启动进程时执行的命令。/bin/bash必须有,不然会报错
ExecStart=/usr/bin/java -jar /home/ziggszhao/app/rocketmq/bin/rocketmq-dashboard-1.0.1-SNAPSHOT.jar
#定义关闭进程时执行的命令。
ExecStop=/usr/bin/kill -15 $MAINPID
PrivateTmp=true
Restart=always
WorkingDirectory=/home/ziggszhao/app/rocketmq/bin
#是否分配独立空间
PrivateTmp=true
[Install]
WantedBy = multi-user.target