搭建Storm集群

来源:互联网 发布:socket服务端 java 编辑:程序博客网 时间:2024/05/16 13:52

1. 安装JDK (6 or later)

a) 下载源码,地址: http://www.oracle.com/technetwork/java/javase/downloads/index.html如:jdk-7u25-linux-x64.tar.gz, 由于下载前需要认证,所以wget方式可能下载失败,可以手动下载。

b) 解压文件

c) 配置环境变量

root@wangs:~# vim /etc/profile

#set java environment

export JAVA_HOME=/your_java_dir/jdk1.7.0_25

export JRE_HOME=/your_java_dir/jdk1.7.0_25/jre

export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH

export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

 

root@wangs:~# chmod +x /your_java_dir/jdk1.7.0_25/bin/* #使可执行

root@wangs:~# source /etc/profile   #使添加的环境变量立即生效

root@wangs:~# java -version   #验证是否安装成功

 

2. 安装Storm

a) 下载Storm的release 版本,地址:http://storm-project.net/downloads.html

b) 解压,并且把bin/目录添加到环境变量

export STORM_HOME=/your_storm_dir/storm-0.8.2

export PATH=$PATH:$STORM_HOME/bin

 

3. 安装leiningen

执行storm-0.8.2/bin/目录下的lein脚本

 

4. 安装 ZeroMQ

根据storm-0.8.2/bin/目录下的install_zmq.sh文件来安装

#install zeromq

wget http://download.zeromq.org/zeromq-2.1.7.tar.gz

tar -xzf zeromq-2.1.7.tar.gz

cd zeromq-2.1.7

./configure #可能缺少gcc g++ uuid-dev,apt-get install 安装即可

make

sudo make install


5. 安装JZMQ

根据storm-0.8.2/bin/目录下的install_zmq.sh文件来安装

#install jzmq (both native and into local maven cache)

git clone https://github.com/nathanmarz/jzmq.git    #先安装git-core

cd jzmq

./autogen.sh   #执行后会列出需要哪些依赖:pkg-configlibtool autoconf automake,安装依赖后再执行一次此脚本。

   ./configure

make

Sudo make install


6. 搭建Zookeeper集群

a) 软件包下载地址: http://mirror.bit.edu.cn/apache/zookeeper/

b) 配置环境变量

export ZOOKEEPER_HOME=/your_zookeeper_dir/zookeeper-3.4.5

export PATH=$PATH:$ZOOKEEPER_HOME/bin   

c) 配置文件

mv zoo_sample.cfg zoo.cfg  #将zookeeper-3.4.5/conf目录下面的zoo_sample.cfg修改为zoo.cfg

vim zoo.cfg #内容如下

# The number of milliseconds of each tick

tickTime=2000

# The number of ticks that the initial

# synchronization phase can take

initLimit=10

# The number of ticks that can passbetween

# sending a request and getting anacknowledgement

syncLimit=5

# the directory where the snapshot isstored.

# do not use /tmp for storage, /tmp hereis just

# example sakes.

dataDir=/var/zookeeper

# the port at which the clients willconnect

clientPort=2181

#

# Be sure to read the maintenance sectionof the

# administrator guide before turning onautopurge.

#

#

http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance

#

# The number of snapshots to retain indataDir

#autopurge.snapRetainCount=3

# Purge task interval in hours

# Set to "0" to disable autopurge feature

#autopurge.purgeInterval=1

server.1=10.7.201.15:2888:3888

server.2=10.7.201.16:2888:3888

server.3=10.7.201.17:2888:3888

d) 设置myid

在我们配置的dataDir指定的目录下,创建一个myid文件,里面内容为一个数字,用来标识当前主机,conf/zoo.cfg文件中配置的server.X中X为什么数字,则myid文件中就输入这个数字,例如:

echo “1” > /var/zookeeper/myid

 

7. Storm-starter本地运行

我们运行Storm-starter项目中的wordCount,对于该类而言,如果没有传递参数,则本地运行,传递参数,则是集群运行。

lein deps  #获取所有的依赖包

lein compile #创建项目

lein uberjar #生成一个适合提交给storm集群的jar包

storm jar <打包后的jar包名>.jar storm.starter.WordCountTopology #本地运行

 

8. Storm-starter集群运行

a) 配置storm

vim  <storm的安装路径>/conf/storm.yaml

########### These MUST be filled in for a storm configuration

storm.zookeeper.servers:

    - "10.7.201.15"

    - "10.7.201.16"

    - "10.7.201.17"

storm.local.dir: "/mnt/storm"

#

nimbus.host: "10.7.201.17"

#

#

# ##### These may optionally be filled in:

#   

## List of custom serializations

# topology.kryo.register:

#     - org.mycompany.MyType

#     - org.mycompany.MyType2:org.mycompany.MyType2Serializer

#

## List of custom kryo decorators

# topology.kryo.decorators:

#     -org.mycompany.MyDecorator

#

## Locations of the drpc servers

# drpc.servers:

#     - "server1"

#     -"server2"

b) 启动服务

zkServer.sh start   #开启zookeeper服务,每台机器都需要开启

storm nimbus  #在nimbus主机上,开启nimbus进程

storm supervisor #在其他supervisor主机上,开启supervisor进程

jps #该命令可以查看各进程运行状态

1882 core      对应的进程是Storm UI

341 Jps       对应的进程是Java jps

1880 nimbus     对应的进程是Storm nimbus

18450 supervisor 对应的进程是Stormsupervisor

27380 worker      对应的线程是Storm main函数里面设置的conf.setNumWorkers(15)

2112 QuorumPeerMain 对应的进程是zkServer.sh

c) 运行wordCount

storm jar <打包后的jar包名>.jar storm.starter.WordCountTopology “hello word” #带参数,则会选择集群运行

d) 开启Web服务

storm ui #打开Storm Web UI,通过http://UI_Server_Ip:8080查看storm集群的状态
原创粉丝点击