首页 文章 精选 留言 我的

精选列表

搜索[MaaS平台],共10000篇文章
优秀的个人博客,低调大师

RF Analyzer for Android 安卓平台连接HackRF的App

Over the last week I've been working on a new project, trying to build a spectrum analyzer for Android that works with my hackrf_android library. Now I finally reached the point were it is stable enough to be useful and I created the GitHub repository today: https://github.com/demantz/RFAnalyzer It is still very basic and I have a lot of ideas to extend its functionality, but I thought it's better to have testers involved as early as possible. Eventually it should evolve in something similar to GQRX, supporting different modes and devices. But that will take some time! The new version of RF Analyzer (1.07) has now support for AM/FM demodulation! It is now also available on Google Play: See the readme on GitHub for a more detailed description! RF Analyzer running on a Nexus 5 In this blog I'm going to show what you can do with the app and in the end I explain how it is working internally for those who like to play with the source code. I also tried to document the code as good as possible, but it is always easier if the basic flow of the program is explained before looking at it. What you can do with it Right now there aren't many fancy features. The app will present you with a simple UI showing the frequency spectrum including a waterfall plot. Here is a list of what you can do right now with version 1.00: Browse the spectrum by scrolling horizontally Zoom in and out, both horizontally and vertically Adjust the sample rate and center frequency to match the current view of the screen by double tapping Auto scale the vertical axis Jump directly to a frequency Adjust the gain settings of the HackRF Select a pre-recorded file as source instead of a real HackRF Change the FFT size Setting the frame rate either to a fixed value or to automatic control Activate logging and showing the log file I'm planning to also support the rtl-sdr in the future and of course I want to include the actual demodulation for common analog modes like AM, FM, SSB, ... But so far you can only browse the spectrum. Here is how you get it to work: Plug the HackRF into your Android device using an OTG (on-the-go) cable. You can get those cables for around 3$ and you can also find them as Y-version which enables external powering the HackRF, for those phones/tablets that don't deliver enough power. After you start RF Analyzer you can hit the start button in the action bar and it should prompt you for the permission to access the USB device. Once you did that the FFT will start: FFT at 20 Msps showing FLEX pagers at 931 MHz Use common gestures to zoom and scroll both vertically and horizontally. Note that the vertical axis of the FFT plot also affects the colors of the waterfall plot: Zoomed in(both vertical and horizontal)view If you scroll outside the current range of the FFT or if you zoom so that the resolution of the FFT is too low you can simply double tap the screen. RF Analyzer will re-tune the HackRF to the frequency currently centered on the screen and also ajust the sample rate so that the FFT covers exactly the frequency range that is currently visible: The resolution of the FFT is too low when zoomed in too closely. And we scrolled to far right that we can see the end of the FFT on the right site After double tapping the HackRF is tuned to 931,61 MHz (note the DC offset peak!) and the sample rate is now adjusted to about 2.5 Msps so that we see the full FFT resolution again You can also use the autoscale button in the action bar to adjust the vertical scale so that it ranges from the minimum to the maximum of the currently visible values of the FFT: If you want to jump to a certain frequency, use the 'set frequency' button and it will prompt you to enter a new frequency: The gain settings of the HackRF (both VGA and LNA gain) can be accessed through the 'set gain' button in the overflow menu: In the settings activity you can: Select other source types (currently only HackRF or file source) Set the FFT size Set the screen orientation (auto / landscape / portrait) Turn autostart on and off (so that you don't have to hit the start button every time) Set the frame rate to auto or a fixed value (useful if you want a linear time axis in the waterfall plot) Deactivate vertical zoom and scrolling (so that you don't accidentally alter the vertical scale while scrolling through frequencies) Turn on logging and set the location of the log file. Show the log file Settings Activity of RF Analyzer on a Nexus 7 Implementing the file source was helpful for debugging the application. It is also a way to test the app if you don't have an OTG cable or your phone/tablet doesn't output enough power for the HackRF. Selecting the file source type will allow you to use RF Analyzer with recorded samples from hackrf_transfer or Test_HackRF. I've uploaded a short capture of some FLEX pager signals for testing:FLEX Pager at 931MHz (2Msps) How it works For those who want to play with the sources of RF Analyzer (GPLv2) I want to quickly explain the internal structure of the app: (Uncomplete) class diagram of RF Analyzer. Underlined classes are running in seperate threads. Gray elements are external modules. To support different devices I defined a common interface that is implemented by all classes which represent sources of IQ samples. The Scheduler will continuously read samples from the source to prevent the receive buffers of the device to fill up. It forwards samples in packets of the size of the FFT to the AnalyzerProcessingLoop by inserting them in a queue. If the queue is full, the samples are thrown away in order to not block the input device. The AnalyzerProcessingLoop also runs in a separate thread and reads the sample packets from the queue, processes them with the help of the FFT class and then calls draw() on the AnalyzerSurface. This method draws the given FFT samples on a SurfaceView and also draws a new line of the waterfall plot as well as the horizontal and vertical axis. For a more detailed impression of how the app works, have a look into the sources onGitHub. I tried my best to add helpful comments to understand the flow of the program. If you have any questions, comments or any other input, don't hesitate to leave a comment or contact me directly on Twitter:@dennismantz Have fun testing it! ;) Here is the video were I demonstrate the old version of RF Analyzer: 原文地址:http://tech.mantz-it.com/2014/10/rf-analyzer-explore-frequency-spectrum.html 本文转自 K1two2 博客园博客,原文链接: http://www.cnblogs.com/k1two2/p/5705149.html ,如需转载请自行联系原作者

优秀的个人博客,低调大师

【物联网中间件平台-03】YFIOs安装指南

1 YFIOs简介 YFIOs就是YFSoft I/O Server的简称,在物联网、云计算时代,一切以数据为中心,不同的传感器通过不同的方式接入网络,通过云计算的方式为不同的终端用户提供服务。 为了适应这种新形势的发展,加速和降低各种传感器、智能模块的入网代价,以微软成熟的.NET Micro Framework系统为基础,打造出物联网时代的轻量级嵌入式组态系统 ——YFIOs。 详情请参见《YFIOs技术白皮书》。 2 YFIOs安装步骤 2.1下载链接 下载链接:http://www.sky-walker.com.cn/MFRelease/YFIOs/YFIOsSDK.rar(目前仅光盘方式提供) 解压后的文件结构如下: 进入Setup目录双击运行setup.exe即可。 2.2系统安装 YFIOs SDK安装前提必须是,当前Windows系统已经安装Visual Studio 2010 和 .NET Micro Framework 4.2 QFE。 否则安装会提示相关的系统没有安装,从而导致YFIOs SDK安装失败。 (1)、安装Visual Studio 2010 Express .NET Micro Framework支持Visual Studio 2010 Expres版本,这是一款免费的开发工具,不过建议有条件的用户,优先考虑安装专业版或企业版。 Visual Studio 2010 Express的下载地址如下: http://www.microsoft.com/express/download/ (2)、安装.NET Micro Framework 4.2 QFE2 SDK http://netmf.codeplex.com/downloads/get/470705 2.2.1安装向导 如果系统已经安装Visual Studio 2010 和 .NET Micro Framework 4.2 QFE,双击Setup.exe文件后,则会出现如下安装界面: 单击下一步,进行目录选择。 2.2.2 选择安装文件夹 可以安装在默认目录,也可以任选一个目录进行安装。 选择好目录后,则单击下一步按钮,进入确认安装界面。 2.2.3 确认安装 2.2.4 正在安装YFIOs 进入这个界面后,如果是Vista或Win7系统,等待一段时间后会弹出一个用户账户控制对话框,询问是否安装,单击确认按钮,则开始安装YFIOs。 安装达到这个进度的时候,会等待比较长的一段时间,因为Visual Studio 2010安装模板的时间比较长(大概3~5分钟)。进度条100%以后,会自动进入下一个安装界面。 2.2.5 安装完成 3 YFIOs安装内容 3.1快捷方式 桌面快捷方式: 开始菜单快捷方式: 安装后,会在桌面和主菜单中出现上图所示的快捷方式。 3.2文档和示例 安装后,YFIOs目录会有如下几个子目录: (1)、Assemblies - YFIOs核心接口程序集 YFSoft.IOI.dll,安装程序会自动注册到.NET Micro Framework V4.2系统中去。 (2)、Document –YFIOs开发文档。 (3)、Sample –驱动和策略开发示例,包含一套完整的紫藤207驱动源代码 (4)、YFIOsLib - YFIOs核心库,驱动和策略在线调试的时候需要引用。 (5)、YFIOsManager –YFIOs管理程序。 (6)、reame.txt–YFIOs说明。 3.3 Visual Studio 2010开发模板 安装完开发包后,新建项目中就如出现YFIOs Driver和YFIOs Startegy选项。 4相关资源 1、.NET Micro Framework 官方网址 http://www.microsoft.com/netmf/default.mspx 2、.NET Micro Framework官方博客 http://blogs.msdn.com/netmfteam/ 3、中文博客 http://blog.csdn.net/yefanqiu http://www.cnblogs.com/yefanqiu 4、叶帆科技 http://www.sky-walker.com.cn/ 5、物联网中间件技术开发论坛 http://www.yfios.net YFIOs/YFHMI免费试用 从2012-12-21起YFIOs和YFHMI将开展为期半年的免费试用活动,符合申请条件的用户,将依次获取YFIOs和YFHMI的试用机会。 申请表下载:http://sky-walker.com.cn/MFRelease/document/yfios_yfhmi_application.doc 本文转自yefanqiu51CTO博客,原文链接:http://blog.51cto.com/yfsoft/1108711,如需转载请自行联系原作者

优秀的个人博客,低调大师

ELK(elasticsearch+logstash+kibana)开源日志分析平台搭建

环境介绍 System: CentOS7.2 x86_64 hostname:elk-server.huangming.org IP Address: 10.0.6.42、10.17.83.42 本篇的ELK环境为单机部署方式,即将ELK所有的软件包都安装在一台服务器上,配置如下: CPU: 4c Mem: 8G Disk: 50 一、Elasticsearch安装 1、安装jdk 1.8及以上的版本(安装过程略) 1 2 3 4 [root@elk-serverelk] #java-version javaversion "1.8.0_65" Java(TM)SERuntimeEnvironment(build1.8.0_65-b17) JavaHotSpot(TM)64-BitServerVM(build25.65-b01,mixedmode) 2、下载Elasticsearch最新版本(目前5.5版本) 1 2 3 4 使用curl命令下载 tar 包 #curl-L-Ohttps://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.2.tar.gz 也可以使用wget命令下载 #wgethttps://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.2.tar.gz 3、解压至指定目录(安装目录)/usr/local/下,并将其重命名为elasticsearch (完整的目录应该为/usr/local/elasticsearch) 1 2 3 #tar-zxfelasticsearch-5.5.2.tar.gz-C/usr/local/ #cd/usr/local/ #mvelasticsearch-5.5.2elasticsearch 2、创建一个用于运行elasticsearch的普通用户,随后修改elasticsearch家目录的所属权限为该用户;创建elasticsearch数据存储目录/data/elasticsearch 1 2 3 4 5 #groupaddelasticsearch #useradd-gelasticsearchelasticsearch-m #chown-Relasticsearch./usr/local/elasticsearch #mkdir/data/elasticsearch #chown-Relasticsearch./data/elasticsearch 2、修改elasticsearch.yml配置文件 1 2 3 4 5 6 #vimconfig/elasticsearch.yml cluster.name:my-application #ELK集群名称 path.data: /data/elasticsearch #elasticsearch数据存储目录 path.logs: /usr/local/elasticsearch/logs #elasticsearch日志存储路径 network.host:10.17.83.42 #elasticsearch监听地址,默认为localhost http.port:9200 #elasticsearch监听端口,默认问9200 6、修改相关的内核参数 #打开/etc/security/limits.conf文件,添加以下参数 1 2 3 4 *softnproc2048 *hardnproc16384 *softnofile65536 *hardnofile65536 #修改vm.max_map_count=262144 1 #echo"/etc/sysctl.conf">>/etc/sysctl.conf 7、运行elasticsearch (注意:要切换到普通用户运行) # su - elasticsearch $ ./bin/elasticsearch 运行elasticsearch 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 [elasticsearch@elk-server~]$ cd /usr/local/elasticsearch/ [elasticsearch@elk-serverelasticsearch]$. /bin/elasticsearch [2017-08-28T14:51:31,069][INFO][o.e.n.Node][]initializing... [2017-08-28T14:51:31,186][INFO][o.e.e.NodeEnvironment][6eN59Pf]using[1]datapaths,mounts[[/(rootfs)]],netusable_space[89.4gb],nettotal_space[91.4gb],spins?[unknown],types[rootfs] [2017-08-28T14:51:31,187][INFO][o.e.e.NodeEnvironment][6eN59Pf]heapsize[1.9gb],compressedordinaryobjectpointers[ true ] [2017-08-28T14:51:31,188][INFO][o.e.n.Node]nodename[6eN59Pf]derivedfromnodeID[6eN59PfuS7iVRfoEppsngg]; set [node.name]tooverride [2017-08-28T14:51:31,189][INFO][o.e.n.Node]version[5.5.2],pid[2759],build[b2f0c09 /2017-08-14T12 :33:14.154Z],OS[Linux /3 .10.0-327.el7.x86_64 /amd64 ],JVM[OracleCorporation /Java HotSpot(TM)64-BitServerVM /1 .8.0_65 /25 .65-b01] [2017-08-28T14:51:31,189][INFO][o.e.n.Node]JVMarguments[-Xms2g,-Xmx2g,-XX:+UseConcMarkSweepGC,-XX:CMSInitiatingOccupancyFraction=75,-XX:+UseCMSInitiatingOccupancyOnly,-XX:+AlwaysPreTouch,-Xss1m,-Djava.awt.headless= true ,-Dfile.encoding=UTF-8,-Djna.nosys= true ,-Djdk.io.permissionsUseCanonicalPath= true ,-Dio.netty.noUnsafe= true ,-Dio.netty.noKeySetOptimization= true ,-Dio.netty.recycler.maxCapacityPerThread=0,-Dlog4j.shutdownHookEnabled= false ,-Dlog4j2.disable.jmx= true ,-Dlog4j.skipJansi= true ,-XX:+HeapDumpOnOutOfMemoryError,-Des.path.home= /usr/local/elasticsearch ] [2017-08-28T14:51:32,174][INFO][o.e.p.PluginsService][6eN59Pf]loadedmodule[aggs-matrix-stats] [2017-08-28T14:51:32,174][INFO][o.e.p.PluginsService][6eN59Pf]loadedmodule[ingest-common] [2017-08-28T14:51:32,175][INFO][o.e.p.PluginsService][6eN59Pf]loadedmodule[lang-expression] [2017-08-28T14:51:32,175][INFO][o.e.p.PluginsService][6eN59Pf]loadedmodule[lang-groovy] [2017-08-28T14:51:32,175][INFO][o.e.p.PluginsService][6eN59Pf]loadedmodule[lang-mustache] [2017-08-28T14:51:32,175][INFO][o.e.p.PluginsService][6eN59Pf]loadedmodule[lang-painless] [2017-08-28T14:51:32,175][INFO][o.e.p.PluginsService][6eN59Pf]loadedmodule[parent- join ] [2017-08-28T14:51:32,175][INFO][o.e.p.PluginsService][6eN59Pf]loadedmodule[percolator] [2017-08-28T14:51:32,175][INFO][o.e.p.PluginsService][6eN59Pf]loadedmodule[reindex] [2017-08-28T14:51:32,176][INFO][o.e.p.PluginsService][6eN59Pf]loadedmodule[transport-netty3] [2017-08-28T14:51:32,176][INFO][o.e.p.PluginsService][6eN59Pf]loadedmodule[transport-netty4] [2017-08-28T14:51:32,176][INFO][o.e.p.PluginsService][6eN59Pf]nopluginsloaded [2017-08-28T14:51:33,991][INFO][o.e.d.DiscoveryModule][6eN59Pf]usingdiscovery type [zen] [2017-08-28T14:51:34,576][INFO][o.e.n.Node]initialized [2017-08-28T14:51:34,577][INFO][o.e.n.Node][6eN59Pf]starting... [2017-08-28T14:51:34,814][INFO][o.e.t.TransportService][6eN59Pf]publish_address{10.17.83.42:9300},bound_addresses{10.17.83.42:9300} [2017-08-28T14:51:34,826][INFO][o.e.b.BootstrapChecks][6eN59Pf]boundorpublishingtoanon-loopbackornon-link- local address,enforcingbootstrapchecks [2017-08-28T14:51:37,883][INFO][o.e.c.s.ClusterService][6eN59Pf]new_master{6eN59Pf}{6eN59PfuS7iVRfoEppsngg}{hs82h4vkTwKCEvKybCodbw}{10.17.83.42}{10.17.83.42:9300},reason:zen-disco-elected-as-master([0]nodesjoined) [2017-08-28T14:51:37,900][INFO][o.e.h.n.Netty4HttpServerTransport][6eN59Pf]publish_address{10.17.83.42:9200},bound_addresses{10.17.83.42:9200} [2017-08-28T14:51:37,900][INFO][o.e.n.Node][6eN59Pf]started [2017-08-28T14:51:37,925][INFO][o.e.g.GatewayService][6eN59Pf]recovered[0]indicesintocluster_state [2017-08-28T14:51:43,485][INFO][o.e.c.m.MetaDataCreateIndexService][6eN59Pf][.kibana]creatingindex,cause[api],templates[],shards[1]/[1],mappings[_default_,index-pattern,server,visualization,search,timelion-sheet,config,dashboard,url] 一般情况我们要求elasticsearch在后台运行,使用命令如下: 1 $. /bin/elasticsearch -d 8、检查elasticsearch状态,如下则表示正常运行 1 2 3 4 5 6 7 8 9 10 11 12 13 14 [root@elk-serverelasticsearch] #curlhttp://10.17.83.42:9200 { "name" : "6eN59Pf" , "cluster_name" : "my-application" , "cluster_uuid" : "cKopwE1iTciIQAiFI6d8Gw" , "version" :{ "number" : "5.5.2" , "build_hash" : "b2f0c09" , "build_date" : "2017-08-14T12:33:14.154Z" , "build_snapshot" : false , "lucene_version" : "6.6.0" }, "tagline" : "YouKnow,forSearch" } 二、Logstash安装 1、下载logstash软件包 1 #wgethttps://artifacts.elastic.co/downloads/logstash/logstash-5.5.2.tar.gz 2、解压至指定安装目录 1 2 3 4 #tar-zxflogstash-5.5.2.tar.gz-C/usr/local/ #cd/usr/local/ #mvlogstash-5.5.2logstash 3、运行logstash # cd logstash/ # ./bin/logstash -e 'input { stdin { } } output { stdout {} }' 输入”hello world! ”,验证是否正常输出 1 2 3 4 5 6 7 8 9 10 11 12 [root@elk-serverlogstash] #./bin/logstash-e'input{stdin{}}output{stdout{}}' ERRORStatusLoggerNolog4j2configuration file found.Usingdefaultconfiguration:loggingonlyerrorstotheconsole. SendingLogstash'slogsto /usr/local/logstash/logs which isnowconfiguredvialog4j2.properties [2017-08-28T15:11:33,267][INFO][logstash.setting.writabledirectory]Creatingdirectory{:setting=> "path.queue" ,:path=> "/usr/local/logstash/data/queue" } [2017-08-28T15:11:33,273][INFO][logstash.setting.writabledirectory]Creatingdirectory{:setting=> "path.dead_letter_queue" ,:path=> "/usr/local/logstash/data/dead_letter_queue" } [2017-08-28T15:11:33,300][INFO][logstash.agent]NopersistentUUID file found.GeneratingnewUUID{:uuid=> "2fb479ab-0ca5-4979-89b1-4246df9a7472" ,:path=> "/usr/local/logstash/data/uuid" } [2017-08-28T15:11:33,438][INFO][logstash.pipeline]Startingpipeline{ "id" => "main" , "pipeline.workers" =>8, "pipeline.batch.size" =>125, "pipeline.batch.delay" =>5, "pipeline.max_inflight" =>1000} [2017-08-28T15:11:33,455][INFO][logstash.pipeline]Pipelinemainstarted Thestdinpluginisnowwaiting for input: [2017-08-28T15:11:33,497][INFO][logstash.agent]SuccessfullystartedLogstashAPIendpoint{:port=>9600} helloworld! 2017-08-28T07:11:42.724Zelk-server.huangming.orghelloworld! 三、Kibana安装 1、下载kibana 1 #wgethttps://artifacts.elastic.co/downloads/kibana/kibana-5.5.2-linux-x86_64.tar.gz 2、解压至安装目录 1 2 3 #tar-zxfkibana-5.5.2-linux-x86_64.tar.gz-C/usr/local/ #cd/usr/local/ #mvkibana-5.5.2-linux-x86_64kibana 3、修改配置 1 2 3 4 5 6 7 #cdkibana/ #vimconfig/kibana.yml server.port:5601 #监听端口 server.host: "10.17.83.42" #指定后端服务器 elasticsearch.url: "http://10.17.83.42:9200" #指定elasticsearch实例地址 4、运行kibana # ./bin/kibana & 1 2 3 4 5 6 7 8 9 10 [root@elk-serverkibana] #./bin/kibana& [1]3219 [root@elk-serverkibana] #log[07:26:02.496][info][status][plugin:kibana@5.5.2]Statuschangedfromuninitializedtogreen-Ready log[07:26:02.604][info][status][plugin:elasticsearch@5.5.2]Statuschangedfromuninitializedtoyellow-Waiting for Elasticsearch log[07:26:02.637][info][status][plugin:console@5.5.2]Statuschangedfromuninitializedtogreen-Ready log[07:26:02.682][info][status][plugin:metrics@5.5.2]Statuschangedfromuninitializedtogreen-Ready log[07:26:02.930][info][status][plugin:elasticsearch@5.5.2]Statuschangedfromyellowtogreen-Kibanaindexready log[07:26:02.932][info][status][plugin:timelion@5.5.2]Statuschangedfromuninitializedtogreen-Ready log[07:26:02.937][info][listening]Serverrunningathttp: //10 .17.83.42:5601 log[07:26:02.939][info][status][uisettings]Statuschangedfromuninitializedtogreen-Ready 5、验证kibana 在客户端浏览器打开http://10.17.83.42:5601 在该页面提示我们需要创建一个index 首先创建一个kinana默认的index(名称为.kibana),如果输入的index名不存在,则无法创建 查看运行状态及已安装的插件 至此ELK已经搭建完成了,下面来创建一个收集message系统日志的实例 本文转自 HMLinux 51CTO博客,原文链接:http://blog.51cto.com/7424593/1960254

优秀的个人博客,低调大师

使用python构建基于hadoop的mapreduce日志分析平台

出处:http://rfyiamcool.blog.51cto.com/1030776/1340057 流量比较大的日志要是直接写入Hadoop对Namenode负载过大,所以入库前合并,可以把各个节点的日志凑并成一个文件写入HDFS。 根据情况定期合成,写入到hdfs里面。 咱们看看日志的大小,200G的dns日志文件,我压缩到了18G,要是用awk perl当然也可以,但是处理速度肯定没有分布式那样的给力。 Hadoop Streaming原理 mapper和reducer会从标准输入中读取用户数据,一行一行处理后发送给标准输出。Streaming工具会创建MapReduce作业,发送给各个tasktracker,同时监控整个作业的执行过程。 任何语言,只要是方便接收标准输入输出就可以做mapreduce~ 再搞之前我们先简单测试下shell模拟mapreduce的性能速度~ 看下他的结果,350M的文件用时35秒左右。 这是2G的日志文件,居然用了3分钟。 当然和我写的脚本也有问题,我们是模拟mapreduce的方式,而不是调用shell下牛逼的awk,gawk处理。 awk的速度 !果然很霸道,处理日志的时候,我也很喜欢用awk,只是学习的难度有点大,不像别的shell组件那么灵活简单。 这是官方的提供的两个demo ~ map.py 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #!/usr/bin/env python "" "A more advanced Mapper, using Python iterators and generators." "" import sys def read_input(file): for line in file: # split the line into words yield line.split() def main(separator= '\t' ): # input comes from STDIN (standard input) data = read_input(sys.stdin) for words in data: # write the results to STDOUT (standard output); # what we output here will be the input for the # Reduce step, i.e. the input for reducer.py # # tab-delimited; the trivial word count is 1 for word in words: print '%s%s%d' % (word, separator, 1 ) if __name__ == "__main__" : main() reduce.py的修改方式 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #!/usr/bin/env python "" "A more advanced Reducer, using Python iterators and generators." "" from itertools import groupby from operator import itemgetter import sys def read_mapper_output(file, separator= '\t' ): for line in file: yield line.rstrip().split(separator, 1 ) def main(separator= '\t' ): # input comes from STDIN (standard input) data = read_mapper_output(sys.stdin, separator=separator) # groupby groups multiple word-count pairs by word, # and creates an iterator that returns consecutive keys and their group: # current_word - string containing a word (the key) # group - iterator yielding all [ "<current_word>" , "<count>" ] items for current_word, group in groupby(data, itemgetter( 0 )): try : total_count = sum( int (count) for current_word, count in group) print "%s%s%d" % (current_word, separator, total_count) except ValueError: # count was not a number, so silently discard this item pass if __name__ == "__main__" : main() 咱们再简单点: 1 2 3 4 5 6 7 #!/usr/bin/env python import sys for line in sys.stdin: line = line.strip() words = line.split() for word in words: print '%s\t%s' % (word, 1 ) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #!/usr/bin/env python from operator import itemgetter import sys current_word = None current_count = 0 word = None for line in sys.stdin: line = line.strip() word, count = line.split( '\t' , 1 ) try : count = int (count) except ValueError: continue if current_word == word: current_count += count else : if current_word: print '%s\t%s' % (current_word, current_count) current_count = count current_word = word if current_word == word: print '%s\t%s' % (current_word, current_count) 咱们就简单模拟下数据,跑个测试 剩下就没啥了,在hadoop集群环境下,运行hadoop的steaming.jar组件,加入mapreduce的脚本,指定输出就行了. 下面的例子我用的是shell的成分。 1 2 3 4 5 [root@ 101 cron]#$HADOOP_HOME/bin/hadoop jar $HADOOP_HOME/contrib/streaming/hadoop-*-streaming.jar \ -input myInputDirs \ -output myOutputDir \ -mapper cat \ -reducer wc 详细的参数,对于咱们来说提供性能可以把tasks的任务数增加下,根据情况自己测试下,也别太高了,增加负担。 (1)-input:输入文件路径 (2)-output:输出文件路径 (3)-mapper:用户自己写的mapper程序,可以是可执行文件或者脚本 (4)-reducer:用户自己写的reducer程序,可以是可执行文件或者脚本 (5)-file:打包文件到提交的作业中,可以是mapper或者reducer要用的输入文件,如配置文件,字典等。 (6)-partitioner:用户自定义的partitioner程序 (7)-combiner:用户自定义的combiner程序(必须用java实现) (8)-D:作业的一些属性(以前用的是-jonconf),具体有: 1)mapred.map.tasks:map task数目 2)mapred.reduce.tasks:reduce task数目 3)stream.map.input.field.separator/stream.map.output.field.separator: map task输入/输出数 据的分隔符,默认均为\t。 4)stream.num.map.output.key.fields:指定map task输出记录中key所占的域数目 5)stream.reduce.input.field.separator/stream.reduce.output.field.separator:reduce task输入/输出数据的分隔符,默认均为\t。 6)stream.num.reduce.output.key.fields:指定reduce task输出记录中key所占的域数目 这里是统计dns的日志文件有多少行 ~ 在mapreduce作为参数的时候,不能用太多太复杂的shell语言,他不懂的~ 可以写成shell文件的模式; 1 2 3 4 5 6 7 8 #! /bin/bash while read LINE; do # for word in $LINE # do # echo "$word 1" awk '{print $5}' done done 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #! /bin/bash count= 0 started= 0 word= "" while read LINE; do goodk=`echo $LINE | cut -d ' ' -f 1 ` if [ "x" == x "$goodk" ];then continue fi if [ "$word" != "$goodk" ];then [ $started -ne 0 ] && echo -e "$word\t$count" word=$goodk count= 1 started= 1 else count=$(( $count + 1 )) fi done 有时候会出现这样的问题,好好看看自己写的mapreduce程序 ~ 13/12/14 13:26:52 INFO streaming.StreamJob: Tracking URL: http://101.rui.com:50030/jobdetails.jsp?jobid=job_201312131904_0030 13/12/14 13:26:53 INFO streaming.StreamJob: map 0% reduce 0% 13/12/14 13:27:16 INFO streaming.StreamJob: map 100% reduce 100% 13/12/14 13:27:16 INFO streaming.StreamJob: To kill this job, run: 13/12/14 13:27:16 INFO streaming.StreamJob: /usr/local/hadoop/libexec/../bin/hadoop job -Dmapred.job.tracker=localhost:9001 -kill job_201312131904_0030 13/12/14 13:27:16 INFO streaming.StreamJob: Tracking URL: http://101.rui.com:50030/jobdetails.jsp?jobid=job_201312131904_0030 13/12/14 13:27:16 ERROR streaming.StreamJob: Job not successful. Error: # of failed Map Tasks exceeded allowed limit. FailedCount: 1. LastFailedTask: task_201312131904_0030_m_000000 13/12/14 13:27:16 INFO streaming.StreamJob: killJob... Streaming Command Failed! python做为mapreduce执行成功后,结果和日志一般是放在你指定的目录下的,结果是在part-00000文件里面~ 本文转自大角牛博客51CTO博客,原文链接http://blog.51cto.com/jingshengsun888/1341123如需转载请自行联系原作者 运维的戏子

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码