1、64bit OS, Linux/Unix/Mac is recommended;
2、64bit JDK 1.8+;
3、Maven 3.2.x
4、Git
JDK每台机器都需要安装,maven和git只需要一台安装即可,编译好rocketmq之后使用scp命令拷贝到其他机器。
1、安装64位jdk配置环境变量
JAVA_HOME=/usr/local/jdk1.8.0_111
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH JAVA_HOME CLASSPATH
2、安装git(可以不安装,安装只是为了下载源码)
yum install git
3、使用git下载rocktmq源码,使用maven编译
git clone -b develop https://github.com/apache/incubator-rocketmq.git
cd incubator-rocketmq
mvn -Prelease-all -DskipTests clean install -U
cd distribution/target/
mv apache-rocketmq /data/comm_apps/
4、安装maven配置环境变量
MAVEN_HOME=/data/comm_apps/maven
PATH=$MAVEN_HOME/bin:$PATH
export MAVEN_HOME PATH
5、配置jvm参数
cd /data/comm_apps/apache-rocketmq/bin
vim runserver.sh
vim runbroker.sh
默认内存太大。根据需要修改
6、配置rocketMQ的环境变量
vim /etc/profile
追加以下内容
NAMESRV_ADDR=192.168.102.32:9876,192.168.102.33:9876,192.168.102.34:9876,192.168.102.35:9876
export NAMESRV_ADDR
ROCKETMQ_HOME=/data/comm_apps/apache-rocketmq
PATH=$ROCKETMQ_HOME/bin:$PATH
export ROCKETMQ_HOME PATH
使该配置文件生效:
source /etc/profile
7、每台依次启动namesrv
cd /data/comm_apps/apache-rocketmq/bin
nohup sh mqnamesrv &
可以使用jps查看启动结果
8、启动broker
安装的集群是2m-2s-async模式
192.168.102.32(broker-a)
192.168.102.34(broker-a-s)
192.168.102.33(broker-b)
192.168.102.35(broker-b-s)
(1) 修改配置文件
通过配置文件指定机器的集群和broker归属,比如brokerName一样的属于同一个broker,一个broker只能有一个master,可以有多个slave,brokerId为0的为master,其他的为slave。
对应的配置文件加一行参数如下:
namesrvAddr=192.168.102.32:9876;192.168.102.33:9876;192.168.102.34:9876;192.168.102.35:9876
(2)启动命令如下:
192.168.102.32的bin目录下执行:
nohup sh mqbroker -c /data/comm_apps/apache-rocketmq/conf/2m-2s-async/broker-a.properties >~/logs/rocketmqlogs/broker.log &
192.168.102.34的bin目录下执行:
nohup sh mqbroker -c /data/comm_apps/apache-rocketmq/conf/2m-2s-async/broker-a-s.properties >~/logs/rocketmqlogs/broker.log &
192.168.102.33的bin目录下执行:
nohup sh mqbroker -c /data/comm_apps/apache-rocketmq/conf/2m-2s-async/broker-b.properties >~/logs/rocketmqlogs/broker.log &
192.168.102.35的bin目录下执行:
nohup sh mqbroker -c /data/comm_apps/apache-rocketmq/conf/2m-2s-async/broker-b-s.properties >~/logs/rocketmqlogs/broker.log &
9. 查看集群是否安装成功
在每台broker机器上选择对应的配置文件启动master,slave,全部启动完成之后,可以在rocketmq的bin目录下查看集群情况:
sh mqadmin clusterList -n "192.168.102.32:9876;192.168.102.33:9876;192.168.102.34:9876;192.168.102.35:9876"