lily+Solr 原理与配置

教程 犀牛 ⋅ 于 2021-06-02 17:40:25 ⋅ 1193 阅读

概述

  • 为什么要引入lily和solr

​ 在Hbase中,表的RowKey 按照字典排序, 单一的通过RowKey检索数据的方式,不再满足更多的需求,查询成为Hbase的瓶颈,希望像Sql一样快速检索数据,Hbase之前定位的是大表的存储,要进行这样的查询,往往是要通过类似Hive、Pig等系统进行全表的MapReduce计算,这种方式既浪费了机器的计算资源,又因高延迟使得应用黯然失色,于是HBase Secondary Indexing的方案出现了。

  • Solr

    Solr是一个独立的企业级搜索应用服务器,是Apache Lucene项目的开源企业搜索平台,其主要功能包括全文检索、命中标示、分面搜索、动态聚类、数据库集成,以及富文本(如Word、PDF)的处理。Solr是高度可扩展的,并提供了分布式搜索和索引复制。Solr 4还增加了NoSQL支持,以及基于Zookeeper的分布式扩展功能SolrCloud。它的主要特性包括:高效、灵活的缓存功能,垂直搜索功能,Solr是一个高性能,采用Java5开发,基于Lucene的全文搜索服务器。同时对其进行了扩展,提供了比Lucene更为丰富的查询语言,同时实现了可配置、可扩展并对查询性能进行了优化,并且提供了一个完善的功能管理界面,是一款非常优秀的全文搜索引擎,Solr可以高亮显示搜索结果,通过索引复制来提高可用,性,提供一套强大Data Schema来定义字段,类型和设置文本分析,提供基于Web的管理界面。

  • Key-Value Store Indexer

这个组件非常关键,是Hbase到Solr生成索引的中间工具,在CDH5.3.2中的Key-Value Indexer使用的是Lily HBase Indexer 服务,Lily HBase Indexer是一款灵活的、可扩展的、高容错的、事务性的,并且近实时的处理HBase列索引数据的分布式服务软件。它是NGDATA公司开发的Lily系统的一部分,已开放源代码,Lily HBase Indexer使用SolrCloud来存储HBase的索引数据,当HBase执行写入、更新或删除操作时,Indexer通过HBase的replication功能来把这些操作抽象成一系列的Event事件,并用来保证写入Solr中的HBase索引数据的一致性,并且Indexer支持用户自定义的抽取,转换规则来索引HBase列数据。Solr搜索结果会包含用户自定义的columnfamily:qualifier字段结果,这样应用程序就可以直接访问HBase的列数据。

  • hbase+lily+solr架构

file

服务配置

hbase配置文件搜索index,启用编制索引。

file

启用复制

file

solr

  • collection创建脚本
# 用来创建solr collection
cat > createcollection.sh << EOF
# zk节点
ZK="worker-1"
# 要创建的collection名称
COLLECTION="hainiu"
BASE=`pwd`
# 分片数
SHARD=1
# 副本数
REPLICA=1
echo "create solr collection"
rm -rf tmp/*
# 生成配置文件
solrctl --zk $ZK:2181/solr instancedir --generate tmp/${COLLECTION}_configs
# 上传配置文件到zk
solrctl --zk $ZK:2181/solr instancedir --create $COLLECTION tmp/${COLLECTION}_configs
echo "如果collection名称重复会报configuration重复错误,更换collection名称"
# solr创建collection
solrctl --zk $ZK:2181/solr collection --create $COLLECTION -s $SHARD -r $REPLICA
echo "如果collection名称重复会报configuration重复错误,更换collection名称"
# 查看collection
solrctl --zk $ZK:2181/solr collection --list
EOF
  • 执行创建脚本
sh createcollection.sh

file

  • solr web验证

file

  • solr创建field字段

使用postman或者curl命令操作solr api创建字段

方式一postman:

file

file

方式二curl:

# 非安全模式
curl -X POST -H 'Content-Type:application/json' -d '{
    "add-field":{
        "name":"content",
        "type":"text_en",
        "stored":true,
        "indexed":true
    }
}' http://worker-3:8983/solr/hainiu/schema
# 安全模式 用户名和密码可以随意输入
curl --negotiate -u xiniu:xiniu -X POST -H 'Content-Type:application/json' -d '{
    "add-field":{
        "name":"content",
        "type":"text_en",
        "stored":true,
        "indexed":true
    }
}' http://worker-3:8983/solr/hainiu0602/schema

lily hbase indexer

mkdir -p /root/solr-hbase/conf
cd /root/solr-hbase
  • 准备morphline配置文件(解读)
# 准备morphline配置文件
morphlines : [
  {
    # morphline配置id,与indexer配置文件中的morphlineID一致
    id : morphline1 
    importCommands : ["org.kitesdk.morphline.**", "com.ngdata.**"]
    commands : [
    {
        extractHBaseCells {
          # hbase字段映射
          mappings : [
            {
              # textinfo为hbase对应的列族,content为hbase对应的列名
              inputColumn : "textinfo:content"
              # 输出列,对应solr中的field字段
              outputField : "content"
              # solr中字段类型
              type : "string"
              source : value
            }]
        }
    }
    ]
  }
]

正式配置文件

cat > conf/morphlines.conf << EOF
morphlines : [
  {
    id : morphline1 
    importCommands : ["org.kitesdk.morphline.**", "com.ngdata.**"]
    commands : [
    {
        extractHBaseCells {
          mappings : [
            {
              inputColumn : "textinfo:content"
              outputField : "content"
              type : "string"
              source : value
            }]
        }
    }
    ]
  }
]
EOF
  • 准备indexer配置文件
cat > conf/indexer-config.xml << EOF
<?xml version="1.0"?>
<indexer table="TextHbase" mapper="com.ngdata.hbaseindexer.morphline.MorphlineResultToSolrMapper" mapping-type="row" >
    <!-- The relative or absolute path on the local file system to the morphline configuration file. -->
    <!-- Use relative path "morphlines.conf" for morphlines managed by Cloudera Manager -->
    <param name="morphlineFile" value="/root/solr-hbase/conf/morphlines.conf"/>
    <!-- The optional morphlineId identifies a morphline if there are multiple morphlines in morphlines.conf -->
    <!-- <param name="morphlineId" value="morphline1"/> -->
</indexer>
EOF
  • 执行lily hbase indexer刷新脚本
vim hbase2solr.sh
# 填入如下内容
COLLECTION='hainiu'
ZK='worker-1'
echo 'Delete previous docs...'
solrctl collection --deletedocs $COLLECTION
echo 'Lily HBase MapReduce indexing...'
config="/etc/hadoop/conf.cloudera.yarn"
parcel="/opt/cloudera/parcels/CDH"
jar="$parcel/lib/hbase-solr/tools/hbase-indexer-mr-*-job.jar"
hbase_conf="/etc/hbase/conf/hbase-site.xml"
opts="'mapred.child.java.opts=-Xmx1024m'"
log4j="$parcel/share/doc/search*/examples/solr-nrt/log4j.properties"
zk="$ZK:2181/solr"
# libjars="lib/lucene-analyzers-smartcn-4.10.3-cdh5.14.2.jar"
# export HADOOP_OPTS="-Djava.security.auth.login.config=conf/jaas.conf"
hadoop --config $config jar $jar --conf $hbase_conf -D $opts --log4j $log4j --hbase-indexer-file conf/indexer-config.xml --verbose --go-live --zk-host $zk --collection $COLLECTION
  • 安全模式执行lily hbase indexer刷新脚本

创建jaas.conf文件,填写如下内容

mkdir -p conf/jaas.conf
Client {
  com.sun.security.auth.module.Krb5LoginModule required
  useKeyTab=true
  keyTab="/root/solr-hbase/solr.keytab"
  storeKey=true
  useTicketCache=false
  principal="solr@HAINIU.COM";
};
vim hbase2solr.sh
# 填入如下内容
COLLECTION='hainiu'
ZK='worker-1'
echo 'Delete previous docs...'
solrctl collection --deletedocs $COLLECTION
echo 'Lily HBase MapReduce indexing...'
config="/etc/hadoop/conf.cloudera.yarn"
parcel="/opt/cloudera/parcels/CDH"
jar="$parcel/lib/hbase-solr/tools/hbase-indexer-mr-*-job.jar"
hbase_conf="/etc/hbase/conf/hbase-site.xml"
opts="'mapred.child.java.opts=-Xmx1024m'"
log4j="$parcel/share/doc/search*/examples/solr-nrt/log4j.properties"
zk="$ZK:2181/solr"
# libjars="lib/lucene-analyzers-smartcn-4.10.3-cdh5.14.2.jar"
export HADOOP_OPTS="-Djava.security.auth.login.config=conf/jaas.conf"
hadoop --config $config jar $jar --conf $hbase_conf -D $opts --log4j $log4j --hbase-indexer-file conf/indexer-config.xml --verbose --go-live --zk-host $zk --collection $COLLECTION
  • 执行hbase2solr.sh脚本
sh hbase2solr.sh

file

file

file

  • solr web验证数据

file

file

版权声明:原创作品,允许转载,转载时务必以超链接的形式表明出处和作者信息。否则将追究法律责任。来自海汼部落-犀牛,http://hainiubl.com/topics/75587
回复数量: 0
    暂无评论~~
    • 请注意单词拼写,以及中英文排版,参考此页
    • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`, 更多语法请见这里 Markdown 语法
    • 支持表情,可用Emoji的自动补全, 在输入的时候只需要 ":" 就可以自动提示了 :metal: :point_right: 表情列表 :star: :sparkles:
    • 上传图片, 支持拖拽和剪切板黏贴上传, 格式限制 - jpg, png, gif,教程
    • 发布框支持本地存储功能,会在内容变更时保存,「提交」按钮点击时清空
    Ctrl+Enter