CDH+HBase Indexer+Solr爲HBase數據建立二級索引

CDH+HBase Indexer+Solr爲HBase數據建立二級索引

[TOC]php

0.前期聲明

本文章中有變量爲用戶自定義,爲了行文方便,文章中使用安裝環境時所使用的路徑、命名。html

  • Collection名字:humanCollection
  • 配置文件路徑:/root/human
  • 安裝zookeeper的機器名:master,slave1,slave2,slave3,slave4
  • CDH版本:5.15.0
  • HBase版本:1.2.0
  • Lily HBase Indexer版本:1.5
  • Solr版本:4.10.3
1.HBase建表並添加數據,而且肯定HBase表開啓REPLICATION功能(1表示開啓replication功能,0表示不開啓,默認爲0 )
  • 建立表

create '表名', {NAME => '列族名',NUMREGIONS => 5,SPLITALGO => 'HexStringSplit',REPLICATION_SCOPE => 1}java

  • 表已存在:
disable '表名' 
alter '表名',{NAME => '列族名', REPLICATION_SCOPE => 1} 
enable '表名' 
複製代碼
2.HBase啓用複製(在CM的hbase上搜索複製,勾選啓用複製)

3.準備中文分詞包(若是須要中文分詞的話)

1.根據solr和CDH的版本下載中文分詞包,安裝的solr是4.10.3,CDH版本是5.15.0,web

lucene-analyzers-smartcn-4.10.3-cdh5.15.0.jarshell

2.將中文分詞jar包分發到集羣全部機器的Solr和YARN服務相關的目錄數據庫

root@master:~# cp lucene-analyzers-smartcn-4.10.3-cdh5.15.0.jar /opt/cloudera/parcels/CDH/lib/hadoop-yarn
root@master:~# cp lucene-analyzers-smartcn-4.10.3-cdh5.15.0.jar /opt/cloudera/parcels/CDH/lib/solr/webapps/solr/WEB-INF/lib
複製代碼

3.重啓才能生效apache

4.建立的SolrCloud,生成實體配置文件

solrctl --zk master:2181,slave1:2181,slave2:2181,slave3:2181,slave4:2181/solr instancedir --generate /root/humanjson

**此時會在/root/human文件夾下生成一個conf文件夾bash

5.修改conf目錄下的schema.xml文件,主要是name對應到HBase中存儲的column內容。特別注意時間類型

關於schema.xml中的相關配置的詳解app

<?xml version="1.0" encoding="UTF-8" ?>
<schema name="example" version="1.5">
<fields>
	<!-- name字段,它對應了咱們後續須要修改Morphline.conf文件中的outputField屬性。所以能夠當作是hbase中須要建立索引的值,所以建議將其與表名和列族結合。所用到的類型須要在fieldType中設置。 id、_version_,和text是必須的 -->
    
    <!-- 必須字段 -->
	<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
   <field name="_root_" type="string" indexed="true" stored="false"/>
   <field name="name" type="text_general" indexed="true" stored="true"/>
   <field name="content" type="text_general" indexed="false" stored="true" multiValued="true"/>
   <field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>
   <field name="_version_" type="long" indexed="true" stored="true"/>
    
    <!-- 數據庫字段 -->
    <field name="數據庫字段" type="text_ch" indexed="是否建立索引" stored="是否存儲原始數據(若是不須要存儲相應字段值,儘可能設爲false)" required="false" multiValued="false" />
</fields>
<!-- 惟一鍵,相似主鍵,也可讓Solr自動生成 -->
<uniqueKey>id</uniqueKey>
<types>
  <!-- DateField在Solr5.0中被移除, 使用TrieDateField替換. -->
  <fieldType name="date_range" class="solr.DateField"/>
  <fieldType name="string" class="solr.StrField" sortMissingLast="true" />

    <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
    <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>

    <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
    </fieldType>
    <fieldType name="text_en" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_en.txt" />
        <filter class="solr.LowerCaseFilterFactory"/>
	<filter class="solr.EnglishPossessiveFilterFactory"/>
        <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
        <filter class="solr.PorterStemFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_en.txt" />
        <filter class="solr.LowerCaseFilterFactory"/>
	<filter class="solr.EnglishPossessiveFilterFactory"/>
        <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
        <filter class="solr.PorterStemFilterFactory"/>
      </analyzer>
    </fieldType>
    <fieldType name="text_en_splitting" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">
      <analyzer type="index">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_en.txt" />
        <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
        <filter class="solr.PorterStemFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_en.txt" />
        <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
        <filter class="solr.PorterStemFilterFactory"/>
      </analyzer>
    </fieldType>
    <fieldType name="text_ch" class="solr.TextField" positionIncrementGap="100">  
    <analyzer type="index"> 
      	<!-- solr.SmartChineseSentenceTokenizerFactory屬於lucene-analyzers-smartcn-4.10.3-cdh5.15.0.jar,包名是:org.apache.lucene.analysis.cn.smart.SmartChineseSentenceTokenizerFactory和 org.apache.lucene.analysis.cn.smart.SmartChineseWordTokenFilterFactory solr6.0去掉了這個類,取而代之的是HMMChineseTokenizerFactory。配置以下: <analyzer> <tokenizer class="solr.HMMChineseTokenizerFactory"/> <filter class="solr.StopFilterFactory" words="org/apache/lucene/analysis/cn/smart/stopwords.txt"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> -->  
      <tokenizer class="solr.SmartChineseSentenceTokenizerFactory"/>  
      <filter class="solr.SmartChineseWordTokenFilterFactory"/>  
    </analyzer>  
  </fieldType>
</types>
</schema>
複製代碼

可選項:修改conf目錄下的solrconfig.xml文件,將硬提交打開。會影響部分性能,根據需求去作。

<autoCommit>
       <maxTime>${solr.autoCommit.maxTime:60000}</maxTime>
       <openSearcher>true</openSearcher>
 </autoCommit>

複製代碼
  • 若是修改/root/human/conf下的配置文件schema.xml,須要從新上傳加載,執行如下語句:
solrctl --zk master:2181,slave1:2181,slave2:2181,slave3:2181/solr instancedir --update humanCollection /root/human/conf
solrctl --zk master:2181,slave1:2181,slave2:2181,slave3:2181/solr collection --reload humanCollection
複製代碼
6.初始化 collection實例並將配置文件上傳到 zookeeper

solrctl --zk master:2181,slave1:2181,slave2:2181,slave3:2181,slave4:2181/solr instancedir --create humanCollection /root/human/conf

登錄zk客戶端查看節點:ls /solr/configs/humanCollection,該節點下有solrconfig.xml、scheme.xml等配置文件;ls /solr/collections/下有humanCollection

root@master:~# cd /opt/cloudera/parcels/CDH/lib/zookeeper/bin
root@master:/opt/cloudera/parcels/CDH/lib/zookeeper/bin# ./zkCli.sh
...
[zk: localhost:2181(CONNECTED) 0] ls /solr/configs/humanCollection
[mapping-FoldToASCII.txt, currency.xml, protwords.txt, scripts.conf, synonyms.txt, stopwords.txt, _schema_analysis_synonyms_english.json, velocity, admin-extra.html, solrconfig.xml.secure, update-script.js, _schema_analysis_stopwords_english.json, solrconfig.xml, admin-extra.menu-top.html, elevate.xml, schema.xml, clustering, spellings.txt, xslt, mapping-ISOLatin1Accent.txt, _rest_managed.json, lang, admin-extra.menu-bottom.html]
[zk: localhost:2181(CONNECTED) 1] ls /solr/collections
複製代碼
7.建立collection
  • 默認參數

solrctl collection --create humanCollection

  • 若是但願將數據分散到各個節點進行存儲和檢索,則須要建立多個shard,增長參數

solrctl --zk master:2181,slave1:2181,slave2:2181,slave3:2181,slave4:2181/solr collection --create humanCollection -s 4 -r 1 -m 10

其中:

-s表示設置分片Shard數爲4,表示solrclound是4臺機器

-r表示設置的replica數爲1,表示1個副本

-m 默認值是1,表示最大shards數目

-c是指定zk上solr/configs節點下使用的配置文件名稱

-a是容許添加副本

** 建立solr分片時,要根據實際狀況定shard、replication,maxShardsPerNode,不然報錯,注意三個數值:

numShards、replicationFactor、liveSolrNode,一個正常的solrCloud集羣不允許同一個liveSolrNode上部署同

一個shard的多個replic,所以當maxShardsPerNode=1時,numShards*replicationFactor>liveSolrNode時,報

錯。所以正確時因知足如下條件:numShards*replicationFactor<liveSolrNode*maxShardsPerNode,即

s*r < liveSolrNode*m

  • 查看建立的collection:

solrctl --zk master:2181,slave1:2181,slave2:2181,slave3:2181,slave4:2181/solr collection --list

如下是沒有重啓報錯,因此必定要重啓solr,不然中文分詞會報錯!

<?xml version="1.0" encoding="utf-8"?>
<response> 
  <lst name="responseHeader"> 
    <int name="status">0</int>  
    <int name="QTime">1255</int> 
  </lst>  
  <lst name="failure"> 
    <str>org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException:Error CREATEing SolrCore 'humanCollection_shard1_replica1': Unable to create core [humanCollection_shard1_replica1] Caused by: solr.SmartChineseSentenceTokenizerFactory</str>  
    <str>org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException:Error CREATEing SolrCore 'humanCollection_shard3_replica1': Unable to create core [humanCollection_shard3_replica1] Caused by: solr.SmartChineseSentenceTokenizerFactory</str>  
    <str>org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException:Error CREATEing SolrCore 'humanCollection_shard4_replica1': Unable to create core [humanCollection_shard4_replica1] Caused by: solr.SmartChineseSentenceTokenizerFactory</str>  
    <str>org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException:Error CREATEing SolrCore 'humanCollection_shard2_replica1': Unable to create core [humanCollection_shard2_replica1] Caused by: solr.SmartChineseSentenceTokenizerFactory</str> 
  </lst> 
</response>
複製代碼
8.建立 Morphline 配置文件

進入CM管理頁面:http://IP:7180/——選擇Key-Value Store Indexer——配置——Morphlines 文件

SOLR_LOCATOR : {
  collection : humanCollection
  zkHost : "$ZK_HOST" 
}
morphlines : [
{
id : morphlineOfHuman 								
importCommands : ["org.kitesdk.morphline.**", "com.ngdata.**"]	
commands : [                    
  {
    extractHBaseCells {
      mappings : [ 
        {
          inputColumn : "human:features_type"	
          outputField : "features_type" 
          type : string  
          source : value 
        },
        { 
		  inputColumn : "human:createTime" 
          outputField : "createTime" 
          type : string  
          source : value 
        }
      ]
    }
  }
  {
	convertTimestamp {
	  field : createTime
	  inputFormats : ["yyyy-MM-dd HH:mm:ss"]
	  inputTimezone : Asia/Shanghai
	  outputFormat : "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
	  outputTimezone : Asia/Shanghai
	}
  }
  { logDebug { format : "output record: {}", args : ["@{}"] } }
]
}
]
複製代碼

id:表示當前morphlines文件的ID名稱。

importCommands:須要引入的命令包地址。

extractHBaseCells:該命令用來讀取HBase列數據並寫入到SolrInputDocument對象中,該命令必須包含零個或者

多個mappings命令對象。

mappings:用來指定HBase列限定符的字段映射。

inputColumn:須要寫入到solr中的HBase列字段。值包含列族和列限定符,並用':'分開。其中列限定符也可使用通配符'*'來表示。

outputField:用來表示morphline讀取的記錄須要輸出的數據字段名稱,該名稱必須和solr中的schema.xml文件的字段名稱保持一致,不然寫入不正確。

type:用來定義讀取HBase數據的數據類型,咱們知道HBase中的數據都是以byte[]的形式保存,可是全部的內容在

Solr中索引爲text形式,因此須要一個方法來把byte[]類型轉換爲實際的數據類型。type參數的值就是用來作這件

事情的。如今支持的數據類型有:byte,int,long,string,boolean,float,double,short和bigdecimal。固然你也能夠指

定自定的數據類型,只須要實現com.ngdata.hbaseindexer.parse.ByteArrayValueMapper接口便可。

source:用來指定HBase的KeyValue那一部分做爲索引輸入數據,可選的有‘value’和'qualifier',當爲value的時候

表示使用HBase的列值做爲索引輸入,當爲qualifier的時候表示使用HBase的列限定符做爲索引輸入。

9.建立 Lily HBase Indexer 配置

在/root/human目錄下建立一個morphline-hbase-mapper-humanCollection.xml文件,每一個collection對應一個morphline-hbase-mapper-humanCollection.xml 文件,morphlineId不要和hbase的table名稱相同。

<?xml version="1.0" encoding="UTF-8"?>
<!-- table:須要索引的HBase表名稱 mapper:用來實現和讀取指定的Morphline配置文件類,固定爲MorphlineResultToSolrMapper -->
<indexer table="對應Hbase裏的表名" mapper="com.ngdata.hbaseindexer.morphline.MorphlineResultToSolrMapper" mapping-type="row">
<!-- param中的name參數用來指定當前配置爲morphlineFile文件 value用來指定morphlines.conf文件的路徑,絕對或者相對路徑用來指定本地路徑,若是是使用Cloudera Manager來管理morphlines.conf就直接寫入值morphlines.conf -->
<param name="morphlineFile" value="morphlines.conf"/>
<!-- morphlineId的value是對應Key-Value Store Indexer中配置文件Morphlines.conf中morphlines屬性id值。morphlineId不要和hbase的table名稱相同 -->
<param name="morphlineId" value="morphlineOfHuman"/>
</indexer>
複製代碼
10.註冊 Lily HBase Indexer Configuration 和 Lily HBase Indexer Service

當 Lily HBase Indexer 配置 XML文件的內容使人滿意,將它註冊到 Lily HBase Indexer Service。上傳 Lily HBase Indexer 配置 XML文件至 ZooKeeper,由給定的 SolrCloud 集合完成此操做。

hbase-indexer add-indexer \
--name humanIndexer \
--indexer-conf /root/human/morphline-hbase-mapper-humanCollection.xml \
--connection-param solr.zk=master:2181,slave1:2181,slave2:2181,slave3:2181/solr \
--connection-param solr.collection=humanCollection \
--zookeeper master:2181,slave1:2181,slave2:2181,slave3:2181
複製代碼

再次運行hbase-indexer list-indexers --zookeeper master:2181,slave1:2181,slave2:2181,slave3:2181,slave4:2181查看是否添加成功。

root@master:/opt/cloudera/parcels/CDH/lib/zookeeper/bin# hbase-indexer list-indexers --zookeeper master:2181,slave1:2181,slave2:2181,slave3:2181,slave4:2181
Number of indexes: 1

humanCollectionIndexer
  + Lifecycle state: ACTIVE
  + Incremental indexing state: SUBSCRIBE_AND_CONSUME
  + Batch indexing state: INACTIVE
  + SEP subscription ID: Indexer_humanCollectionIndexer
  + SEP subscription timestamp: 2018-12-10T09:36:29.514+08:00
  + Connection type: solr
  + Connection params:
    + solr.zk = master:2181,slave1:2181,slave2:2181,slave3:2181,slave4:2181/solr
    + solr.collection = humanCollection
  + Indexer config:
      270 bytes, use -dump to see content
  + Indexer component factory: com.ngdata.hbaseindexer.conf.DefaultIndexerComponentFactory
  + Additional batch index CLI arguments:
      (none)
  + Default additional batch index CLI arguments:
      (none)
  + Processes
    + 4 running processes
    + 0 failed processes
複製代碼

問題:

www.cnblogs.com/husky/p/sol…

  • (1) 若是有建立indexer失敗,原來的indexer已經存在,則使用hbase-indexer delete-indexer --name $IndxerName --zookeeper master:2181,slave1:2181,slave2:2181,slave3:2181,slave4:2181刪除原來的indexer
  • (2)使用hbase-indexer list-indexers --zookeeper master:2181,slave1:2181,slave2:2181,slave3:2181,slave4:2181命令,查看是否建立成功

緣由是zookeeper只設置了一個

錯誤示例:

hbase-indexer add-indexer \
--name bqjrIndexer \
--indexer-conf $HOME/hbase-indexer/bqjr/morphline-hbase-mapper.xml \
--connection-param solr.zk=bqbpm2.bqjr.cn:2181/solr \
--connection-param solr.collection=bqjr \
--zookeeper bqbpm2.bqjr.cn:2181
複製代碼

正確示例

hbase-indexer add-indexer \
--name bqjrIndexer \
--indexer-conf $HOME/hbase-indexer/bqjr/morphline-hbase-mapper.xml \
--connection-param solr.zk=bqbps1.bqjr.cn:2181,bqbpm1.bqjr.cn:2181,bqbpm2.bqjr.cn:2181/solr \
--connection-param solr.collection=bqjr \
--zookeeper bqbps1.bqjr.cn:2181,bqbpm1.bqjr.cn:2181,bqbpm2.bqjr.cn:2181
複製代碼
  • (3)若是索引器須要重建,刪除使用下列方法。若是刪除不了,始終在刪除中的死循環中,就須要到zk上手動刪除節點信息:ls /ngdata/hbaseindexer下。
hbase-indexer delete-indexer -n smsdayIndexer --zookeeper nn1.hadoop:2181
複製代碼
11.同步數據

添加數據到HBASE,而後進入Solr的管理界面:http://IP:8983(CDH有可能爲898四、8985)/solr

在q(query)裏面輸入HBase_Indexer_Test_cf1_name:xiaogang能夠看到對應得HBase得rowkey

12.批量同步索引

仔細觀察11咱們會發現一個問題,咱們只記錄了後面插入的數據,那原來就存在HBase的數據怎麼辦呢?

在運行命令的目錄下必須有morphlines.conf文件,執行find / |grep morphlines.conf$通常咱們選擇最新的

那個process 。

若是沒有morphlines.conf,則新建一個morphlines.conf文件,添加在CM中配置的morphline的文件內容:

morphlines : [
{
id : morphlineOfHuman
importCommands : ["org.kitesdk.morphline.**", "com.ngdata.**"]	
commands : [                    
  {
    extractHBaseCells { 
      mappings : [ 
        {
          inputColumn : "human:features_type"
          outputField : "features_type"
          type : string
          source : value
        }
        { 
		  inputColumn : "human:createTime" 
          outputField : "createTime" 
          type : string  
          source : value 
        }
      ]
    }
  }
  {
	convertTimestamp {
	  field : createTime
	  inputFormats : ["yyyy-MM-dd HH:mm:ss"]
	  inputTimezone : Asia/Shanghai
	  outputFormat : "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
	  outputTimezone : Asia/Shanghai
	}
  }
  { logDebug { format : "output record: {}", args : ["@{}"] } }
]
}
]
複製代碼

而後,執行

hadoop --config /etc/hadoop/conf.cloudera.yarn \
jar /opt/cloudera/parcels/CDH/lib/hbase-solr/tools/hbase-indexer-mr-*-job.jar \
-D 'mapred.child.java.opts=-Xmx1024m' \
--conf /etc/hbase/conf/hbase-site.xml \
--log4j /opt/cloudera/parcels/CDH/share/doc/search*/examples/solr-nrt/log4j.properties \
--hbase-indexer-file /root/human/morphline-hbase-mapper-humanCollection.xml \
--morphline-file /root/human/morphlines.conf \
--verbose \
--go-live \
--zk-host master:2181,slave1:2181,slave2:2181,slave3:2181/solr \
--collection humanCollection

-- 中文分詞須要加上的,不用分詞則不用加上這一句
-libjars /home/hadoop/package/lucene-analyzers-smartcn-4.10.3-cdh5.15.0.jar \
複製代碼

參考:Lily HBase Batch Indexing for Cloudera Search

問題:

  • (1)使用自帶的indexer工具批量同步索引失敗,提示找不到morphlines.conf

首先,命令中要指定morphlines.conf文件路徑和morphline-hbase-mapper.xml文件路徑。執行: find / |grep morphlines.conf$

通常咱們選擇最新的那個process,咱們將其拷貝或者添加到配置項中。進入到

/opt/cm-5.7.0/run/cloudera-scm-agent/process/1386-ks_indexer-HBASE_INDEXER/morphlines.conf

或者加上

--morphline-file /opt/cm-5.7.0/run/cloudera-scm-agent/process/1501-ks_indexer-HBASE_INDEXER/morphlines.conf

執行下面的命令

hadoop --config /etc/hadoop/conf \
jar /opt/cloudera/parcels/CDH/lib/hbase-solr/tools/hbase-indexer-mr-1.5-cdh5.7.0-job.jar \
--conf /etc/hbase/conf/hbase-site.xml \
--hbase-indexer-file $HOME/hbase-indexer/bqjr/morphline-hbase-mapper.xml \
--morphline-file /opt/cm-5.7.0/run/cloudera-scm-agent/process/1629-ks_indexer-HBASE_INDEXER/morphlines.conf \
--zk-host bqbpm1.bqjr.cn:2181,bqbps1.bqjr.cn:2181,bqbpm2.bqjr.cn:2181/solr \
--collection bqjr \
--go-live
複製代碼
  • (2)使用自帶的indexer工具批量同步索引失敗,提示找不到solrconfig.xml

加上reducers--reducers 0就能夠了

hadoop --config /etc/hadoop/conf \
jar /opt/cloudera/parcels/CDH/lib/hbase-solr/tools/hbase-indexer-mr-job.jar \
--conf /etc/hbase/conf/hbase-site.xml \
--hbase-indexer-file $HOME/hbase-indexer/bqjr/morphline-hbase-mapper.xml \
--morphline-file /opt/cm-5.7.0/run/cloudera-scm-agent/process/1501-ks_indexer-HBASE_INDEXER/morphlines.conf \
--zk-host bqbpm2.bqjr.cn:2181/solr \
--collection bqjr \
--reducers 0 \
--go-live
複製代碼
13.設置多個indexer

每個Hbase Table對應生成一個Solr的Collection索引,每一個索引對應一個Lily HBase Indexer 配置文件morphlines.conf和morphline配置文件morphline-hbase-mapper.xml,其中morphlines.conf可由CDH的Key-Value Store Indexer控制檯管理,以id區分 。可是咱們在CDH中沒辦法配置多個morphlines.conf文件的,那咱們怎麼讓indexer和collection關聯呢?

SOLR_LOCATOR :{
    # ZooKeeper ensemble
    zkHost :"$ZK_HOST"
}
morphlines :[
	{
	id : XDGL_ACCT_FEE_Map
	importCommands :["org.kitesdk.**","com.ngdata.**"]
	commands :[
        {
        extractHBaseCells {
        mappings :[
			{
        	inputColumn :"cf1:ETL_IN_DT"
        	outputField :"XDGL_ACCT_FEE_cf1_ETL_IN_DT"
        	type :string
        	source : value
			}
		]
		}
	}
	{ logDebug { format :"output record: {}", args :["@{}"]}}
	]
},
{
    id : XDGL_ACCT_PAYMENT_LOG_Map
    importCommands :["org.kitesdk.**","com.ngdata.**"]
    commands :[
		{
        extractHBaseCells {
        mappings :[
			{
            inputColumn :"cf1:ETL_IN_DT"
            outputField :"XDGL_ACCT_PAYMENT_LOG_cf1_ETL_IN_DT"
            type :string
            source : value
			}
		]
		}
	}
	{ logDebug { format :"output record: {}", args :["@{}"]}}
	]
}
]
複製代碼
14.擴展命令

solrctl

solrctl instancedir --list
solrctl collection --list
複製代碼
  • 更新coolection配置
solrctl instancedir --update User \$HOME/hbase-indexer/User
	solrctl collection --reload User
複製代碼
  • 刪除instancedir
solrctl --zk master:2181,slave1:2181,slave2:2181,slave3:2181,slave4:2181/solr instancedir --delete humanCollection
複製代碼
  • 刪除collection
solrctl --zk master:2181,slave1:2181,slave2:2181,slave3:2181,slave4:2181/solr collection --delete humanCollection
複製代碼
  • 刪除collection全部doc
solrctl collection --deletedocs User
複製代碼
  • 刪除User配置目錄
rm -rf $HOME/hbase-indexer/User
複製代碼

hbase-indexer

  • 若修改了morphline-hbase-mapper.xml,需更新索引
hbase-indexer update-indexer -n userIndexer
複製代碼
  • 刪除索引
hbase-indexer delete-indexer -n userIndexer --zookeeper master:2181,slave:2181
複製代碼
  • 查看索引
hbase-indexer list-indexers
複製代碼
[hadoop@db1 lib]$ solrctl --help

usage: /opt/cloudera/parcels/CDH-5.5.1-1.cdh5.5.1.p0.11/bin/../lib/solr/bin/solrctl.sh [options] command [command-arg] [command [command-arg]] 
solrctl [options] command [command-arg] [command [command-arg]] ...  
可選參數有:  
--solr:指定 SolrCloud 的 web API,若是在 SolrCloud 集羣以外的節點運行命令,就須要指定該參數。  
--zk:指定 zk 集羣solr目錄。  
--help:打印幫助信息。  
--quiet:靜默模式運行。  

command 命令有:  
init [--force]:初始化配置。  
instancedir:維護實體目錄。可選的參數有:  
--generate path  
--create name path  
--update name path  
--get name path  
--delete name  
--list  


collection:維護 collections。可選的參數有:  
[--create name -s <numShards>
                              [-a Create collection with autoAddReplicas=true]
                              [-c <collection.configName>]
                              [-r <replicationFactor>]
                              [-m <maxShardsPerNode>]
                              [-n <createNodeSet>]]
--delete name: Deletes a collection.  
--reload name: Reloads a collection.  
--stat name: Outputs SolrCloud specific run-time information fora collection.  
`--list: Lists all collections registered in SolrCloud.  
--deletedocs name: Purges all indexed documents from a collection.  


core:維護 cores。可選的參數有:  
--create name [-p name=value]]  
--reload name: Reloads a core.  
--unload name: Unloads a core.  
--status name: Prints status of a core.  


cluster:維護集羣配置信息。可選的參數有:  
--get-solrxml file  
--put-solrxml file 
複製代碼
15.問題
  • (1)HBaseIndexer啓動後一下子就自動退出

這個問題有不少緣由。一個是前面說的mappine文件不匹配,另外一種是因爲內存溢出。

這裏面能夠看到錯誤日誌,若是是內存溢出的問題,須要調大。

解決:配置-資源管理-堆棧大小(字節) 50MB改成1G

  • (2)HBaseIndexer同步的數據與Solr不一致

第一種是由於本身寫的Spark同步和HBaseIndexer同時在跑,而數據是一直更新的,在批量插入的時候清空了數據會致使本來由HBaseIndexer的插入的數據刪除掉了

第二種如HBase Indexer致使Solr與HBase數據不一致問題解決所說,因爲HBase插入的WAL和實際數據是異步的,所以會產生「取不到數據」的狀況,增長read-row="never"

詳情參考:stackoverflow

16.參考資料:

1.Solr官網文檔

2.Solr Wiki

3.Solr Wiki DateRangeField

4.如何使用Lily HBase Indexer對HBase中的數據在Solr中創建索引

5.CDH使用Solr實現HBase二級索引

6.HBase+Solr 的 二級索引 實時查詢

7.如何在CDH中使用Solr對HDFS中的JSON數據創建全文索引

8.hbase基於solr配置二級索引

9.HBase創建二級索引的一些解決方案(Solr+hbase方案等)

10.基於Solr的Hbase二級索引

11.我與solr(五)--關於schema.xml中的相關配置的詳解

12.我與solr(六)--solr6.0配置中文分詞器IK Analyzer

相關文章
相關標籤/搜索