1.RocketMQ安装
1.1 下载 | RocketMQ (apache.org)
1.2 解压
先创建路径/usr/local/rocketmq
unzip rocketmq-all-5.3.0-bin-release.zip -d /usr/local/rocketmq
1.3环境变量配置
添加到环境变量
vim /etc/profile
export ROCKET_HOME=/usr/local/rocketmq
export PATH=$PATH:$ROCKET_HOME/bin
让环境变量生效
source /etc/profile
1.4创建日志文件夹
mkdir /usr/local/rocketmq/logs
1.5修改启动文件,设置参数
修改runserver.sh
vim /usr/local/rocketmq/bin/runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms128m -Xmx128m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m"
修改runbroker.sh
vim /usr/local/rocketmq/bin/runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms128m -Xmx128m"
JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=256m"
修改broker.conf
vim /usr/local/rocketmq/conf/broker.conf
添加如下
#允许自动创建topic
autoCreateTopicEnable=true
namesrvAddr=localhost:9876
1.6启动
启动Nameserver
nohup mqnamesrv >/usr/local/rocketmq/logs/mqnamesrv.log 2>&1 &
启动Broker
nohup mqbroker -n localhost:9876 >/usr/local/rocketmq/logs/broker.log 2>&1 &
或者
nohup sh mqbroker -c /usr/local/rocketmq/conf/broker.conf >/usr/local/rocketmq/logs/broker.log 2>&1 &
查看
ps -ef|grep mq
1.7 测试
先指定一下地址
export NAMESRV_ADDR=172.26.70.245:9876
发送消息
sh tools.sh org.apache.rocketmq.example.quickstart.Producer
接收消息
sh tools.sh org.apache.rocketmq.example.quickstart.Consumer
1.8关闭
sh mqshutdown namesrv
sh mqshutdown broker