【原创】《从0开始学RocketMQ》—单机搭建
内容目录
1. RocketMQ是什么?
2. 下载并解压
3. 启动NameServer
4. 启动 Broker
5. 关闭消息队列
1. RocketMQ是什么?
RocketMQ是一种消息队列。何为消息队列?即数据结构中一种“先进先出”的数据结构。在微服务中,分布式消息队列可以解决什么问题?应用解耦、流量削峰、消息分发、保证最终一致性、方便动态扩容等。
RocketMQ中不可不知的四个角色:Producer(消息生产者)、Consumer(消息消费者)、Broker(消息暂存者)、NameServer(消息协调者)。由这四个角色的作用可知,启动 RocketMQ 时,应该先启动 NameServer,然后再启动 Broker,后续需要发送消息就用 Producer,需要接收消息就用 Consumer。
2. 下载并解压
cd /usr/local
wget -c http://mirrors.shu.edu.cn/apache/rocketmq/4.3.2/rocketmq-all-4.3.2-bin-release.zip
unzip rocketmq-all-4.3.-bin-release.zip -d .
cd rocketmq-all-4.3.-bin-release
ls
[root@- rocketmq-all-4.3.-bin-release]# ls
benchmark bin conf lib LICENSE NOTICE README.md
3. 启动NameServer
启动NameServer:nohup sh bin/mqnamesrv &
,然而发现不能正常启动,如下:
[root@- rocketmq-all-4.3.-bin-release]# nohup sh bin/mqnamesrv &
[]
[root@- rocketmq-all-4.3.-bin-release]# nohup: ignoring input and appending output to ‘nohup.out’ []+ Exit nohup sh bin/mqnamesrv
查看nohup.out:
[root@- rocketmq-all-4.3.-bin-release]# cat nohup.out
ERROR: Please set the JAVA_HOME variable in your environment, We need java(x64)! !!
可是,本机明明已经安装jdk并且已经配置了 JAVA_HOME 环境变量呀:
[root@- rocketmq-all-4.3.-bin-release]# java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) -Bit Server VM (build 25.171-b11, mixed mode)
环境变量设置:
#####################java env###############
JAVA_HOME=/opt/jdk1..0_171
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
PATH=$JAVA_HOME/bin:$HOME/bin:$HOME/.local/bin:$PATH
查看 runserver.sh 脚本,发现有这么三行命令:
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
[ ! -e "$JAVA_HOME/bin/java" ] && error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)!"
将其注释之,继续往下看,发现下面两行:
export JAVA_HOME
export JAVA="$JAVA_HOME/bin/java"
嗯,果断修改 JAVA_HOME 的值如下:
export JAVA_HOME=/opt/jdk1..0_171
再次启动 NameServer :
[root@- rocketmq-all-4.3.-bin-release]# nohup sh bin/mqnamesrv &
[]
[root@- rocketmq-all-4.3.-bin-release]# nohup: ignoring input and appending output to ‘nohup.out’ [root@- rocketmq-all-4.3.-bin-release]# ls
benchmark bin conf lib LICENSE nohup.out NOTICE README.md
[root@- rocketmq-all-4.3.-bin-release]# cat nohup.out
Java HotSpot(TM) -Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release
Java HotSpot(TM) -Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
The Name Server boot success. serializeType=JSON
此处可以看到 NameServer 已成功启动,查看 NameServer 日志:
[root@- rocketmq-all-4.3.-bin-release]# tail -f ~/logs/rocketmqlogs/namesrv.log
-- :: INFO main - tls.client.certPath = null
-- :: INFO main - tls.client.authServer = false
-- :: INFO main - tls.client.trustCertPath = null
-- :: INFO main - Using OpenSSL provider
-- :: INFO main - SSLContext created for server
-- :: INFO NettyEventExecutor - NettyEventExecutor service started
-- :: INFO FileWatchService - FileWatchService service started
-- :: INFO main - The Name Server boot success. serializeType=JSON
-- :: INFO NSScheduledThread1 - --------------------------------------------------------
-- :: INFO NSScheduledThread1 - configTable SIZE:
NameServer 启动成功
4. 启动 Broker
启动Broker:nohup sh bin/mqbroker -n localhost:9876&
,然而发现不能正常启动,如下:
[root@- rocketmq-all-4.3.-bin-release]# nohup sh bin/mqbroker -n localhost:&
[]
[root@- rocketmq-all-4.3.-bin-release]# nohup: ignoring input and appending output to ‘nohup.out’ []+ Exit nohup sh bin/mqbroker -n localhost:
查看nohup.out,发现里面多了这么几行错误信息:
Java HotSpot(TM) -Bit Server VM warning: INFO: os::commit_memory(0x00000005c0000000, , ) failed; error='Cannot allocate memory' (errno=)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map bytes for committing reserved memory.
# An error report file with more information is saved as:
# /usr/local/rocketmq-all-4.3.-bin-release/hs_err_pid28580.log
遂,查看 hs_err_pid28580.log:
[root@- rocketmq-all-4.3.-bin-release]# tail -1000f /usr/local/rocketmq-all-4.3.-bin-release/hs_err_pid28580.log
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map bytes for committing reserved memory.
# Possible reasons:
# The system is out of physical RAM or swap space
# In bit mode, the process size limit was hit
# Possible solutions:
# Reduce memory load on the system
# Increase physical memory or swap space
# Check if swap backing store is full
# Use bit Java on a bit OS
# Decrease Java heap size (-Xmx/-Xms)
# Decrease number of Java threads
# Decrease Java thread stack sizes (-Xss)
# Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
# Out of Memory Error (os_linux.cpp:), pid=, tid=0x00007fbc93a6c700
#
# JRE version: (.0_171-b11) (build )
# Java VM: Java HotSpot(TM) -Bit Server VM (25.171-b11 mixed mode linux-amd64 compressed oops)
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
........
VM Arguments:
jvm_args: -Xms8g -Xmx8g -Xmn4g -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent= -XX:InitiatingHeapOccupancyPercent= -XX:SoftRefLRUPolicyMSPerMB= -XX:SurvivorRatio= -verbose:gc -Xloggc:/dev/shm/mq_gc_%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles= -XX:GCLogFileSize=30m -XX:-OmitStackTraceInFastThrow -XX:+AlwaysPreTouch -XX:MaxDirectMemorySize=15g -XX:-UseLargePages -XX:-UseBiasedLocking -Djava.ext.dirs=/opt/jdk1..0_171/jre/lib/ext:/usr/local/rocketmq-all-4.3.-bin-release/bin/../lib
java_command: org.apache.rocketmq.broker.BrokerStartup -n localhost:
java_class_path (initial): .:/usr/local/rocketmq-all-4.3.-bin-release/bin/../conf:.:/opt/jdk1..0_171/lib/tools.jar:/opt/jdk1..0_171/lib/dt.jar
Launcher Type: SUN_STANDARD
......
大概意思呢,就是说,启动broker时内存不足,为什么内存不足呢?因为启动时候指定了JVM最大可用内存和最小可用内存均为8G,年轻代大小为2G。
查看Broker启动脚本,发现果然指定了这三个jvm启动参数,然后意外发现对于JAVA_HOME的设置,runbroker.sh与runserver.sh是一样一样的:
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
[ ! -e "$JAVA_HOME/bin/java" ] && error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)!" export JAVA_HOME
export JAVA="$JAVA_HOME/bin/java"
export BASE_DIR=$(dirname $)/..
export CLASSPATH=.:${BASE_DIR}/conf:${CLASSPATH} #===========================================================================================
# JVM Configuration
#===========================================================================================
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"
遂,修改启动脚本中JAVA_HOME的设置以及JVM启动脚本如下:
#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
#[ ! -e "$JAVA_HOME/bin/java" ] && error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)!" export JAVA_HOME=/opt/jdk1..0_171
export JAVA="$JAVA_HOME/bin/java"
export BASE_DIR=$(dirname $)/..
export CLASSPATH=.:${BASE_DIR}/conf:${CLASSPATH} #===========================================================================================
# JVM Configuration
#===========================================================================================
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"
再次启动Broker:
[root@- rocketmq-all-4.3.-bin-release]# nohup sh bin/mqbroker -n localhost:&
[]
[root@- rocketmq-all-4.3.-bin-release]# nohup: ignoring input and appending output to ‘nohup.out’ [root@- rocketmq-all-4.3.-bin-release]# cat nohup.out
Java HotSpot(TM) -Bit Server VM warning: INFO: os::commit_memory(0x00000005c0000000, , ) failed; error='Cannot allocate memory' (errno=)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map bytes for committing reserved memory.
# An error report file with more information is saved as:
# /usr/local/rocketmq-all-4.3.-bin-release/hs_err_pid28580.log
The broker[-, 39.107.153.215:] boot success. serializeType=JSON and name server is localhost:
此处可以看到Broker已启动成功,查看Broker日志:
[root@- rocketmq-all-4.3.-bin-release]# tail -1000f ~/logs/rocketmqlogs/broker.log
-- :: INFO main - rocketmqHome=/usr/local/rocketmq-all-4.3.-bin-release
-- :: INFO main - namesrvAddr=localhost:
......
-- :: INFO FileWatchService - FileWatchService service started
-- :: INFO PullRequestHoldService - PullRequestHoldService service started
-- :: INFO brokerOutApi_thread_1 - register broker to name server localhost: OK
-- :: INFO main - Start transaction service!
-- :: INFO main - The broker[-, 39.107.157.89:] boot success. serializeType=JSON and name server is localhost:
5. 关闭消息队列
关闭 Broker:
[root@- rocketmq-all-4.3.-bin-release]# sh bin/mqshutdown broker
The mqbroker() is running...
Send shutdown request to mqbroker() OK
关闭 NameServer:
[root@- rocketmq-all-4.3.-bin-release]# sh bin/mqshutdown namesrv
The mqnamesrv() is running...
Send shutdown request to mqnamesrv() OK
【原创】《从0开始学RocketMQ》—单机搭建的更多相关文章
- 【原创】《从0开始学RocketMQ》—集群搭建
用两台服务器,搭建出一个双master双slave.无单点故障的高可用 RocketMQ 集群.此处假设两台服务器的物理 IP 分别为:192.168.50.1.192.168.50.2. 内容目录 ...
- rocketmq单机搭建
RocketMQ 是alibaba开源的消息队列. 本文使用的是开源版本v3.18 系统: centos6.x最小化安装 需要用到的软件包: jdk-7u67-linux-x64.tar.gz ali ...
- Redis 5.0.7 讲解,单机、集群模式搭建
Redis 5.0.7 讲解,单机.集群模式搭建 一.Redis 介绍 不管你是从事 Python.Java.Go.PHP.Ruby等等... Redis都应该是一个比较熟悉的中间件.而大部分经常写业 ...
- 从0开始学爬虫9之requests库的学习之环境搭建
从0开始学爬虫9之requests库的学习之环境搭建 Requests库的环境搭建 环境:python2.7.9版本 参考文档:http://2.python-requests.org/zh_CN/l ...
- Windows Server 2003 IIS6.0+PHP5(FastCGI)+MySQL5环境搭建教程
准备篇 一.环境说明: 操作系统:Windows Server 2003 SP2 32位 PHP版本:php 5.3.14(我用的php 5.3.10安装版) MySQL版本:MySQL5.5.25 ...
- 单机搭建Android开发环境(四)
单机搭建安卓开发环境,前三篇主要是磨刀霍霍,这一篇将重点介绍JDK.REPO.GIT及编译工具的安装,下载项目代码并编译.特别说明,以下操作基于64位12.04 Server版Ubuntu.若采用其他 ...
- 单机搭建Android开发环境(三)
单机搭建Android开发环境,第一篇重点介绍了如何优化Windows 7系统,以提高开发主机的性能并延长SSD的使用寿命.第二篇重点介绍了基于VMWare安装64位版的Ubuntu 12.04,并安 ...
- 如何从 0 开始学 ruby on rails (漫步版)
如何从 0 开始学 ruby on rails (漫步版) ruby 是一门编程语言,ruby on rails 是 ruby 的一个 web 框架,简称 rails. 有很多人对 rails 感兴 ...
- 如何从 0 开始学 Ruby on Rails
如何从 0 开始学 Ruby on Rails (漫步版)Ruby 是一门编程语言,Ruby on Rails 是 Ruby 的一个 web 框架,简称 Rails. 有很多人对 Rails 感兴趣, ...
随机推荐
- IDEA添加作者注释
1.打开IDEA的settings,然后在Editor下找到File and Code Templates 2.然后选择File Header 选择需要注释的的格式即可.
- stored procedure --存储过程
存储过程(Stored Procedure),计算机用语,是一组为了完成特定功能的SQL语句集,是利用SQL Server所提供的Transact-SQL语言所编写的程序.经编译后存储在数据库中.存储 ...
- Eureka 简介
Eureka 简介
- Linux 上运行 mapreduce 类型错误
1.ClassCastException 错误代码 /** * */ /** * @author hadoop * */ package WordCount; import java.io.IOExc ...
- Linux下kill命令的学习,(主要根据man手册进行的翻译)
名字 kill -终止一个进程 格式 kill [-s signal | -p] [--] pid .. ...
- CSS中:overflow:hidden的作用
功能1.隐藏溢出 在IE6下,当子容器的宽高超出父容器时,父容器就会被撑开来. 要想解决这个问题,在父容器中除定义宽和高的值以外,还必须写overflow:hidden,这样就能把子容器的其它内容隐 ...
- Apache Karaf配置远程调试
软件环境 apache-karaf-4.0.0 配置方法: 在 bin/karaf.bat 文件里,顶部增加 set KARAF_DEBUG=true 然后.重新启动karaf 启动之后.就可以看到例 ...
- GIS+=地理信息+云计算技术——Spark集群部署
第一步:安装软件 Spark 1.5.4:wget http://www.apache.org/dyn/closer.lua/spark/spark-1.5.2/spark-1.5.2 ...
- oracle 12c 13姨
搞了一下oracle 12c.有些体会还是先记下来. 12c搞搞新意思,弄了个CDB(容器数据库,可不是商务中心CBD哟)和PDB(可插拔数据库).PDB插在CDB里. 简单而言,CDB就是一个数据库 ...
- 浅谈UML的概念和模型之UML视图
相信大家都知道UML的全称,统一建模语言(UML是 Unified Modeling Language的缩写)是用来对软件系统进行可视化建模的一种语言.UML为面向对象开发系统的产品进行说明.可视化. ...