说明:rocketmq需要jdk环境。
(1)下载jdk安装包
https://www.oracle.com/technetwork/java/javase/archive-139210.html 下载jdk,这边选择的是jdk-8u144-linux-x64.tar.gz
(2)下载rocketmq安装包
http://rocketmq.apache.org/dowloading/releases/ 下载RocketMQ,这边选择的版本是rocketmq-all-4.7.0-bin-release.zip
(1)上传安装包到服务器
(2)解压并拷贝到安装目录
tar -zxvf jdk-8u144-linux-x64.tar.gz -C /usr/local/
ln -s /usr/local/jdk1.8.0_144 /usr/local/jdk
sed -i.ori '$a export JAVA_HOME=/usr/local/jdk\nexport PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH\nexport CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar' /etc/profile
source /etc/profile
#出现下面结果证明部署成功
[root@localhost opt]# java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
unzip /opt/rocketmq-all-4.7.0-bin-release.zip
mv rocketmq-all-4.7.0-bin-release /usr/local/rocketmq
(1)解压重命名
unzip rocketmq-all-4.7.0-bin-release.zip
mv rocketmq-all-4.7.0-bin-release /usr/local/rocketmq
(2)修改配置文件
cd /usr/local/rocketmq/conf/
# 先把broker.conf备份下
cp broker.conf broker.conf_20190821_bak
修改broker.conf 配置
vim broker.conf
brokerClusterName = test1
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER #当前节点为master,即单主
flushDiskType = ASYNC_FLUSH
autoCreateTopicEnable = true
brokerIP1=192.168.126.135
namesrvAddr=192.168.126.135:9876
defaultTopicQueueNums=4
autoCreateSubscriptionGroup=true
listenPort=10911
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
storePathRootDir=/usr/local/rocketmq/store
storePathCommitLog=/usr/local/rocketmq/store/commitlog
storePathConsumeQueue=/usr/local/rocketmq/store/consumequeue
storePathIndex=/usr/local/rocketmq/store/index
storeCheckpoint=/usr/local/rocketmq/store/checkpoint
abortFile=/usr/local/rocketmq/store/abort
maxMessageSize=65536
(3)修改RocketMQ的name server运行端口
# 修改端口很简单,在conf目录下新建一个nameser.properties文件,然后写入一行配置即可。
vim nameser.properties
listenPort=9876
默认为9876端口。
(4)创建日志和存储文件等的存放目录
mkdir -p /usr/local/rocketmq/store
mkdir -p /usr/local/rocketmq/store/commitlog
mkdir -p /usr/local/rocketmq/logs
(5)修改nameServer的启动文件
由于默认的NameServer的启动文件的JVM内存给的比较大,由于这里是测试环境,所以这边需要改小点。如果是线上的话,就根据实际情况来
vim /usr/local/rocketmq/bin/runserver.sh
修改内容如下:
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
(6)修改broker的启动文件
和上面一样,broker的启动文件的JVM参数也需要调整下。
vim /usr/local/rocketmq/bin/runbroker.sh
修改内容如下:
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m"
(1)启动 name server
nohup sh /usr/local/rocketmq/bin/mqnamesrv -c /usr/local/rocketmq/conf/nameser.properties >> /usr/local/rocketmq/logs/mqnamesrv_stdout.log 2>&1 &
(2)启动broker
nohup sh /usr/local/rocketmq/bin/mqbroker -c /usr/local/rocketmq/conf/broker.conf >> /usr/local/rocketmq/logs/broker_stdout.log 2>&1 &
(3)使用 jps 命令查看进程
(1)关闭namesrv服务:
sh bin/mqshutdown namesrv
(2)关闭broker服务 :
sh bin/mqshutdown broker
RocketMQ中提供多种配置文件,分别有 broker.conf 、2m-2s-async、2m-2s-sync、2m-noslave四种。
(2)配置介绍
在安装包conf 目录下有官方自带配置文件模板从上自下以此是:两主两从异步;两主两从同步;两主。
该配置文件可用于配置单机版 RocketMQ,用该配置文件启动的RocketMQ是 master服务。
该文件夹下有四个配置文件,用于配置异步的双主双从服务。具体实现是:服务器1配置 broker-a.properties(master) ,服务器2配置 broker-a-s.properties(slave),服务器3配置 broker-b.properties(master),服务器4配置 broker-b-s.properties(slave)。各服务从配置的broker