概述:
RocketMQ作为一款纯java、分布式、队列模型的开源消息中间件,支持事务消息、顺序消息、批量消息、定时消息、消息回溯等。
环境准备:
OS:entOS Linux release 7.6.1810 (Core)
配置:8C 16G
操作步骤
- 配置环境变量(jdk1.8)
yum install java-1.8.0-openjdk
yum install java-1.8.0-openjdk-devel.x86_64
环境变量引用,在/etc/profile中输入以下内容
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64 JRE_HOME=$JAVA_HOME/jre CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin export JAVA_HOME JRE_HOME CLASS_PATH PATH source /etc/profile
检查环境变量是否正常
[root@localhost rocketmq]# java -version
openjdk version “1.8.0_242”
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
[root@localhost rocketmq]# javac -version
javac 1.8.0_242
下载rocketMQ组件
yum -y install wget wget http://mirrors.tuna.tsinghua.edu.cn/apache/rocketmq/4.6.0/rocketmq-all-4.6.0-bin-release.zip
解压文件至/home
unzip rocketmq-all-4.6.0-bin-release.zip -d /home/
得到一个名为rocketmq-all-4.6.0-bin-release的目录,目录下文件如下:
[root@localhost home]# tree rocketmq-all-4.6.0-bin-release
rocketmq-all-4.6.0-bin-release
├── benchmark
│ ├── consumer.sh
│ ├── producer.sh
│ ├── runclass.sh
│ └── tproducer.sh
├── bin
│ ├── cachedog.sh
│ ├── cleancache.sh
│ ├── cleancache.v1.sh
│ ├── dledger
│ │ └── fast-try.sh
│ ├── mqadmin
│ ├── mqadmin.cmd
│ ├── mqbroker
│ ├── mqbroker.cmd
│ ├── mqbroker.numanode0
│ ├── mqbroker.numanode1
│ ├── mqbroker.numanode2
│ ├── mqbroker.numanode3
│ ├── mqnamesrv
│ ├── mqnamesrv.cmd
│ ├── mqshutdown
│ ├── mqshutdown.cmd
│ ├── os.sh
│ ├── play.cmd
│ ├── play.sh
│ ├── README.md
│ ├── runbroker.cmd
│ ├── runbroker.sh
│ ├── runserver.cmd
│ ├── runserver.sh
│ ├── setcache.sh
│ ├── startfsrv.sh
│ ├── tools.cmd
│ └── tools.sh
├── conf
│ ├── 2m-2s-async
│ │ ├── broker-a.properties
│ │ ├── broker-a-s.properties
│ │ ├── broker-b.properties
│ │ └── broker-b-s.properties
│ ├── 2m-2s-sync
│ │ ├── broker-a.properties
│ │ ├── broker-a-s.properties
│ │ ├── broker-b.properties
│ │ └── broker-b-s.properties
│ ├── 2m-noslave
│ │ ├── broker-a.properties
│ │ ├── broker-b.properties
│ │ └── broker-trace.properties
│ ├── broker.conf
│ ├── dledger
│ │ ├── broker-n0.conf
│ │ ├── broker-n1.conf
│ │ └── broker-n2.conf
│ ├── logback_broker.xml
│ ├── logback_namesrv.xml
│ ├── logback_tools.xml
│ ├── plain_acl.yml
│ └── tools.yml
├── lib
│ ├── commons-beanutils-1.9.2.jar
│ ├── commons-cli-1.2.jar
│ ├── commons-codec-1.9.jar
│ ├── commons-collections-3.2.2.jar
│ ├── commons-digester-1.8.1.jar
│ ├── commons-lang3-3.4.jar
│ ├── commons-logging-1.2.jar
│ ├── commons-validator-1.6.jar
│ ├── dledger-0.1.jar
│ ├── fastjson-1.2.61.jar
│ ├── guava-19.0.jar
│ ├── javassist-3.20.0-GA.jar
│ ├── jcommander-1.72.jar
│ ├── jna-4.2.2.jar
│ ├── logback-classic-1.0.13.jar
│ ├── logback-core-1.0.13.jar
│ ├── netty-all-4.0.42.Final.jar
│ ├── netty-tcnative-boringssl-static-1.1.33.Fork26.jar
│ ├── openmessaging-api-0.3.1-alpha.jar
│ ├── rocketmq-acl-4.6.0.jar
│ ├── rocketmq-broker-4.6.0.jar
│ ├── rocketmq-client-4.6.0.jar
│ ├── rocketmq-common-4.6.0.jar
│ ├── rocketmq-example-4.6.0.jar
│ ├── rocketmq-filter-4.6.0.jar
│ ├── rocketmq-logging-4.6.0.jar
│ ├── rocketmq-namesrv-4.6.0.jar
│ ├── rocketmq-openmessaging-4.6.0.jar
│ ├── rocketmq-remoting-4.6.0.jar
│ ├── rocketmq-srvutil-4.6.0.jar
│ ├── rocketmq-store-4.6.0.jar
│ ├── rocketmq-tools-4.6.0.jar
│ ├── slf4j-api-1.7.7.jar
│ └── snakeyaml-1.19.jar
├── LICENSE
├── NOTICE
└── README.md
修改启动脚本(rockermq默认启动内存很大,需根据实际情况来修改)
vim runbroker.sh 可修改:JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"
vim runbroker.sh 可修改:JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"
配置rockermq环境参数
vim /etc/profile export ROCKETMQ_HOME=/home/rocketmq #实际路径 export NAMESRV_ADDR=localhost:9876 export PATH=$JAVA_HOME/bin:$ROCKETMQ_HOME/bin:$PATH source /etc/profile
修改日志存储路径
cd /home/rocketmq/conf #实际路径 sed -i 's#${user.home}#/home/rocketmq#g' *.xml #默认是存在用户目录下
启动
nohup mqnamesrv & nohup mqbroker -n IP:9876 & #IP是部署的本机IP
查看日志
[root@localhost rocketmqlogs]# cat namesrv.log |grep succ 2020-02-14 15:31:20 INFO main - The Name Server boot success. serializeType=JSON 正常
[root@localhost rocketmqlogs]# cat broker.log |grep succ 2020-02-14 15:31:32 INFO main - The broker[localhost.localdomain, 192.168.200.128:10911] boot success. serializeType=JSON and name server is 192.168.200.128:9876 正常
store存储方式$HOME\store\commitlog\${fileName}
因此如果用root起的话,默认是在/root下,如果想存在其他目录下,只需要切换个用户启动即可
useradd rocketmq chown -R rocketmq.rocketmq /home/rocketmq
此时在启动,就到其他用户的家目录里了
bash-4.2$ tree /home/rocketmq/store
/home/rocketmq/store
├── checkpoint
├── config
│ ├── consumerFilter.json
│ ├── consumerFilter.json.bak
│ ├── consumerOffset.json
│ ├── consumerOffset.json.bak
│ ├── delayOffset.json
│ ├── delayOffset.json.bak
│ └── topics.json
└── lock