热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

clouderasearch1.0.0环境搭建(2):利用flume-ng的MorphlineSolrSink实现近实时(NRT)搜索

要实现近实时搜索,就必须有一种机制来实时的处理数据然后生成到solr的索引中去,flume-ng刚好提供了这样一种机制,它可以实时收集数据,然后通过MorphlineSolrSink对数据进行ETL,

要实现近实时搜索,就必须有一种机制来实时的处理数据然后生成到solr的索引中去,flume-ng刚好提供了这样一种机制,它可以实时收集数据,然后通过MorphlineSolrSink对数据进行ETL,最后写入到solr的索引中,这样就能在solr搜索引擎中近实时的查询到新进来的数据了。

搭建步骤:

1 我们这里只做演示效果,所以新建了一个文件file01来保存了两条数据,后面将通过flume-ng avro-client -H localhost -p 44444 -F file01将这两条数据提交给flume agent。

这两条数据如下:

{"id": "1234567890", "user_friends_count": 111, "user_location": "Palo Alto", "user_description": "desc1", "user_statuses_count": 11111, "user_followers_count": 111, "user_name": "name1", "user_screen_name": "fake_user1", "created_at": "1985-09-04T18:01:01Z", "text": "sample tweet one", "retweet_count": 0, "retweeted": false, "in_reply_to_user_id": 0, "source": "href=\"http:\/\/sample.com\"", "in_reply_to_status_id": 0, "media_url_https": null, "expanded_url": null}
{"id": "2345678901", "user_friends_count": 222, "user_location": "San Francisco", "user_description": "desc2", "user_statuses_count": 222222, "user_followers_count": 222, "user_name": "name2", "user_screen_name": "fake_user2", "created_at": "1985-09-04T19:14:34Z", "text": "sample tweet two", "retweet_count": 0, "retweeted": false, "in_reply_to_user_id": 0, "source": "href=\"http:\/\/sample.com\"", "in_reply_to_status_id": 0, "media_url_https": null, "expanded_url": null}

是两条JSON数据,后面我们会用morphlines来对json数据进行ETL抽取指定的几个字段。

2 在CM中flume的配置中配置Flume-NG Solr 接收器,如下图:

morphlines配置文件如下:

[plain] view plain copy 在CODE上查看代码片派生到我的代码片
  1. # Specify server locations in a SOLR_LOCATOR variable; used later in   
  2. # variable substitutions:  
  3. SOLR_LOCATOR : {  
  4.   # Name of solr collection  
  5.   collection : collection1  
  6.     
  7.   # ZooKeeper ensemble  
  8.   zkHost : "master68:2181,slave69:2181,slave76:2181/solr"    
  9. }  
  10.   
  11. # Specify an array of one or more morphlines, each of which defines an ETL   
  12. # transformation chain. A morphline consists of one or more potentially   
  13. # nested commands. A morphline is a way to consume records such as Flume events,   
  14. # HDFS files or blocks, turn them into a stream of records, and pipe the stream   
  15. # of records through a set of easily configurable transformations on its way to   
  16. # Solr.  
  17. morphlines : [  
  18.   {  
  19.     # Name used to identify a morphline. For example, used if there are multiple   
  20.     # morphlines in a morphline config file.  
  21.     id : morphline1   
  22.       
  23.     # Import all morphline commands in these java packages and their subpackages.  
  24.     # Other commands that may be present on the classpath are not visible to this  
  25.     # morphline.  
  26.     importCommands : ["org.kitesdk.**", "org.apache.solr.**"]  
  27.       
  28.     commands : [                      
  29.       {  
  30.         readJson {}  
  31.       }  
  32.       {   
  33.         extractJsonPaths {  
  34.           flatten : false  
  35.           paths : {   
  36.             id : /id              
  37.             user_name : /user_screen_name  
  38.             created_at : /created_at  
  39.             text : /text        
  40.           }  
  41.         }  
  42.       }  
  43.         
  44.       # Consume the output record of the previous command and pipe another  
  45.       # record downstream.  
  46.       #  
  47.       # convert timestamp field to native Solr timestamp format  
  48.       # such as 2012-09-06T07:14:34Z to 2012-09-06T07:14:34.000Z  
  49.       {  
  50.         convertTimestamp {  
  51.           field : created_at  
  52.           inputFormats : ["yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd"]  
  53.           inputTimezone : America/Los_Angeles  
  54.           outputFormat : "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"                                   
  55.           outputTimezone : UTC  
  56.         }  
  57.       }  
  58.         
  59.       # Consume the output record of the previous command and pipe another  
  60.       # record downstream.  
  61.       #  
  62.       # This command deletes record fields that are unknown to Solr   
  63.       # schema.xml.  
  64.       #  
  65.       # Recall that Solr throws an exception on any attempt to load a document   
  66.       # that contains a field that is not specified in schema.xml.  
  67.       {  
  68.         sanitizeUnknownSolrFields {  
  69.           # Location from which to fetch Solr schema  
  70.           solrLocator : ${SOLR_LOCATOR}  
  71.         }  
  72.       }    
  73.               
  74.       # log the record at DEBUG level to SLF4J  
  75.       { logDebug { format : "output record: {}", args : ["@{}"] } }      
  76.         
  77.       # load the record into a Solr server or MapReduce Reducer  
  78.       {   
  79.         loadSolr {  
  80.           solrLocator : ${SOLR_LOCATOR}  
  81.         }  
  82.       }  
  83.     ]  
  84.   }  
  85. ]  

简单解释一下这个morphlines配置文件,首先执行了一个readJson命令,将读入的event的内容转换成了一个json对象,然后使用extractJsonPaths命令抽取json对象的具体字段值并重新赋值给另一个字段(例如user_name : /user_screen_name 是读取user_screen_name的值并赋值给user_name ),然后使用convertTimestamp对create_at字段进行格式化,最后执行sanitizeUnknownSolrFields命令舍弃solr的schema中没有配置的field字段,即通过ETL之后record最终只保留solr中已配置的字段。然后通过loadSolr指令将最终的record提交到solr。

3 接下来就是flume agent的配置:

[plain] view plain copy 在CODE上查看代码片派生到我的代码片
  1. tier1.sources=source1  
  2. tier1.channels=channel1  
  3. tier1.sinks=sink1  
  4.   
  5. tier1.sources.source1.type = avro  
  6. tier1.sources.source1.bind = 0.0.0.0  
  7. tier1.sources.source1.port = 44444  
  8. tier1.sources.source1.channels=channel1  
  9.   
  10. tier1.channels.channel1.type=memory  
  11. tier1.channels.channel1.capacity=10000  
  12.   
  13. tier1.sinks.sink1.type = org.apache.flume.sink.solr.morphline.MorphlineSolrSink  
  14. tier1.sinks.sink1.channel = channel1  
  15. tier1.sinks.sink1.morphlineFile = morphlines.conf  
  16. tier1.sinks.sink1.morphlineId = morphline1  

这里一个注意点就是我们在CM中配置的Flume-NG Solr 接收器,所以morphlineFile直接写morphlines.conf就行了,否则需要写绝对路径,不然没法找到morphlines的配置文件。

4 上面三部准备好之后,启动agent,然后在shell控制台执行 flume-ng avro-client -H localhost -p 44444 -F file01命令,将我们第一步创建的数据文件提交给agent。

5执行完后,如果没报错的话,可以去solr中通过http://slave77:8983/solr/collection1/select?q=*:*查询一下这两条数据是不是已经创建到搜索引擎的索引库中


如果看到如下图示的结果,恭喜你,你已经成功完成了本篇文章的NRT架构的搭建。


推荐阅读
  • 首先我们在taotao-search-interface工程中新建一个SearchService接口,并在接口中添加一个方法,如下图所示。接着,我们到taotao-search-s ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • Ubuntu16.04安装CDH5.14.2
    一、安装clouderamanager(下文简称cm)(一).环境及软件准备:1.环境:Ubuntu16.04desktopx3台ip分别为:10.132.226.121,10.1 ... [详细]
  • 本文由编程笔记#小编为大家整理,主要介绍了logistic回归(线性和非线性)相关的知识,包括线性logistic回归的代码和数据集的分布情况。希望对你有一定的参考价值。 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • springboot启动不了_Spring Boot + MyBatis 多模块搭建教程
    作者:枫本非凡来源:www.cnblogs.comorzlinp9717399.html一、前言1、创建父工程最近公司项目准备开始重构,框 ... [详细]
  • Lucene 全文检索技术入门
    一、搜索引擎的历史萌芽:Archie、Gopher起步:Robot(网络机器人)的出现与spider(网络爬虫)发展:excite、galax ... [详细]
  • solr倒排索引(转载)
    原文地址:http:blog.csdn.netchichengitarticledetails9235157http:blog.csdn.netnjpjsoftdevarticle ... [详细]
author-avatar
手机用户2502873453_987
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有