diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..23646f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +*# +*.iml +*.ipr +*.iws +*.jar +*.sw? +*~ +.#* +.*.md.html +.DS_Store +.classpath +.factorypath +.gradle +.idea +.metadata +.project +.recommenders +.settings +.springBeans +/build +/code +MANIFEST.MF +_site/ +activemq-data +bin +build +build.log +dependency-reduced-pom.xml +dump.rdb +interpolated*.xml +lib/ +manifest.yml +overridedb.* +settings.xml +target +classes +out +transaction-logs +.flattened-pom.xml +secrets.yml +.gradletasknamecache +.sts4-cache \ No newline at end of file diff --git a/README.md b/README.md index 08c8284..233e3a0 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ -> 大数据常用技术栈学习之路 — — 持续更新中 +> Java 程序员的大数据学习之路 — — 持续更新中 @@ -16,6 +16,7 @@ + @@ -30,20 +31,22 @@ Hive Spark Flink - Flume - Oozie - Sqoop - Azkaban - Hbase - Kafka - Zookeeper - Scala + storm + Flume + Oozie + Sqoop + Azkaban + Hbase + Kafka + Zookeeper + Scala -> 本仓库涉及的所有软件的详细搭建步骤整理至:[linux下大数据常用软件安装指南](https://github.com/heibaiying/BigData-Notes/blob/master/notes/linux下大数据常用软件安装指南.md) + +> 本仓库涉及的所有软件的详细搭建步骤整理至:[Linux下大数据常用软件安装指南](https://github.com/heibaiying/BigData-Notes/blob/master/notes/Linux下大数据常用软件安装指南.md) @@ -55,17 +58,24 @@ ## 二、Hive -1. [数据仓库——Hive](https://github.com/heibaiying/BigData-Notes/blob/master/notes/Hive.md) +1. [数据仓库Hive](https://github.com/heibaiying/BigData-Notes/blob/master/notes/Hive.md) ## 三、Spark +1. RDD详解 +2. Spark Transformation 和 Action + ## 四、Flink -## 五、Flume -## 六、Oozie -## 七、Sqoop -## 八、Azkaban -## 九、Hbase -## 十、Kafka -## 十一、Zookeeper -## 十二、Scala +## 五、Storm + +1. [storm核心概念详解](https://github.com/heibaiying/BigData-Notes/blob/master/notes/Storm核心概念详解.md) + +## 六、Flume +## 七、Oozie +## 八、Sqoop +## 九、Azkaban +## 十、Hbase +## 十一、Kafka +## 十二、Zookeeper +## 十三、Scala diff --git a/notes/RDD详解.md b/notes/RDD详解.md new file mode 100644 index 0000000..e69de29 diff --git a/notes/Storm核心概念详解.md b/notes/Storm核心概念详解.md new file mode 100644 index 0000000..ba71fe8 --- /dev/null +++ b/notes/Storm核心概念详解.md @@ -0,0 +1,268 @@ +# storm 核心概念核心概念详解 + + +## 一、storm核心概念 + +
+ +### 1.1 Topologies(拓扑) + +Storm应用程序的逻辑被封装在 Storm topology(拓扑)中,一个拓扑是 Spout 和 Bolt 通过 stream groupings 连接起来的有向无环图,Storm会一直保持Topologies运行,直到你将其杀死(kill)为止。 + +### 1.2 Streams(流) + +stream 是 Storm 中的核心概念,一个 stream 是一个无界的、以分布式方式并行创建和处理的 Tuple 序列。 + +默认情况下 Tuple 可以包含 integers, longs, shorts, bytes, strings, doubles, floats, booleans, and byte arrays 等数据类型,当然你也可以实现自己的自定义类型。 + +### 1.3 Spouts + +Spout 是一个 topology(拓扑)中 stream的源头, 通常 Spout 会从外部数据源读取 Tuple。 + +Spout分为 **可靠** 和**不可靠**两种,可靠的 Spout 在 Storm 处理失败的时候能够重新发送 Tuple, 不可靠的 Spout一旦把Tuple 发送出去就不管了。 + +Spout 可以向不止一个流中发送数据,可以使用`OutputFieldsDeclare` 的 declareStream 方法定义多个流,并在 `SpoutOutputCollector`对象的 emit 方法中指定要发送到的stream 。 + +```java +public class SpoutOutputCollector implements ISpoutOutputCollector { + ISpoutOutputCollector _delegate; + + ... + + public List emit(String streamId, List tuple, Object messageId) { + return _delegate.emit(streamId, tuple, messageId); + } + + + public List emit(List tuple, Object messageId) { + return emit(Utils.DEFAULT_STREAM_ID, tuple, messageId); + } + + + public List emit(List tuple) { + return emit(tuple, null); + } + + + public List emit(String streamId, List tuple) { + return emit(streamId, tuple, null); + } + + public void emitDirect(int taskId, String streamId, List tuple, Object messageId) { + _delegate.emitDirect(taskId, streamId, tuple, messageId); + } + + public void emitDirect(int taskId, List tuple, Object messageId) { + emitDirect(taskId, Utils.DEFAULT_STREAM_ID, tuple, messageId); + } + + + public void emitDirect(int taskId, String streamId, List tuple) { + emitDirect(taskId, streamId, tuple, null); + } + + public void emitDirect(int taskId, List tuple) { + emitDirect(taskId, tuple, null); + } + +} +``` + +Spout 中的最主要的方法是 `nextTuple`。`nextTuple` 向 topology(拓扑)中发送一个新的 Tuple, 如果没有 Tuple 需要发送就直接返回。对于任何 Spout 实现 `nextTuple` 方法都必须非阻塞的,因为 Storm在一个线程中调用Spout 的所有方法。 + +Spout 的另外几个重要的方法是 `ack` 和 `fail`。 这些方法在 Storm 检测到 Spout 发送出去的 Tuple 被成功处理或者处理失败的时候调用。 `ack`和`fail`只会在可靠的 Spout 中会被调用。 + +**IRichSpout**: 创建 Spout 时必须实现的接口,其中定义了Spout 的主要方法。但是在通常情况下,由于我们并不需要实现其中的全部方法,所以我们并不会直接实现IRichSpout,而是继承其抽象子类**BaseRichSpout**。 + +```java +public interface ISpout extends Serializable { + + void open(Map conf, TopologyContext context, SpoutOutputCollector collector); + + void close(); + + void activate(); + + void deactivate(); + + void nextTuple(); + + void ack(Object msgId); + + void fail(Object msgId); +} +``` + +BaseRichSpout继承自BaseComponent并空实现了ISpout中的部分方法,这样我们在实现自定义Spout的时候就不需要实现其中不必要的方法。 + +注:BaseComponent是IComponent的抽象实现类,IComponent 中定义了Topologies(拓扑)中所有基本组件(如Spout,Bolts)的常用方法。 + +```java +public abstract class BaseRichSpout extends BaseComponent implements IRichSpout { + @Override + public void close() { + } + + @Override + public void activate() { + } + + @Override + public void deactivate() { + } + + @Override + public void ack(Object msgId) { + } + + @Override + public void fail(Object msgId) { + } +} + +``` + +### 1.4 Bolts + +Bolts是实际的stream处理单元,它负责处理数据的处理。Bolts可以执行过滤(filtering),聚合(aggregations),joins,与文件/数据库交互等操作。Bolts从spout/Bolts接收数据,处理后再发射数据到一个或多个Bolts中。 + +Bolts是stream的的处理单元,对于一个处理单元来说,重要的就只有三点: + ++ 如何获取数据? ++ 怎样处理数据? ++ 怎样将处理好的数据发送出去? + +**1.获取数据** + +Spouts在从外部数据源获得数据后,将数据发送到stream,Bolts想要获得对应的数据,可以通过`shuffleGrouping`方法实现对组件(Spouts/Bolts)特定流的订阅。 + +**2.处理数据** + +Bolt 中最主要的方法是 `execute` 方法, 当有一个新 Tuple 输入的时候就会进入这个方法,我们可以在这个方法中实现具体的处理逻辑。 + +**3.发送数据** + +这个地方与Sprout是相同的,Bolts 可以向不止一个流中发送数据,可以使用`OutputFieldsDeclare` 的 declareStream 方法定义多个流,并在 `SpoutOutputCollector`对象的 emit 方法中指定要发送到的stream 。 + + + +### 1.5 Stream groupings(分组策略) + +
+ +spouts和bolts在集群上执行任务时,是由多个Task并行执行(如上图,每一个圆圈代表一个Task)。当一个tuple需要从Bolt A发送给Bolt B执行的时候,我们怎么知道需要发送给Bolt B的哪一个Task执行?这是由Stream groupings 分组策略来决定的。 + +Storm 中一共有8个内置的 Stream Grouping。也可以通过实现 `CustomStreamGrouping`接口来自定义 Stream groupings。 + +1. **Shuffle grouping**: Tuple 随机的分发到 Bolt Task, 每个 Bolt 获取到等量的 Tuple。 +2. **Fields grouping**: streams 通过 grouping 指定的字段来分区. 例如流通过 "user-id" 字段分区, 具有相同 "user-id" 的 Tuple 会发送到同一个task, 不同 "user-id" 的 Tuple 可能会流入到不同的 tasks。 +3. **Partial Key grouping**: stream 通过 grouping 中指定的 field 来分组, 与 Fields Grouping 相似.。但是对于 2 个下游的 Bolt 来说是负载均衡的, 可以在输入数据不平均的情况下提供更好的优化。 +4. **All grouping**: stream 在所有的 Bolt Tasks之间复制. 这个 Grouping 需要谨慎使用。 +5. **Global grouping**: 整个 stream 会进入 Bolt 其中一个任务。特别指出, 它会进入 id 最小的 task。 +6. **None grouping**: 这个 grouping , 你不需要关心 stream 如何分组. 当前, None grouping 和 Shuffle grouping 等价。同时, Storm可能会将使用 None grouping 的 bolts 和上游订阅的 bolt/spout 运行在同一个线程。 +7. **Direct grouping**: 这是一种特殊的 grouping 方式. stream 用这个方式 group 意味着由这个 Tuple 的 **生产者** 来决定哪个**消费者** 来接收它。Direct grouping 只能被用于 direct streams 。 +8. **Local or shuffle grouping**: 如果目标 Bolt 有多个 task 和 streams源 在同一个 woker 进程中, Tuple 只会 shuffle 到相同 worker 的任务。否则, 就和 shuffle goruping 一样。 + + + +## 二、storm架构详解 + +
+ +### 2.1 nimbus进程 + + 也叫做 master node,是storm集群工作的全局指挥官。 + +1. 通过thrift接口,监听并接收client对topology的submit, 将topology代码保存到本地目录/nimbus/stormdist/下 ; +2. 为client提交的topology计算任务分配,根据集群worker资源情况,计算出topology的spoult和bolt的task应该如何在worker间分配,任务分配结果写入zookeeper ; +3. 通过thrift接口,监听supervisor的下载topology代码的请求,并提供下载 ; +4. 通过thrift接口,监听ui对统计信息的读取,从zookeeper上读取统计信息,返回给ui ; +5. 若进程退出后,立即在本机重启,则不影响集群运行。 + + + +### 2.2 supervisor进程 + +也叫做 worker node , storm集群的资源管理者,按需启动worker进程。 + +1. 定时从zookeeper 检查是否有代码未下载到本地的新topology ,定时删除旧topology代码 ; +2. 根据nimbus的任务分配结果,在本机按需启动1个或多个worker进程,监控守护所有的worker进程; +3. 若进程退出,立即在本机重启,则不影响集群运行。 + + + +### 2.3 Zookeeper的作用 + +Nimbus和Supervisor进程都被设计为**快速失败**(遇到任何意外情况时进程自毁)和**无状态**(所有状态保存在Zookeeper或磁盘上)。 因此,如果Nimbus或Supervisor守护进程死亡,它们会重新启动,并从zookeeper上获取之前的状态数据,就像什么都没发生一样。 + + + +### 2.4 worker进程 + +torm集群的任务构造者 ,构造spoult或bolt的task实例,启动executor线程。 + +1. 根据zookeeper上分配的task,在本进程中启动1个或多个executor线程,将构造好的task实例交给executor去运行(死循环调用spoult.nextTuple()或bolt.execute()方法); +2. 向zookeeper写入心跳 ; +3. 维持传输队列,发送tuple到其他的worker ; +4. 若进程退出,立即在本机重启,则不影响集群运行。 + +### 2.5 executor线程 + +storm集群的任务执行者 ,循环执行task代码。 + +1. 执行1个或多个task(每个task对应spout或bolt的1个并行度),将输出加入到worker里的tuple队列 ; +2. 执行storm内部线程acker,负责发送消息处理状态给对应spoult所在的worker。 + + + +### 2.6 并行度 + +
+ +1个worker进程执行的是1个topology的子集(注:不会出现1个worker为多个topology服务)。1个worker进程会启动1个或多个executor线程来执行1个topology的component(spout或bolt)。因此1个运行中的topology就是由集群中多台物理机上的多个worker进程组成的。 + +executor是1个被worker进程启动的单独线程。每个executor会运行1个component(spout或bolt)的中的一个或者多个task。 + +task是最终运行spout或bolt中代码的单元。topology启动后,1个component(spout或bolt)的task数目是固定不变的,但该component使用的executor线程数可以动态调整(例如:1个executor线程可以执行该component的1个或多个task实例)。这意味着,对于1个component:`#threads<=#tasks`(即:线程数小于等于task数目)这样的情况是存在的。默认情况下task的数目等于executor线程数目,即1个executor线程只运行1个task。 + +**默认情况下**: + ++ 每个worker进程默认启动一个executor线程 ++ 每个executor默认启动一个task线程 + + + +## 三、Linux下Storm单机版本环境搭建 + + + +## 四、storm词频统计案例 + + + + + +## 参考资料 + +1. [storm documentation -> Concepts](http://storm.apache.org/releases/1.2.2/Concepts.html) + +2. [Internal Working of Apache Storm](https://www.spritle.com/blogs/2016/04/04/apache-storm/) +3. [Understanding the Parallelism of a Storm Topology](http://storm.apache.org/releases/1.2.2/Understanding-the-parallelism-of-a-Storm-topology.html) +4. [Storm nimbus 单节点宕机的处理](https://blog.csdn.net/daiyutage/article/details/52049519) + diff --git a/notes/installation/JDK安装.md b/notes/installation/Linux下JDK安装.md similarity index 100% rename from notes/installation/JDK安装.md rename to notes/installation/Linux下JDK安装.md diff --git a/notes/installation/Linux下Python安装.md b/notes/installation/Linux下Python安装.md new file mode 100644 index 0000000..273a914 --- /dev/null +++ b/notes/installation/Linux下Python安装.md @@ -0,0 +1,71 @@ +## Linux下Python安装 + +>**系统环境**:centos 7.6 +> +>**Python版本**:Python-3.6.8 + +### 1.环境依赖 + +Python3.x的安装需要需要这四个依赖:gcc, zlib, zlib-devel, openssl-devel,这四个软件需要先进行安装 + +```shell +yum install gcc -y +yum install zlib -y +yum install zlib-devel -y +yum install openssl-devel -y +``` + +### 2.下载编译 + +官方下载地址: https://www.python.org/downloads/ + +```shell +# wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz +``` + +### 3.解压编译 + +```shell +# tar -zxvf Python-3.6.8.tgz +``` + +进入解压后目录进行编译,可以指定编译安装的路径,这里我们指定为`/usr/app/python3.6` + +```shell +# cd Python-3.6.8 +# ./configure --prefix=/usr/app/python3.6 +# make && make install +``` + +### 4.环境变量配置 + +```shell +vim /etc/profile +``` + +```shell +export PYTHON_HOME=/usr/app/python3.6 +export PATH=${PYTHON_HOME}/bin:$PATH +``` + +使得环境变量立即生效: + +```shell +source /etc/profile +``` + +### 5.验证安装是否成功 + +输入python3命令,如果能进入python交互环境,则代表安装成功 + +```shell +[root@hadoop001 app]# python3 +Python 3.6.8 (default, Mar 29 2019, 10:17:41) +[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux +Type "help", "copyright", "credits" or "license" for more information. +>>> 1+1 +2 +>>> exit() +[root@hadoop001 app]# +``` + diff --git a/notes/installation/Spark单机版本环境搭建.md b/notes/installation/Spark单机版本环境搭建.md index bd0c40f..075515a 100644 --- a/notes/installation/Spark单机版本环境搭建.md +++ b/notes/installation/Spark单机版本环境搭建.md @@ -4,7 +4,6 @@ >**系统环境**:centos 7.6 > ->**Spark版本**:spark-2.2.3-bin-hadoop2.6 diff --git a/notes/installation/Storm单机版本环境搭建.md b/notes/installation/Storm单机版本环境搭建.md new file mode 100644 index 0000000..480e358 --- /dev/null +++ b/notes/installation/Storm单机版本环境搭建.md @@ -0,0 +1,102 @@ +# Storm单机版本环境搭建 + + + +>**storm版本**:1.2.2 + + + + +### 1.安装环境要求 + +按照[官方文档](http://storm.apache.org/releases/1.2.2/Setting-up-a-Storm-cluster.html)的要求: + +> you need to install Storm's dependencies on Nimbus and the worker machines. These are: +> +> 1. Java 7+ (Apache Storm 1.x is tested through travis ci against both java 7 and java 8 JDKs) +> 2. Python 2.6.6 (Python 3.x should work too, but is not tested as part of our CI enviornment) + +storm 运行依赖于Java 7+ 和 Python 2.6.6 +,所以需要先安装以上两个软件。 + + 由于以上两个软件在多个环境中都有依赖,其安装步骤单独整理至: + ++ [Linux环境下JDK安装](https://github.com/heibaiying/BigData-Notes/blob/master/notes/installation/Linux下JDK安装.md) + ++ [Linux环境下Python安装](https://github.com/heibaiying/BigData-Notes/blob/master/notes/installation/Linux下Python安装.md) + + + +### 2.下载并解压 + +官方下载地址:http://storm.apache.org/downloads.html + +下载后进行解压: + +```shell +# tar -zxvf apache-storm-1.2.2.tar.gz +``` + + + +### 3.配置环境变量 + +```shell +# vim /etc/profile +``` + +添加环境变量: + +```shell +export STORM_HOME=/usr/app/apache-storm-1.2.2 +export PATH=$STORM_HOME/bin:$PATH +``` + +使得配置的环境变量生效: + +```shell +# source /etc/profile +``` + + + +### 4.启动相关进程 + +因为要启动多个进程,所以这里我们统一用后台进程的方式启动 + +```shell +# 启动zookeeper +nohup sh storm dev-zookeeper & +# 启动主节点 nimbus +nohup sh storm nimbus & +# 启动从节点 supervisor +nohup sh storm supervisor & +# 启动UI界面 ui +nohup sh storm ui & +# 启动日志查看服务 logviewer +nohup sh storm logviewer & +``` + + + +### 5.验证是否启动成功 + +验证方式一:jps 查看进程 + +```shell +[root@hadoop001 app]# jps +1074 nimbus +1283 Supervisor +620 dev_zookeeper +1485 core +9630 logviewer +``` + +验证方式二: 访问8080端口,查看Web-UI界面 + +
\ No newline at end of file diff --git a/notes/linux下大数据常用软件安装指南.md b/notes/linux下大数据常用软件安装指南.md index ca26486..fbaf75a 100644 --- a/notes/linux下大数据常用软件安装指南.md +++ b/notes/linux下大数据常用软件安装指南.md @@ -1,26 +1,31 @@ ## 大数据环境搭建指南 +### 一、基础软件安装 - -## 一、JDK - -1. [Linux环境下JDK的安装](https://github.com/heibaiying/BigData-Notes/blob/master/notes/installation/JDK安装.md) +1. [Linux环境下JDK安装](https://github.com/heibaiying/BigData-Notes/blob/master/notes/installation/Linux下JDK安装.md) +2. [Linux环境下Python安装](https://github.com/heibaiying/BigData-Notes/blob/master/notes/installation/Linux下Python安装.md) -## 二、Hadoop +### 二、Hadoop -1. [Hadoop单机版本环境搭建](https://github.com/heibaiying/BigData-Notes/blob/master/notes/installation/hadoop单机版本环境搭建.md) +1. [Hadoop单机版本环境搭建](https://github.com/heibaiying/BigData-Notes/blob/master/notes/installation/Hadoop单机版本环境搭建.md) -## 三、Spark +### 三、Spark 1. [Spark单机版本环境搭建](https://github.com/heibaiying/BigData-Notes/blob/master/notes/installation/Spark单机版本环境搭建.md) -## 网络配置 +### 四、Storm + +1. [Storm单机版本环境搭建](https://github.com/heibaiying/BigData-Notes/blob/master/notes/installation/Storm单机版本环境搭建.md) + + + +### 五、Linux + [虚拟机静态IP配置](https://github.com/heibaiying/BigData-Notes/blob/master/notes/installation/虚拟机静态IP配置.md) diff --git a/pictures/Internal-Working-of-Apache-Storm.png b/pictures/Internal-Working-of-Apache-Storm.png new file mode 100644 index 0000000..df50c16 Binary files /dev/null and b/pictures/Internal-Working-of-Apache-Storm.png differ diff --git a/pictures/Stream groupings.png b/pictures/Stream groupings.png new file mode 100644 index 0000000..74d827f Binary files /dev/null and b/pictures/Stream groupings.png differ diff --git a/pictures/relationships-worker-processes-executors-tasks.png b/pictures/relationships-worker-processes-executors-tasks.png new file mode 100644 index 0000000..876c73d Binary files /dev/null and b/pictures/relationships-worker-processes-executors-tasks.png differ diff --git a/pictures/spout-bolt.png b/pictures/spout-bolt.png new file mode 100644 index 0000000..ecbbc3a Binary files /dev/null and b/pictures/spout-bolt.png differ diff --git a/pictures/storm-bolts.png b/pictures/storm-bolts.png new file mode 100644 index 0000000..e1cf453 Binary files /dev/null and b/pictures/storm-bolts.png differ diff --git a/pictures/storm-flow.png b/pictures/storm-flow.png new file mode 100644 index 0000000..45df814 Binary files /dev/null and b/pictures/storm-flow.png differ diff --git a/pictures/storm-spouts.png b/pictures/storm-spouts.png new file mode 100644 index 0000000..c7f96da Binary files /dev/null and b/pictures/storm-spouts.png differ diff --git a/pictures/storm-streams.png b/pictures/storm-streams.png new file mode 100644 index 0000000..6892da0 Binary files /dev/null and b/pictures/storm-streams.png differ diff --git a/pictures/storm-topology.png b/pictures/storm-topology.png new file mode 100644 index 0000000..304b769 Binary files /dev/null and b/pictures/storm-topology.png differ diff --git a/pictures/storm-tuples.png b/pictures/storm-tuples.png new file mode 100644 index 0000000..79572cf Binary files /dev/null and b/pictures/storm-tuples.png differ diff --git a/pictures/storm-web-ui.png b/pictures/storm-web-ui.png new file mode 100644 index 0000000..c8a93b7 Binary files /dev/null and b/pictures/storm-web-ui.png differ diff --git a/pictures/storm.png b/pictures/storm.png new file mode 100644 index 0000000..570276e Binary files /dev/null and b/pictures/storm.png differ diff --git a/pictures/topology-tasks.png b/pictures/topology-tasks.png new file mode 100644 index 0000000..0affaba Binary files /dev/null and b/pictures/topology-tasks.png differ