一、RocketMQ安装环境
64bit linux 64bit jdk1.8+ maven 3.2.x git(不一定需要)
本文安装环境为centos7.2、jdk1.8.0_144、maven-3.5.3,软件默认存放目录为/usr/local
1、安装jdk1.8
如果是采用centos7+,它默认已经安装jdk1.8了,这个步骤可以忽略
1.1 解压jdk包
tar xvf jdk-8u144-linux-x64.gz
1.2 设置环境变量
cd /etc vim profile export JAVAHOME=/usr/local/jdk1.8.0144 export JREHOME=/usr/local/jdk1.8.0144/jre export PATH=$PATH:/usr/local/jdk1.8.0144/bin export CLASSPATH=./:/usr/local/jdk1.8.0144/lib:/usr/local/jdk1.8.0_144/jre/lib 按esc,输入:wq保存并退出,并执行source /etc/profile使之生效 执行 java -version 按jdk是否安装成功
2、安装maven
2.1 解压maven包
tar zxf apache-maven-3.5.3-bin.tar.gz
2.2 设置环境变量
ln -s apache-maven-3.5.3/ maven echo 'export MAVENHOME=/usr/local/maven' >> /etc/profile echo 'export PATH=${PATH}:${MAVENHOME}/bin' >>/etc/profile source /etc/profile 执行mvn -version看maven是否安装成功
3、下载RocketMQ源码包
有三种方式可以下载到源码包 a、从apache rockemq官网下载
b、通过git拉取源码包 cd /usr/local git clone https://github.com/apache/rocketmq.git
c、从RocketMq的github上下载release版本 进入https://github.com/apache/rocketmq/releases,点击"releases",下载源码包
1.1 解压RocketMQ源码包
tar zxf rocketmq-rocketmq-all-4.2.0.tar.gz
1.2 编译RocketMQ源码
cd /usr/local/rocketmq-rocketmq-all-4.2.0 mvn -Prelease-all -DskipTests clean install -U 这个步骤比较耗时
1.3 创建软链接
ln -s /usr/local/rocketmq-rocketmq-all-4.2.0/distribution/target/apache-rocketmq /usr/local/rocketmq
1.4 设置环境变量
这个步骤非必须
echo 'export rocketmq=/usr/local/rocketmq' >> /etc/profile echo 'export PATH=$PATH:$rocketmq/bin' >>/etc/profile source /etc/profile
1.4 配置可执行权限
cd /usr/local/rocketmq/bin chmod +x mqadmin mqbroker mqfiltersrv mqshutdown mqnamesrv
1.5 修改日志配置文件
单机版这个步骤可以忽略,启动后,默认在root下会产生logs文件夹以及相应日志文件,但我们可以通过这个步骤设置日志存放位置
cd /usr/local/rocketmq mkdir logs cd /usr/local/rocketmq/conf && sed -i 's#${user.home}#/usr/local/rocketmq#g' *.xml
1.6 创建存储路径
单机版这个步骤可以忽略,rocketmq默认会在root产生store文件夹以及相关文件,但我们可以通过这个创建存储路径,并在broker.conf指定存储路径信息,来指定存储位置
mkdir /usr/local/rocketmq/store mkdir /usr/local/rocketmq/store/commitlog mkdir /usr/local/rocketmq/store/consumequeue mkdir /usr/local/rocketmq/store/index
1.7 修改broker.conf文件
echo 'namesrvAddr=localhost:9876' >> /usr/local/rocketmq/conf/broker.conf echo 'autoCreateTopicEnable=true' >> /usr/local/rocketmq/conf/broker.conf echo 'storePathRootDir=/usr/local/rocketmq/store' >> /usr/local/rocketmq/conf/broker.conf echo 'storePathCommitLog=/usr/local/rocketmq/store/commitlog' >> /usr/local/rocketmq/conf/broker.conf echo 'storePathConsumeQueue=/usr/local/rocketmq/store/consumequeue' >> /usr/local/rocketmq/conf/broker.conf echo 'storePathIndex=/usr/local/rocketmq/store/index' >> /usr/local/rocketmq/conf/broker.conf
1.8 修改启动脚本的内存参数
RocketMQ默认是4g内存启动,我们可根据实际情况进行相应配置
vim /usr/local/rocketmq/bin/runbroker.sh JAVAOPT="${JAVAOPT} -server -Xms1g -Xmx1g -Xmn512m -XX:PermSize=128m -XX:MaxPermSize=320m"
vim /usr/local/rocketmq/bin/runserver.sh JAVAOPT="${JAVAOPT} -server -Xms1g -Xmx1g -Xmn512m -XX:PermSize=128m -XX:MaxPermSize=320m"
1.9 关闭防火墙或者对外开放RocketMQ TCP端口
这个步骤是为了让远程能够访问到rocketmq
关闭防火墙的命令
systemctl stop firewalld.service
查看防火墙状态
firewall-cmd --state
开放RocketMQ TCP端口 firewall-cmd --zone=public --add-port=9876/tcp --permanent firewall-cmd --zone=public --add-port=10911/tcp --permanent firewall-cmd --reload
1.启动Name Server
nohup sh /usr/local/rocketmq/bin/mqnamesrv >/dev/null 2>&1 &
2.查看Name Server日志
tail -f -n 500 /usr/local/rocketmq/logs/rocketmqlogs/namesrv.log
3.启动broker
nohup sh /usr/local/rocketmq/bin/mqbroker -c /usr/local/rocketmq/conf/broker.conf >/dev/null 2>&1 &
4.查看broker日志
tail -f -n 500 /usr/local/rocketmq/logs/rocketmqlogs/broker.log
使用默认的测试例子 export NAMESRV_ADDR=localhost:9876 sh /usr/local/rocketmq/bin/tools.sh org.apache.rocketmq.example.quickstart.Producer sh /usr/local/rocketmq/bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
1.关闭broker
sh /usr/local/rocketmq/bin/mqshutdown broker
2.关闭Name Server
sh /usr/local/rocketmq/bin/mqshutdown namesrv
详情点击https://github.com/lyb-geek/first-rocketmq进行下载查看