This document is installed with the ROCKETMQ Current the latest version of Rocketmq v4.0.0, when Ali had ROCKETMQ donated to the Apache organizations, why specifically point this out because there are separate places in the download, install, and service scripts. This is my first blog, if the typesetting is not very clear, please refer to the comments in order to correct their own writing habits.
First, installation ROCKETMQ
1 , installation Requirements
64bit OS, Linux/unix/mac is recommended; 64bit JDK 1.7+; Maven 3.2.x;git
2 , cloning, and compiling
> git clone -b develop https://github.com/ apache/incubator-rocketmq.git will generate the "INCUBATOR-ROCKETMQ" directory under the current directory, and the next part of the operation is in this directory > CD incubator-rocketmq> mvn -prelease-all -dskiptests clean install -u This step time will be longer, please wait patiently, execution success will generate multiple directories. This is the compilation process, we only need to follow the compilation process generated in the DISTRIBUTION/TARGET/APACHE-ROCKETMQ directory, usually for convenience, we have to copy the directory. > CD DISTRIBUTION/TARGET/APACHE-ROCKETMQ
at this point, you need to be aware that: Start the first time Name Server Stop when you stop. B Roker
3 , try to start "NameServer"
> nohup sh bin/mqnamesrv &> tail-f ~/logs/rocketmqlogs/namesrv.log log file will automatically generate the Name Server boot success ...
4 , try to start "Broker"
> nohup sh bin/mqbroker-n localhost:9876 &> tail-f ~/logs/rocketmqlogs/broker.logthe broker[%s, 172.30.30.233 : 10911] Boot success ...
5 , Stop "Broker" Service
> SH bin/mqshutdown Broker the Mqbroker (36695) is running ... Send shutdown request to Mqbroker (36695) OK
6 , Stop "NameServer" Service
> SH bin/mqshutdown namesrv the Mqnamesrv (36664) is running ... Send shutdown request to Mqnamesrv (36664) OK
After the test is complete, the installation is successful, everything will work, this installation process is excerpted from the official documents, any objection please visit the Official document https://rocketmq.incubator.apache.org/
Second, the configuration Mqbroker
1. Typically we use a cluster mode to run broker
Broker Cluster has a variety of configuration methods: 1, single master advantages: In addition to simple configuration is not a good disadvantage: unreliable, the machine restarts or downtime, will result in the entire service is not available 2, multi-Master advantages: Simple configuration, the highest performance disadvantage: There may be a small number of message loss (configuration-related), a single machine During a reboot or outage, messages that are not consumed by the machine are not subscribed before the machine resumes, affecting the real-time 3, multi-master, and Slave, each master with a Slave, many pairs of master-slave, the cluster adopts asynchronous replication, the master has a short message delay, the millisecond level Advantages: Performance is almost the same as multi-master, high-real-time, primary and standby switch to the application transparent, without manual intervention disadvantage: Master down or disk corruption will be a small number of messages lost 4, more than master slave, each master with a slave, There are many pairs of master-slave, the cluster adopts synchronous double write, the master and prepare all write successfully, return to the application Success Advantage: Service availability and data availability is very high disadvantage: performance is slightly lower than asynchronous cluster, the current version master is not automatically switched to primary
2. Configuration file exists by default is a
[[email protected] conf]# ls 2m-2s-async 2m-noslave broker.conf.bak logback_filtersrv.xml logback_tools.xml2m-2s -sync brk.conf Logback_broker.xml Logback_namesrv.xml
which m represents the primary node, s it means to run from the node, in the form of a cluster, to modify it in the configuration file, and then call it in the service script. Here we just run a single-node broker, the specific cluster mode please self-pondering, the default broker.conf do backup, and copy a configuration file, renamed to brk.conf This name is random, it is recommended to be known, convenient to call in the script.
3. # Cat Brk.conf
Brokerclustername = Onebroker Brokername = Broker-abrokerid = 0 0 means master,1 = 04fileReservedTime = 4 8brokerRole = Async_masterflushdisktype = Async_flushnamesrvaddr = mycat:9876 indicates mqname serverstorepathrootdir =/data/ro Cketmq/storestorepathcommitlog =/data/rocketmq/store/commitlogautocreatetopicenable = Trueautocreatesubscriptiongroup = True
4. usually
/data/rocketmq/store and the / Data/rocketmq/store/commitlog is required to manually create the
for security reasons, we use MQ users start and close services
# useradd mq# chown-r mq:mq/data/rocketmq/# chown-r MQ:MQ/OPT/APACHE-ROCKETMQ
Iii. Provision of service scripts
# Cat/etc/init.d/mqnamesrv
#!/bin/bash# chkconfig: 2345 55 25# description:mq manmger. /etc/rc.d /init.d/functionsstart () {statusif [ $? -ne 0 ] thenecho ' start Rocketmq-namserv. ' #################################### #需要修改的就是下面一行 ####################################### # #su - mq -c "nohup /opt/apache-rocketmq/bin/mqnamesrv &> /data/ rocketmq/logs/mq_namser.log & "if [ $? -eq 0 ];thenecho " started ... " Fifi}stop () {pid= ' ps ax | grep -i ' Org.apache.rocketmq.namesrv.NamesrvStartup ' | grep java | grep -v grep | awk ' {print $1} ' if [ -z "$pid" ] ; thenecho "no mqnamesrv running." return 2;elseecho "The mqnamesrv (${pid}) is running ..." kill ${pid}echo " Send shutdown request to mqnamesrv (${pid}) ok "Fi}restart () {stopstart}status () {pid= ' ps ax | grep -i ' Org.apache.rocketmq.namesrv.NamesrvStartup ' |grep java | grep -v grep | awk ' {print $1} ' if [ -z ' $pid ] ; thenecho ' no Mqnamesrv running. " return 1;fiecho "The mqnamesrv (${pid}) is running ..." return 0}case "$" instart) Start; stop) stop;; restart) restart;; status) status; *) echo $ "Usage: $0 {start|stop|restart|tatus}" Esac
# Cat/etc/init.d/mqbroker
#!/bin/bash# chkconfig: 2345 95 25# description:mq manmger. /etc/rc.d /init.d/functionsstart () {pid= ' ps ax | grep -i ' Org.apache.rocketmq.broker.BrokerStartup ' |grep java | grep -v grep | awk ' {print $1} ' if [ -z ' $pid ' ] ; then### Call script to start mq-master-1.propertiesecho ' Start rocketmq-broker ... ' su - mq -c ' nohup /opt/apache-rocketmq/bin/mqbroker -c /opt/apache-rocketmq/conf/brk.conf &> / data/rocketmq/logs/mqbroker.log & "sleep 1newpid= ' ps ax | grep -i ' Org.apache.rocketmq.broker.BrokerStartup ' |grep java | grep -v grep | awk ' {print $1} ' echo ' Restart mqbroker (${newpid}) is running success ... " elseecho "The mqbroker (${pid}) is running ..." fi}stop () {pid= ' PS&Nbsp;ax | grep -i ' Org.apache.rocketmq.broker.BrokerStartup ' |grep java | grep -v grep | awk ' {print $1} ' if [ -z "$pid" ] ; thenecho "no mqbroker running." return 2;elseecho "The mqbroker (${pid}) is running ..." echo -e "Send Shutdown to mqbroker (${pid}) \c "kill ${pid}oldpid= $pidwhile [ ${oldpid} ] Dooldpid= ' ps ax | grep -i ' Org.apache.rocketmq.broker.BrokerStartup ' |grep java | grep -v grep | awk ' {print $1} ' echo -e '!\c ' sleep 1doneecho -e "\nsend shutdown request to mqbroker (${pid}) ok" fi} Status () {pid= ' ps ax | grep -i ' Org.apache.rocketmq.broker.BrokerStartup ' | grep java | grep -v grep | awk ' {Print $1} "if [ -z " $pid " ] ; thenecho " no mqbroker running. " return 1;fiecho "The mqbroker (${pid}) is running ..." return 0}case "$" instart) Start; stop) stop;; restart) Stopstart;; status) status; *) echo $ "Usage: $0 {start|stop|restart|tatus}" Esac
Start the service, to start the mqnamesrv after the start of the Mqbroker, so far, the installation and configuration process is over, as for ROCKETMQ there are more play, to follow up the study, I hope to be helpful.
This article is from the "Tianxi" blog, make sure to keep this source http://tianxi.blog.51cto.com/12735181/1922653
Build ROCKETMQ under Linux (with service script)