一步步搭环境:
----------------------------------------------------
系统环境要求:
Mac OS X 或者 Ubuntu14.04>=
1. Java环境配置
Linux java环境配置。因为heron用到Bazel管理工具的要求必须是JDK1.8版本,所以可以直接下JDK1.8进行安装。
JDK安装下载解压到/usr/local目录下,然后进行环境变量配置,有两个地方可以配置(/etc/profile(全局配置) 或者 ~/.bashrc(只针对某个用户)),打开文件,shift+g定位到文件末尾,添加如下语句
export JAVA_HOME=/usr/local/jdk export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar: export PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
为了使得更改立即生效,可以使用source命令
source /etc/profile #source ~/.bashrc
2. 下载脚本
可以去github上下载Twitter提供的heron安装脚本(https://github.com/twitter/heron/releases),可以下载自己系统对应的文件。
注:如果是Mac,脚本文件是带有darwin的,即heron-client-install-0.14.3-darwin.sh、heron-tools-install-0.14.3-darwin.sh 这样的文件。
heron的单节点运行主要用到2个脚本文件
heron-client-install-0.14.2-PLATFORM.sh
heron-tools-install-0.14.2-PLATFORM.sh
3. 安装
下载完成,可以使用 --user进行安装
若脚本没有执行权限,则先执行如下语句,其他脚本文件同理
$ chmod +x heron-client-install-0.14.3-ubuntu.sh
安装client
$ ./heron-client-install-0.14.3-ubuntu.sh --user Heron client installer ---------------------- Uncompressing...... Heron is now installed! Make sure you have "$/home/xxx/bin" in your path. ...
如果环境变量中没有 /home/xxx/bin 可以进行环境变量导入
$ export PATH=$PATH:~/bin
接下来安装 tool,依旧使用 --user
$ ./heron-tools-install-0.14.3- .sh --user Heron tools installer --------------------- Uncompressing...... Heron Tools is now installed! ...
可以使用如下语句检查heron是否安装成功
heron version
如果提示如下语句,提示JAVA_HOME没有设置:
root@vm-heron:~/bin# heron version ERROR:root:JAVA_HOME not set
可是明明环境变量已经设置,而且使用echo $PATH可以看到环境变量....
那就执行一次export将JAVA_HOME进行导入(终端关闭后,就不起作用了)
export JAVA_HOME=/usr/local/jdk
然后再执行,就可以成功
root@vm-heron:~$ heron version heron.build.version : '0.14.3' heron.build.time : Sat Sep 10 01:04:00 PDT 2016 heron.build.timestamp : 1473494660000 heron.build.host : tw-mbp-kramasamy heron.build.user : kramasamy heron.build.git.revision : 71d5b256d779be73b37c50d2a58af8f00d618276 heron.build.git.status : Clean
4. 部署运行
安装完成后,在~/.heron/example目录下会有一些Twitter的官方例子,可以使用heron的CLI工具在本地部署一个tolopogy。
$ heron submit local \ > ~/.heron/examples/heron-examples.jar \ > com.twitter.heron.examples.ExclamationTopology \ > ExclamationTopology \ > --deploy-deactivated INFO: Using config file under /home/${user}/.heron/conf/local INFO: Launching topology 'ExclamationTopology' INFO: Topology 'ExclamationTopology' launched successfully INFO: Elapsed time: 6.915s.
这个运行之后就会在家目录下产生一个 ./herondata的目录,此目录存放了之前运行的数据。可以看看其内容
$ ll ~/.herondata/topologies/local/${user}/ExclamationTopology -rw-rw-r-- 1 user user 2343 9月 18 16:14 ExclamationTopology.defn drwxr-xr-x 2 user user 4096 1月 1 1970 heron-conf/ drwxr-xr-x 4 user user 4096 1月 1 1970 heron-core/ -rwxr-xr-x 1 user user 4586211 1月 1 1970 heron-examples.jar* -rw-rw-r-- 1 user user 0 9月 18 16:14 heron-executor-0.stderr -rw-rw-r-- 1 user user 0 9月 18 16:14 heron-executor-1.stderr -rw-rw-r-- 1 user user 0 9月 18 16:14 java-a4298b50-started.stderr drwxrwxr-x 2 user user 4096 9月 18 16:14 log-files/ -r-xr-xr-x 1 user user 281 1月 1 1970 release.yaml*
5. 启动Heron Tracker
Heron Tracker是用来收集heron集群信息的web服务,可以通过运行heron-tracker来部署它。
$ heron-tracker INFO: 09/18/2016 16:35:05 +0000 Connecting to file state with rootpath: /home/${user}/.herondata/repository/state/local INFO: 09/18/2016 16:35:05 +0000 Tracker has started INFO: 09/18/2016 16:35:05 +0000 Running on port: 8888 INFO: 09/18/2016 16:35:05 +0000 Using config file: /home/${user}/.herontools/conf/heron_tracker.yaml INFO: 09/18/2016 16:35:05 +0000 State watch triggered for topologies. INFO: 09/18/2016 16:35:05 +0000 Adding new topology: ExclamationTopology, state_manager: local INFO: 09/18/2016 16:35:05 +0000 Registering a watch with uid: 53ccd3c3-f6d2-4d53-af11-c736a96986d3 INFO: 09/18/2016 16:35:05 +0000 No execution state found for: ExclamationTopology INFO: 09/18/2016 16:35:05 +0000 Watch triggered for topology execution state: ExclamationTopology INFO: 09/18/2016 16:35:05 +0000 Setting topology info for topology: ExclamationTopology INFO: 09/18/2016 16:35:05 +0000 Watch triggered for topology pplan: ExclamationTopology INFO: 09/18/2016 16:35:05 +0000 Setting topology info for topology: ExclamationTopology INFO: 09/18/2016 16:35:05 +0000 Watch triggered for topology tmaster: ExclamationTopology INFO: 09/18/2016 16:35:05 +0000 Setting topology info for topology: ExclamationTopology INFO: 09/18/2016 16:35:05 +0000 Watch triggered for topology scheduler location: ExclamationTopology INFO: 09/18/2016 16:35:05 +0000 Setting topology info for topology: ExclamationTopology INFO: 09/18/2016 16:36:31 +0000 302 GET / (127.0.0.1) 0.50ms INFO: 09/18/2016 16:36:31 +0000 200 GET /topologies (127.0.0.1) 0.71ms WARNING: 09/18/2016 16:36:32 +0000 404 GET /favicon.ico (127.0.0.1) 1.10ms WARNING: 09/18/2016 16:36:32 +0000 404 GET /favicon.ico (127.0.0.1) 0.49ms
执行中若是出现,没有权限错误,则把家目录下的 .pex目录权限改成当前用户
$ sudo chown -R ${user}:${user} ~/.pex/
然后在浏览器中输入http://localhost:8888/,即可看到如下内容
{"status": "success", "executiontime": 4.076957702636719e-05, "message": "", "version": "1.0.0", "result": {"local": {"${user}": {"default": ["ExclamationTopology"]}}}}
6. Heron UI使用
Heron UI 就是直观的用户界面了,通过它可以看tolopogy的详细运行情况,通过 heron-ui来部署启动
$ heron-ui INFO: 09/18/2016 16:47:24 +0000 Listening at http://0.0.0.0:8889 INFO: 09/18/2016 16:47:24 +0000 Using tracker url: http://localhost:8888
然后就可以在浏览器中输入http://localhost:8889/,就可以打开如下界面了。
注:上一步的heron-tracker也是必须在运行状态,长期运行可以使用守护进程启动,否则会出现[Errno 111] connected refused的异常。
7. tolopogy的几个常用命令
上面我们在本地环境提交了一个tolopogy,我们可以使用heron的CLI工具进行一些管理,如activate、deactivate、kill等。
$ heron activate local ExclamationTopology $ heron deactivate local ExclamationTopology $ heron kill local ExclamationTopolog
若果上面的命令执行成功,会有类似下面这样的提示信息:
INFO: Successfully activated topology 'ExclamationTopology' INFO: Elapsed time: 1.980s.
我们可以通过heron来查看有哪些命令可用
$ heron usage: heron... Available commands: activate Activate a topology deactivate Deactivate a topology help Prints help for commands kill Kill a topology restart Restart a topology submit Submit a topology version Print version of heron-cli Getting more help: heron help Prints help and options for For detailed documentation, go to http://heronstreaming.io
利用help命令查看如何提交一个tolopogy
$ heron help submit usage: heron submit [options] cluster/[role]/[env] topology-file-name topology-class-name [topology-args] Required arguments: cluster/[role]/[env] Cluster, role, and environment to run topology topology-file-name Topology jar/tar/zip file topology-class-name Topology class name Optional arguments: --config-path (a string; path to cluster config; default: "/home/${user}/.heron/conf") --config-property (key=value; a config key and its value; default: []) --deploy-deactivated (a boolean; default: "false") --extra-launch-classpath (a string; additional JVM class path for launching topology) --topology-main-jvm-property (property=value; JVM system property for executing topology main; default: []) --verbose (a boolean; default: "false")