当前位置: 首页 > news >正文

NiFi 在Raspberry Pi安装运行实践

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

在树莓派上面运行NiFi的几个月折腾经验总结。

概述

Raspberry Pi is an interesting little machine. Even more so with the release of the Raspberry Pi 3. While it may not technically be the most powerful device in this form-factor, it definitely wins on overall community, breadth of support and stability. Naturally, there is sizable interest in running something like NiFi on this little edge device. And that's exactly what we have been doing for the past 8 months (as of May 2016). Today I'd like to share a set of best practices for running NiFi on the Pi that came out of this exercise.

In general, recommendations fall into 2 categories:

  1. Raspberry Pi configuration – OS, system-level settings for running an always-on NiFi instance.
  2. NiFi configuration – tweaks and changes within NiFi itself

Let’s start with some prep work.

Raspberry Pi 配置

I’m assuming the Raspberry Pi is fully under one’s control, including physical access to SD card and USB slots, together with a root account.

SD Card

If you bought a starter kit, it probably came with the NOOBS image pre-installed on the SD card. It’s fine for all kinds of projects, but running things 24x7 changes things. Double-check the manufacturer and use a brand-name SD card like SanDisk. Unfortunately, those other brands in starter kits tend to corrupt much more often, and this is not what you want for an always-on service. Go for a faster SD card. E.g. look for those cards having the 4K video designation and 90 MB/s sustained write speed or better. Your Pi will thank you.

使用 Raspbian OS Lite

Raspberry Pi default OS image has lots of stuff. All great, but absolutely useless and a waste if you never intend to run it in a desktop mode. Instead, take your SD card and re-image it with the lightweight version of the OS (Raspbian Jessie Lite at the time of writing). It drops all desktop software, giving you more space to do what’s important (i.e. running NiFi 24x7!). This is a standard procedure which is well documented at https://www.raspberrypi.org/documentation/installation/installing-images/

 

升级OS软件包

One is encouraged to upgrade the OS to pick up any maintenance releases since the OS image was published:

sudo apt-get update && sudo apt-get dist-upgrade

Go have a coffee or make a sandwich.

Note on Initial Setup

Of course, there is this little chicken-and-egg problem of having to connect your typical desktop monitor and keyboard first to go through an initial boot and configuration. One has 3 options:

  1. Plug in an Ethernet cable and access over SSH. You may need to have access to a router or basic network scanning utility to find Pi's address. @Jim Heaton has more tips in the comment section below. Thanks!
  2. Connect a monitor and keyboard and configure WiFi, start up the SSH daemon and set your Pi free.
  3. Hardcore, but lots of fun - connect directly to a serial console over TX/RX/GND wire combination. Finally a good use for that array of GPIO connectors!. You can either buy one of those USB-to-TTL cables or leverage e.g. a BusPirate device if you have one. If above makes sense, you probably can find your way from here, but let me know if you’re interested in knowing more. I can only mention that it saved me so many times even in a disk full, SSH daemon down, SD card corrupted situation (or a combination of all).

 

Expand the Root Filesystem

Once the lightweight OS has been put on the SD card and Raspberry Pi boots up, there’s one thing often overlooked. The default root partition is around 1.2GB and it will get full eventually. It’s very tedious then to clean up the space, as there is no obvious single large file one could delete to reclaim the space. Instead, use all that SD card (remember NiFi will be running on another mount anyway).

Login into your Pi and run:

 
  1. sudo raspi-config

Select option #1 - Expand Filesystem. The system will expand the root partition to use available SD card space and reboot.

 

Configure OS Locale and Timezone

This is optional, but really not if you plan to collect any interesting data and still make sense of it during analysis. While in the same raspi-config screen, select option #5 Internationalization and update your Pi’s Locale and Timezone.

 

External Storage

If you can, consider external storage for hosting everything NiFi (I.e. not on the same SD card where your OS lives). One can go as far as plugging in a huge external drive (hey, no problem, just ensure it has its own power supply!) into a USB port. But we found a common USB flash drive (or multiple) to be a suitable medium, too. They seem to be less prone to corruption than the SD card, just go with the brand name and opt for higher-speed models whenever you can.

Configure USB Mounts

I will not repeat the internet, there are plenty of guides on how to do it for the Pi. One super-useful tip is to mount by a UUID of the flash drive, which guarantees the mount bindings will persist no matter which USB port one plugs it in. Gives the warm and fuzzy, which we all love. Here’s my favorite guide: http://www.raspberrypi-spy.co.uk/2014/05/how-to-mount-a-usb-flash-disk-on-the-raspberry-pi/ . Use either UUDI or a drive label, just don't use the actual device name, as it can change when you reconfigure the disks.

 

Disable Access Times Recording

Additionally, modify the mounts for the SD card and USB flash drives to disable access times recording for files and directories. This minimizes unnecessary writes to the SD card and flash drives:

 
  1. sudo vi /etc/fstab
  2. # modify the options for a mount to add ‘noatime,nodiratime’
  3. # save changes
  4.  
  5. # repeat for every mount point which you updated above, example for root below
  6. sudo mount -o remount /
  7.  
  8.  
  9. # to verify changes - look for your settings in the output
  10. mount

E.g. here’s how my fstab looks like with an SD card and 2 USB flash drives:

 
  1. proc /proc proc defaults 0 0
  2. /dev/mmcblk0p1 /boot vfat defaults 0 2
  3. /dev/mmcblk0p2 / ext4 defaults,noatime 0 1
  4.  
  5.  
  6. LABEL=USBFLASH1 /mnt/flash1 ext4 defaults,noatime,nodiratime,nofail 0
  7. LABEL=USBFLASH2 /mnt/flash2 ext4 defaults,noatime,nodiratime,nofail 0

 

 

Update: a more robust fstab options string. If your Pi is hanging on boot with auto-mounted drives, try add the nofail option.

Disable WiFi Power Saving

This is kinda critical and will bite you every time if you forget. By default, Raspberry Pi shuts down wifi after some inactivity period only to re-enable it when there’s an incoming connection. Great in theory. In practice, one is facing a 30-40 seconds delay when trying to access the Pi over SSH or hit a NiFi UI. The procedure is slightly different for Pi 2 & 3, I’m listing both here:

Raspberry Pi 2

Follow instructions at http://www.raspberrypi-spy.co.uk/2015/06/how-to-disable-wifi-power-saving-on-the-raspberry-pi/

Raspberry Pi 3

 
  1. sudo iw dev wlan0 set power_save off

 

Create a NiFi User Account

We will not be running NiFi from the SD card. Let’s ensure the home directory isn’t there either. Create a nifi user account and configure its home location to be on the new USB mount (e.g. if there is a /mnt/flash1):

 
  1. sudo useradd -m -d /mnt/flash1/nifi nifi
  2. sudo chmod 750 /mnt/flash1/nifi
  3.  
  4. # and here’s how one would log into the account
  5. # sudo su - nifi

 

Configure OS Kernel

Follow the https://nifi.apache.org/docs/nifi-docs/html/administration-guide.html#configuration-best-practices I, however, configure the limits for the nifi user alone, not for any account on the host. E.g. replace those star symbols with ‘nifi':

 
  1. nifi hard nofile 50000
  2. nifi soft nofile 50000
  3. nifi hard nproc 10000
  4. nifi soft nproc 10000

 

Install JDK

Java 8 is highly recommended. Largely because the PermGen space doesn’t require any special treatment, great for systems like NiFi.

Important: we had some reports of OpenJDK behaving less stable than Oracle JDK in the ARM build (this is what Pi is using). Save yourself some trouble, install Oracle JDK and move on:

 
  1. sudo apt-get update && sudo apt-get install oracle-java8-jdk

 

NiFi Configuration

NiFi installation is trivial, download from https://nifi.apache.org/download.html and unpack. Make sure to unpack in the nifi user home directory (e.g. /mnt/flash1/nifi)

 

Let’s Get Lean!

Before anything else, it’s important to remove modules which don’t make sense on Raspberry Pi. This will improve startup times considerably and reduce strain on the system. You have a final say of what goes and stays, but here’s e.g. the contents of my $NIFI_HOME/lib directory (you can delete all other NAR files):

 
  1. bootstrap
  2. jcl-over-slf4j-1.7.12.jar
  3. jul-to-slf4j-1.7.12.jar
  4. log4j-over-slf4j-1.7.12.jar
  5. logback-classic-1.1.3.jar
  6. logback-core-1.1.3.jar
  7. nifi-api-0.6.1.jar
  8. nifi-documentation-0.6.1.jar
  9. nifi-framework-nar-0.6.1.nar
  10. nifi-html-nar-0.6.1.nar
  11. nifi-http-context-map-nar-0.6.1.nar
  12. nifi-jetty-bundle-0.6.1.nar
  13. nifi-kerberos-iaa-providers-nar-0.6.1.nar
  14. nifi-ldap-iaa-providers-nar-0.6.1.nar
  15. nifi-nar-utils-0.6.1.jar
  16. nifi-properties-0.6.1.jar
  17. nifi-provenance-repository-nar-0.6.1.nar
  18. nifi-runtime-0.6.1.jar
  19. nifi-scripting-nar-0.6.1.nar
  20. nifi-ssl-context-service-nar-0.6.1.nar
  21. nifi-standard-nar-0.6.1.nar
  22. nifi-standard-services-api-nar-0.6.1.nar
  23. nifi-update-attribute-nar-0.6.1.nar
  24. slf4j-api-1.7.12.jar

 

Repositories Configuration

If you have multiple USB drives you can leverage striping for content and provenance repositories. This will improve overall throughput of NiFi.

For a great background and tuning tips see:

https://community.hortonworks.com/content/kbentry/7882/hdfnifi-best-practices-for-setting-up-a-high-perfo.html

Reference documentation for all properties is available at https://nifi.apache.org/docs/nifi-docs/html/administration-guide.html#system_properties

Tame Those Logs

NiFi can get pretty chatty about, well, everything. In an environment that is sensitive to random writes (like the Raspberry Pi) we are better off changing a few things. Edit the $NIFI_HOME/conf/logback.xml and introduce the following changes.

Only ERROR and above messages by default

 
  1. <root level="ERROR">
  2. <appender-ref ref="APP_FILE"/>
  3. </root>

NiFi packages at WARN and above (add one if missing)

 
  1. <logger name="org.apache.nifi" level="WARN"/>

Compress and roll daily logs for nifi-app.log

Find the appender section for nifi-app.log and modify the file pattern to read as below (note the .gz extension):

 
  1. <fileNamePattern>./logs/nifi-app_%d{yyyy-MM-dd_HH}.%i.log.gz</fileNamePattern>

Bonus tip: there’s no need to restart NiFi to pick up changes in the logging configuration. The file is checked for changes every 30 seconds and NiFi reconfigures logging on the fly.

 

Closing Thoughts

Once again, these are only a few tips which came through very useful while running NiFi on a Raspberry Pi. There are more tuning steps available based on the kind of data flowing through it, but hope this gets you started and provides sufficient guard rails. Let us know your thoughts!

转载于:https://my.oschina.net/u/2306127/blog/858994

相关文章:

  • svn变更自动触发jenkins构建工程-简单版
  • mockito static method wiki
  • HBuilder 学习笔记
  • Linux操作系统基础知识
  • 运维学习第三弹
  • Kubernetes Tutorials翻译4——Using a Service to Expose Your App
  • JavaScript 函数式编程
  • 企业云桌面-08-准备虚拟机-041-exsi01-042-exsi02-043-exsi03-044-exsi04
  • Cocos2dx源码赏析(3)之事件分发
  • SQL跨数据库复制表数据
  • opencv轮廓提取、轮廓识别相关要点
  • yii2: oracle汉字占用字节长度
  • jquery easy ui 验证框架
  • java生成验证码并可刷新
  • JS三大经典变量命名法
  • 【跃迁之路】【477天】刻意练习系列236(2018.05.28)
  • 2017前端实习生面试总结
  • ABAP的include关键字,Java的import, C的include和C4C ABSL 的import比较
  • Android交互
  • angular组件开发
  • Golang-长连接-状态推送
  • iOS小技巧之UIImagePickerController实现头像选择
  • java8-模拟hadoop
  • MySQL的数据类型
  • QQ浏览器x5内核的兼容性问题
  • Redis字符串类型内部编码剖析
  • 高程读书笔记 第六章 面向对象程序设计
  • 基于axios的vue插件,让http请求更简单
  • 基于webpack 的 vue 多页架构
  • 开年巨制!千人千面回放技术让你“看到”Flutter用户侧问题
  • 山寨一个 Promise
  • 深入体验bash on windows,在windows上搭建原生的linux开发环境,酷!
  • 通过git安装npm私有模块
  • 用Visual Studio开发以太坊智能合约
  • 阿里云服务器如何修改远程端口?
  • # Python csv、xlsx、json、二进制(MP3) 文件读写基本使用
  • (Java)【深基9.例1】选举学生会
  • (Matalb时序预测)WOA-BP鲸鱼算法优化BP神经网络的多维时序回归预测
  • (解决办法)ASP.NET导出Excel,打开时提示“您尝试打开文件'XXX.xls'的格式与文件扩展名指定文件不一致
  • (七)MySQL是如何将LRU链表的使用性能优化到极致的?
  • (亲测)设​置​m​y​e​c​l​i​p​s​e​打​开​默​认​工​作​空​间...
  • (十八)SpringBoot之发送QQ邮件
  • (十七)devops持续集成开发——使用jenkins流水线pipeline方式发布一个微服务项目
  • (源码版)2024美国大学生数学建模E题财产保险的可持续模型详解思路+具体代码季节性时序预测SARIMA天气预测建模
  • (转)mysql使用Navicat 导出和导入数据库
  • (状压dp)uva 10817 Headmaster's Headache
  • .CSS-hover 的解释
  • .NET CF命令行调试器MDbg入门(二) 设备模拟器
  • .Net CF下精确的计时器
  • .NET/C# 使窗口永不激活(No Activate 永不获得焦点)
  • .net开源工作流引擎ccflow表单数据返回值Pop分组模式和表格模式对比
  • .NET使用HttpClient以multipart/form-data形式post上传文件及其相关参数
  • /usr/local/nginx/logs/nginx.pid failed (2: No such file or directory)
  • @javax.ws.rs Webservice注解
  • [ vulhub漏洞复现篇 ] Celery <4.0 Redis未授权访问+Pickle反序列化利用