Apache RocketMQ

查看主机名

cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain

cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

 

这两个地方的主机名保持一样


wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz

tar xf apache-maven-3.5.0-bin.tar.gz -C /usr/local/

vim /etc/profile

export PATH=/usr/local/apache-maven-3.5.0/bin:$PATH

source /etc/profile

 

=============================================================================================================


Apache RocketMQ


git clone -b develop https://github.com/apache/incubator-rocketmq.git

cd incubator-rocketmq

mvn -Prelease-all -DskipTests clean install -U

修改日志目录:

cd /usr/local/incubator-rocketmq/distribution/target/apache-rocketmq/conf

vim logback_namesrv.xml

vim logback_broker.xml

修改文件里所有:

<file>${user.hose}/log/rocketmqlog/namesrv_default.log</file>
<append>true</append>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${user.home}/log/rocketmqlog/otherdays/namesrv_default.%i.log

修改成:

<file>/var/log/rocketmqlog/namesrv_default.log</file>
<append>true</append>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>/var/log/rocketmqlog/otherdays/namesrv_default.%i.log


查看内存:

free -m

total used free shared buffers cached
Mem: 1861 1789 71 0 1 24
-/+ buffers/cache: 1763 98
Swap: 1983 751 1232


指定内存和java家目录

env|grep JAVA #查看JAVA的家目录

JAVA_HOME=/usr/local/jdk

vim /root/incubator-rocketmq/distribution/target/apache-rocketmq/bin/runserver.sh

[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/java

[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java

修改成:

[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/jre

[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/local/jdk


把:
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g -XX:PermSize=128m -XX:MaxPermSize=320m"

修改成:

JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:PermSize=128m -XX:MaxPermSize=320m"

 

 


vim /root/incubator-rocketmq/distribution/target/apache-rocketmq/bin/runbroker.sh

[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/java

[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java

修改成:

[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/jre

[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/local/jdk


把:
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g -XX:PermSize=128m -XX:MaxPermSize=320m"

修改成:
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:PermSize=128m -XX:MaxPermSize=320m"

 

 

 


vim /root/incubator-rocketmq/distribution/target/apache-rocketmq/conf/broker.conf

末尾添加:

namesrvAddr = mycat:9876
autoCreateTopicEnable = true
autoCreateSubscriptionGroup = true

 


启服务:

nohup sh bin/mqnamesrv &

nohup sh bin/mqbroker -n localhost:9876 &


停止服务:

Rocket.sh

#!/bin/bash
DIR=/usr/local/
RUNDIR=/usr/local/incubator-rocketmq
RQDIR=/usr/local/incubator-rocketmq/distribution/target/apache-rocketmq/

yum install wget git -y

wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz

/bin/tar xf apache-maven-3.5.0-bin.tar.gz -C /usr/local/

echo "export PATH=/usr/local/apache-maven-3.5.0/bin:\$PATH" >> /etc/profile

source /etc/profile

cd /usr/local/

git clone -b develop https://github.com/apache/incubator-rocketmq.git

cd /usr/local/incubator-rocketmq

mvn -Prelease-all -DskipTests clean install -U

cd /usr/local/incubator-rocketmq/distribution/target/apache-rocketmq/

sed -i '27c\[ ! -e "\$JAVA_HOME\/bin\/java" ] \&& JAVA_HOME=\$HOME\/jdk\/jre/' bin/runserver.sh

sed -i '28c\[ ! -e "\$JAVA_HOME\/bin\/java" ] \&& JAVA_HOME=\/usr\/local\/jdk' bin/runserver.sh

sed -i '27c\[ ! -e "\$JAVA_HOME\/bin\/java" ] \&& JAVA_HOME=\$HOME\/jdk\/jre/' bin/runbroker.sh

sed -i '28c\[ ! -e "\$JAVA_HOME\/bin\/java" ] \&& JAVA_HOME=\/usr\/local\/jdk' bin/runbroker.sh

#sed "s#/usr/java#/usr/local/java#g" runserver.sh

#sed "s#/jdk/java#/jdk/jre#g" runserver.sh
sed -i 's/8g/2g/g' bin/runbroker.sh
#sed -n 's/8g/2g/g' bin/runserver.sh
sed -i 's/4g/1g/g' bin/runbroker.sh
#sed -n 's/4g/1g/g' bin/runserver.sh
sed -i 's/2g/1g/g' bin/runserver.sh
#sed -n 's/8g/2g/g' bin/runbroker.sh
sed -i 's/4g/2g/g' bin/runserver.sh
#sed -n 's/4g/1g/g' bin/runbroker.sh

echo "namesrvAddr = mycat:9876
autoCreateTopicEnable = true
autoCreateSubscriptionGroup = true" >> conf/broker.conf
sed -i 's/\${user.home}/\/var/g' conf/logback_broker.xml
#sed -i 's#${user.home}#/var#'conf/logback_namesrv.xml
sed -i 's/\${user.home}/\/var/g' conf/logback_namesrv.xml
#sed -i 's#${user.home}#/var#'conf/logback_broker.xml
nohup sh bin/mqnamesrv &
sleep 2
nohup sh bin/mqbroker -n localhost:9876 &

 

 

===========================================================================================

 

 

rocketmq-cluster: 双master的模式

https://github.com/alibaba/RocketMQ/releases/download/v3.2.6/alibaba-rocketmq-3.2.6.tar.gz

1.解析域名:

每台服务器都进行解析:

cat /etc/hosts

192.168.1.24 rocketmq-nameserver-1
192.168.1.24 rocketmq-master-1
192.168.1.218 rocketmq-nameserver-2
192.168.1.218 rocketmq-master-2

wget https://github.com/alibaba/RocketMQ/releases/download/v3.2.6/alibaba-rocketmq-3.2.6.tar.gz

tar xf alibaba-rocketmq-3.2.6.tar.gz -C /usr/local/

mv /usr/local/{alibaba-rocketmq,rocketmq}

cd /usr/local/rocketmq

cat /etc/profile

export ROCKETMQ_HOME=/usr/local/rocketmq

export PATH=$PATH::$ROCKETMQ_HOME/bin

创建储存路径:

mkdir -p /usr/local/rocketmq/store/{commitlog,consumequeue,index,abort,checkpoint}

配置文件:

配置文件:

cd /usr/lcoal/rocketmq/conf/2m-noslave/

cat broker-a.properties #master1的配置文件

cat broker-b.properties #master2的配置文件

#所属集群的名称

brokerClusterName=DefaultCluster

#broker名称,不同的配置文件填写的不一样

brokerName=broker-a

#0,表示Master,>0,表示Slave
brokerId=0

#删除文件时间点,默认是凌晨4点

deleteWhen=04

#文件保留时间,默认是48小时

fileReservedTime=48

brokerRole=ASYNC_MASTER

flushDiskType=ASYNC_FLUSH

#nameServer地址,分好分割

namesrvAddr=rocketmq-nameserver-1:9876;rocketmq-nameserver-2:9876

#在发送消息时,自动创建服务器不存在的topic,默认创建的对列数

defaultTopicQueueNums=4

#是否允许Broker自动创建topic,建议线下开启,线上关闭

autoCreateTopicEnable=true


#是否允许Broker自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true

#Broker,对外服务的监听端口

listenPort=10911

#CommitLog每个文件的大小默认是1G

mapedFileSizeCommitLog=1073741824

#ConsumeQueue每个文件默认存50W条,可根据业务调整

mapedFileSizeConsumeQueue=50000000

#destroyMapedFileIntervalForcibly=120000

#redeleteHangedFileInterval=120000

#检查物理文件的磁盘空间

diskMaxUsedSpaceRatio=88


#存储路径

storePathRootDir=/usr/local/rocketmq/store

#CommitLog存储路径

storePathCommitLog=/usr/local/rocketmq/store/commitlog

#消费队列存储路径

storePathConsumeQueue=/usr/local/rocketmq/store/consumequeue

#maxMessageSize=65536

#消息索引存储路径

storePathIndex=/usr/local/rocketmq/store/index

#point 文件存储路径

storeCheckpoint=/usr/local/rocketmq/store/checkpoint

#abort 文件存储路径

abortFile=/usr/local/rocketmq/abort

 

修改日志存放路径:

ll /usr/lcoal/rocketmq/conf/

-rw-r--r-- 1 52583 users 8010 Aug 30 17:08 logback_broker.xml

-rw-r--r-- 1 52583 users 2387 Aug 30 17:08 logback_filtersrv.xml

-rw-r--r-- 1 52583 users 2369 Aug 30 17:08 logback_namesrv.xml

-rw-r--r-- 1 52583 users 2435 Mar 28 2015 logback_tools.xml

sed命令修改日志的存放路径

sed -i 's#${user.home}#/usr/local/rocketmq#g' *.xml


修改启动脚本中的JVM参数:在生产环境中根据具体的内存进行修改Java的堆内存

vim /usr/local/rocketmq/bin/runserver.sh

vim /usr/lcoal/rocketmq/bin/runbroker.sh

JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m -XX:PermSize=128m -XX:MaxPermSize=320m"

启动服务:

cd /usr/local/rocketmq/bin/

nohup sh mqnamesrv &

master1:

nohup sh mqbroker -n rocketmq-nameserver-1:9876 -c /root/rocketmq/conf/2m-noslave/broker-a.properties > /dev/null 2>&1 & #-n指定master的ip和端口

master2:

nohup sh mqbroker -n rocketmq-nameserver-1:9876 -c /root/rocketmq/conf/2m-noslave/broker-a.properties > /dev/null 2>&1 & #-n指定master的ip和端口

cat /usr/local/rocketmq/logs/rocketmqlogs/broker.log

INFO main - The broker[broker-a, 192.168.1.24:10911] boot success. and name server is rocketmq-nameserver-1:9876;rocketmq-nameserver-2:9876

netstat -ntlp

tcp 0 0 :::9876 :::* LISTEN 1397/java

tcp 0 0 :::10911 :::* LISTEN 1428/java

tcp 0 0 :::10912 :::* LISTEN 1428/java


====================================================================================================

cd /usr/local/rocketmq/bin/

默认的配置项

sh mqbroker -m

显示所有配置项 :

sh mqbroker -p

启动服务:

nohup sh mqnamesrv &

nohup sh mqbroker -c /root/rocketmq/conf/2m-noslave/broker-a.properties > /dev/null 2>&1 &

关闭服务:

sh mqshutdown namesrv

sh mqshutdown broker

查看服务启动情况:

jps

2690 BrokerStartup
2663 NamesrvStartup
2967 Jps

===================================================================================================

实例:

创建topic

sh mqadmin updateTopic -n rocketmq-nameserver-1:9876 -c DefaultCluster -t TopicTest1

查看topic信息

sh mqadmin topicList -n rocketmq-nameserver-1:9876

查看topic统计信息

sh mqadmin topicStats -n rocketmq-nameserver-1:9876 -t TopicTest1

查看所有消费组Group

sh mqadmin consumerProgress -n rocketmq-nameserver-1:9876

查看指定消费组下的所有topic数据堆积情况

sh mqadmin consumerProgress -n rocketmq-nameserver-1:9876 -g ConsumerGroupName

删除topic

sh mqadmin deleteTopic -n rocketmq-nameserver-1:9876 -c DefaultCluster -t Topictest1

启动脚本

 

 

cat Rocket-start.sh

#!/bin/bash
RQDIR=/usr/local/incubator-rocketmq/distribution/target/apache-rocketmq

cd $RQDIR

nohup sh bin/mqnamesrv &
sleep 2
nohup sh bin/mqbroker -c $RQDIR/conf/broker.conf -n localhost:9876 &

 

posted @ 2018-04-22 15:26  迷路的大雁  阅读(342)  评论(0编辑  收藏  举报