服务安装(需Java基础环境)
集群主机
序号 | IP | 角色 | 架构模式 |
---|---|---|---|
1 | 192.168.3.73 | nameserver、brokerserver | Master1、Slave1 |
下载安装
下载最新安装包: http://rocketmq.apache.org/dowloading/releases/
下载并安装最新稳定版的RocketMQ.
[root@rockketmq ~]# cd /usr/local/src && wget https://dist.apache.org/repos/dist/release/rocketmq/5.1.0/rocketmq-all-5.1.0-bin-release.zip --no-check-certificate
[root@rockketmq local]# cd /usr/local/src && unzip rocketmq-all-5.1.0-bin-release.zip -d /usr/local/
[root@rockketmq local]# cd .. && mv rocketmq-all-5.1.0-bin-release/ rocketmq
修改JVM默认配置(物理机器内存为8G)
[root@localhost rocketmq]# vi bin/runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
JAVA_OPT="${JAVA_OPT} -server -Xms2g -Xmx2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
[root@localhost rocketmq]# vi bin/runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g"
JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=4g"
1.2.1、启动 NameServer
### 首先启动 Name Server
$ nohup sh mqnamesrv 2>&1 &
### 验证Name Server 是否启动成功
$ tail -f ~/logs/rocketmqlogs/namesrv.log
The Name Server boot success...
1.2.2、启动 Broker + Proxy
# 启动 Broker
$ nohup sh bin/mqbroker -n localhost:9876 --enable-proxy &
### 验证Broker 是否启动成功,例如Broker的IP为:192.168.1.2,且名称为broker-a
$ tail -f ~/logs/rocketmqlogs/broker_default.log
The broker[xxx, 192.169.1.2:10911] boot success...
问题描述:
RocketMQ默认的虚拟机内存较大,启动Broker如果因为内存不足失败,需要修改下面两个配置文件,修改JVM内存大小
# 编辑 runbroker.sh 和 runserver.sh 修改JVM大小 vi runbroker.sh vi runserver.sh
参考配置
#JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m" JAVA_OPT="${JAVA_OPT} -server -Xms256M -Xmx256M -Xmn128M -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
1.2.3、关机服务器
# 1、关闭 Broker
sh bin/mqshutdown broker
# 2、关闭 NameServer
sh bin/mqshutdown namesrv
3、开机自启动
创建专用的数据存储目录
$ mkdir -p /home/rocketmq/data/store
创建 rocketmq:rocketmq
用户组和用户,并进行授权:
$ groupadd rocketmq
$ useradd -g rocketmq -M -s /sbin/nologin rocketmq
$ chown -R rocketmq. /usr/local/rocketmq/
$ chown -R rocketmq. /home/rocketmq/data/
$ chown -R rocketmq. /home/rocketmq/logs/
Name Server 开机自启动
配置开机启动脚本:
[root@rocketmq ~]# vi /lib/systemd/system/rocketmq-namesrv.service
脚本内容:
[Unit]
Description=RocketMQ 5.x Name Server
After=network.target
[Service]
User=rocketmq
Environment='JAVA_HOME=/usr/local/java'
ExecStart=/usr/local/rocketmq/bin/mqnamesrv > /home/rocketmq/logs/namesrv.log 2>&1 &
ExecStop=/usr/local/rocketmq/bin/mqshutdown namesrv
ExecReload=/usr/local/rocketmq/bin/mqshutdown namesrv && /usr/local/rocketmq/bin/mqnamesrv > /home/rocketmq/logs/namesrv.log 2>&1 &
LimitNOFILE=65536
Restart=0
[Install]
WantedBy=multi-user.target
设置随机启动:
[root@rocketmq ~]# systemctl daemon-reload
[root@rocketmq ~]# systemctl disable rocketmq-namesrv.service
[root@rocketmq ~]# systemctl enable rocketmq-namesrv.service
[root@rocketmq ~]# systemctl start rocketmq-namesrv.service
[root@rocketmq ~]# systemctl status rocketmq-namesrv.service
[root@rocketmq ~]# systemctl stop rocketmq-namesrv.service
[root@rocketmq ~]# systemctl restart rocketmq-namesrv.service
Broker + Proxy 开机自启动
配置 broker.conf :
这里务必配置
storePathRootDir
相关参数,实际上启动运行时候没配置会提示错误无法配置开机自启动!
[root@rocketmq ~]# vi /usr/local/rocketmq/conf/broker.conf
broker.conf 内容:
#所属集群名称
brokerClusterName=DefaultCluster
#broker名字,同一组的master-slave中,broker名字相同
brokerName=broker-a
#brokerId的ID,0 表示Master,>0 表示Slave
brokerId=0
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=48
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_MASTER
#nameServer集群地址,如果是多个,使用分号;分割
namesrvAddr=127.0.0.1:9876
brokerIP1=192.168.3.73
#存储路径
storePathRootDir=/home/rocketmq/data/store
#commitLog 存储路径
storePathCommitLog=/home/rocketmq/data/store/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/home/rocketmq/data/store/consumequeue
#消息索引存储路径
storePathIndex=/home/rocketmq/data/store/index
#checkpoint 文件存储路径
storeCheckpoint=/home/rocketmq/data/store/checkpoint
#abort 文件存储路径
abortFile=/home/rocketmq/data/store/abort
配置开机启动脚本:
[root@rocketmq ~]# vi /lib/systemd/system/rocketmq-broker.service
脚本内容:
[Unit]
Description=RocketMQ 5.x Broker
After=network.target remote-fs.target nss-lookup.target rocketmq-namesrv.service
[Service]
User=rocketmq
Environment='JAVA_HOME=/usr/local/java'
Environment='ROCKETMQ_HOME=/usr/local/rocketmq'
ExecStart=/usr/local/rocketmq/bin/mqbroker autoCreateTopicEnable=true -c /usr/local/rocketmq/conf/broker.conf -n localhost:9876 --enable-proxy > /home/rocketmq/logs/broker.log 2>&1 &
ExecStop=/usr/local/rocketmq/bin/mqshutdown broker
ExecReload=/usr/local/rocketmq/bin/mqshutdown broker && /usr/local/rocketmq/bin/mqbroker autoCreateTopicEnable=true -c /usr/local/rocketmq/conf/broker.conf -n localhost:9876 --enable-proxy > /home/rocketmq/logs/broker.log 2>&1 &
LimitNOFILE=65536
Restart=0
[Install]
WantedBy=multi-user.target
设置随机启动:
[root@rocketmq ~]# systemctl daemon-reload
[root@rocketmq ~]# systemctl disable rocketmq-broker.service
[root@rocketmq ~]# systemctl enable rocketmq-broker.service
[root@rocketmq ~]# systemctl start rocketmq-broker.service
[root@rocketmq ~]# systemctl status rocketmq-broker.service
[root@rocketmq ~]# systemctl stop rocketmq-broker.service
[root@rocketmq ~]# systemctl restart rocketmq-broker.service
[root@rocketmq ~]# journalctl -xe
作者:Jeebiz 创建时间:2023-01-25 19:51
最后编辑:Jeebiz 更新时间:2024-11-01 10:05
最后编辑:Jeebiz 更新时间:2024-11-01 10:05