Apache Storm 简明教程

Apache Storm - Installation

现在让我们来看看如何在计算机上安装 Apache Storm 框架。这里有三个主要的步骤 −

Let us now see how to install Apache Storm framework on your machine. There are three majo steps here −

  1. Install Java on your system, if you don’t have it already.

  2. Install ZooKeeper framework.

  3. Install Apache Storm framework.

Step 1 − Verifying Java Installation

使用以下命令检查您的系统是否已安装 Java。

Use the following command to check whether you have Java already installed on your system.

$ java -version

如果 Java 已经存在,那么您会看到它的版本号。如果没有,请下载 JDK 的最新版本。

If Java is already there, then you would see its version number. Else, download the latest version of JDK.

Step 1.1 − Download JDK

使用以下链接下载 JDK 的最新版本 − www.oracle.com

Download the latest version of JDK by using the following link − www.oracle.com

最新版本是 JDK 8u 60,文件是 “jdk-8u60-linux-x64.tar.gz” 。将文件下载到您的计算机上。

The latest version is JDK 8u 60 and the file is “jdk-8u60-linux-x64.tar.gz”. Download the file on your machine.

Step 1.2 − Extract files

通常,文件被下载到 downloads 文件夹中。使用以下命令提取 tar 设置。

Generally files are being downloaded onto the downloads folder. Extract the tar setup using the following commands.

$ cd /go/to/download/path
$ tar -zxf jdk-8u60-linux-x64.gz

Step 1.3 − Move to opt directory

为了让所有用户都可以使用 Java,将提取的 Java 内容移动到“/usr/local/java”文件夹中。

To make Java available to all users, move the extracted java content to “/usr/local/java” folder.

$ su
password: (type password of root user)
$ mkdir /opt/jdk
$ mv jdk-1.8.0_60 /opt/jdk/

Step 1.4 − Set path

若要设置 path 及 JAVA_HOME 变量,请将以下命令添加到 ~/.bashrc 文件中。

To set path and JAVA_HOME variables, add the following commands to ~/.bashrc file.

export JAVA_HOME =/usr/jdk/jdk-1.8.0_60
export PATH=$PATH:$JAVA_HOME/bin

现在将所有更改应用到当前运行的系统中。

Now apply all the changes in to the current running system.

$ source ~/.bashrc

Step 1.5 − Java Alternatives

使用以下命令更改 Java 备用项。

Use the following command to change Java alternatives.

update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_60/bin/java 100

Step 1.6

现在,使用第 1 步中说明的验证命令 (java -version) 验证 Java 安装。

Now verify the Java installation using the verification command (java -version) explained in Step 1.

Step 2 − ZooKeeper Framework Installation

Step 2.1 − Download ZooKeeper

要在计算机上安装 ZooKeeper 框架,请访问以下链接并下载 ZooKeeper http://zookeeper.apache.org/releases.html 的最新版本

To install ZooKeeper framework on your machine, visit the following link and download the latest version of ZooKeeper http://zookeeper.apache.org/releases.html

到目前为止,ZooKeeper 的最新版本是 3.4.6 (ZooKeeper-3.4.6.tar.gz)。

As of now, the latest version of ZooKeeper is 3.4.6 (ZooKeeper-3.4.6.tar.gz).

Step 2.2 − Extract tar file

使用以下命令提取 tar 文件 −

Extract the tar file using the following commands −

$ cd opt/
$ tar -zxf zookeeper-3.4.6.tar.gz
$ cd zookeeper-3.4.6
$ mkdir data

Step 2.3 − Create configuration file

使用命令 "vi conf/zoo.cfg" 打开名为“conf/zoo.cfg”的配置文件,并使用所有以下参数作为起始点。

Open configuration file named “conf/zoo.cfg” using the command "vi conf/zoo.cfg" and setting all the following parameters as starting point.

$ vi conf/zoo.cfg
tickTime=2000
dataDir=/path/to/zookeeper/data
clientPort=2181
initLimit=5
syncLimit=2

一旦配置文件已成功保存,便可以启动 ZooKeeper 服务器。

Once the configuration file has been saved successfully, you can start the ZooKeeper server.

Step 2.4 − Start ZooKeeper Server

使用以下命令启动 ZooKeeper 服务器。

Use the following command to start the ZooKeeper server.

$ bin/zkServer.sh start

执行该命令后,你会收到如下的响应 −

After executing this command, you will get a response as follows −

$ JMX enabled by default
$ Using config: /Users/../zookeeper-3.4.6/bin/../conf/zoo.cfg
$ Starting zookeeper ... STARTED

Step 2.5 − Start CLI

使用以下命令启动 CLI。

Use the following command to start the CLI.

$ bin/zkCli.sh

执行上述命令后,你将连接到 ZooKeeper 服务器并得到以下响应。

After executing the above command, you will be connected to the ZooKeeper server and get the following response.

Connecting to localhost:2181
................
................
................
Welcome to ZooKeeper!
................
................
WATCHER::
WatchedEvent state:SyncConnected type: None path:null
[zk: localhost:2181(CONNECTED) 0]

Step 2.6 − Stop ZooKeeper Server

连接到服务器并执行完所有操作后,可以使用以下命令停止 ZooKeeper 服务器。

After connecting the server and performing all the operations, you can stop the ZooKeeper server by using the following command.

bin/zkServer.sh stop

你已成功在你的机器上安装了 Java 和 ZooKeeper。现在让我们看看安装 Apache Storm 框架的步骤。

You have successfully installed Java and ZooKeeper on your machine. Let us now see the steps to install Apache Storm framework.

Step 3 − Apache Storm Framework Installation

Step 3.1 Download Storm

要在你的机器上安装 Storm 框架,请访问以下链接并下载 Storm 的最新版本。

To install Storm framework on your machine, visit the following link and download the latest version of Storm http://storm.apache.org/downloads.html

截至目前,Storm 的最新版本为“apache-storm-0.9.5.tar.gz”。

As of now, the latest version of Storm is “apache-storm-0.9.5.tar.gz”.

Step 3.2 − Extract tar file

使用以下命令提取 tar 文件 −

Extract the tar file using the following commands −

$ cd opt/
$ tar -zxf apache-storm-0.9.5.tar.gz
$ cd apache-storm-0.9.5
$ mkdir data

Step 3.3 − Open configuration file

Storm 的当前发行版包含一个位于“conf/storm.yaml”的文件,可配置 Storm 守护程序。将以下信息添加到该文件中。

The current release of Storm contains a file at “conf/storm.yaml” that configures Storm daemons. Add the following information to that file.

$ vi conf/storm.yaml
storm.zookeeper.servers:
 - "localhost"
storm.local.dir: “/path/to/storm/data(any path)”
nimbus.host: "localhost"
supervisor.slots.ports:
 - 6700
 - 6701
 - 6702
 - 6703

应用完所有更改后,保存并返回到终端。

After applying all the changes, save and return to terminal.

Step 3.4 − Start the Nimbus

$ bin/storm nimbus

Step 3.5 − Start the Supervisor

$ bin/storm supervisor

Step 3.6 Start the UI

$ bin/storm ui

在启动 Storm 用户界面应用程序后,在浏览器中输入 URL,你便可以看到 Storm 集群信息及其正在运行的拓扑。该页面应该与以下屏幕截图类似。

After starting Storm user interface application, type the URL http://localhost:8080 in your favorite browser and you could see Storm cluster information and its running topology. The page should look similar to the following screenshot.

storm ui