CDH 6 安装 Hbase 二级索引 Solr + Key-Value Store Indexer
目錄
一、集群安裝Solr +??Key-Value Store Indexer
二、創建Hbase二級索引
1.更改表結構,允許復制
2.創建相應的SolrCloud集合
3.創建 collection實例并將配置文件上傳到 zookeeper
?4.創建 Lily HBase Indexer 配置
5.配置Morphline文件
6.注冊 Lily HBase Indexer Configuration 和 Lily HBase Indexer Service
7.重啟?Key-Value Store Indexer 服務
三、命令匯總
1.列出所有 Hbase indexer
2.刪除 Hbase indexer
3.列出 Solr 所有 collection
4.清空 Solr collection 中所有數據
5.刪除 Solr collection?
6.列出 Solr 所有 instancedir
7.刪除 Solr?instancedir
8.初始化生成?instancedir 配置文件
9.創建?instancedir
10. 創建 Solr collection
11. 創建 Hbase Indexer
12.更新 Solr?instancedir 配置
13.更新 Solr collection配置
14.更新 Hbase Indexer
一、集群安裝Solr +??Key-Value Store Indexer
? ? ? 先安裝Solr ,再安裝Key-Value Store Indexer ,安裝節點和hbase,hdfs在相同節點。
二、創建Hbase二級索引
1.更改表結構,允許復制
已存在的表 disable 'tableName' alter 'tableName',{NAME =>'fn', REPLICATION_SCOPE =>1} enable 'tableName' 不存在的表 create ‘table‘,{NAME =>‘cf‘, REPLICATION_SCOPE =>1} #其中1表示開啟replication功能,0表示不開啟,默認為02.創建相應的SolrCloud集合
這里得路徑和用戶名都可以自己定義
進入?~/hbase-indexer/user_index 目錄下的conf目錄,將managed-schema 文件復制為?schema.xml
cp managed-schema schema.xml在schema.xml文件中加入
<field name="HBase_Indexer_Test_cf1_name" type="string" indexed="true" stored="true"/> 屬性解析: name:這里的name是自定義,但是后面要使用到,要和后面的Morphline.conf文件中的outputField屬性對應。 type:字段類型 indexed:是否建立索引 stored:是否存儲注意:這里name字段它對應了我們后續需要修改Morphline.conf文件中的outputField屬性。因此可以看成是hbase中需要創建索引的值。因此我們建議將其與表名和列族結合,格式建議如下:
HBase_Indexer_ZDTable_fn_name Hbase_indexer_表名_列簇_列名再修改solrconfig.xml,找到下面的配置將false改為true,這個是硬提交,會影響性能
<autoCommit><maxTime>${solr.autoCommit.maxTime:60000}</maxTime><openSearcher>true</openSearcher></autoCommit>創建
solrctl instancedir --create index1 /home/jast/opt/hbase-indexer/index13.創建 collection實例并將配置文件上傳到 zookeeper
solrctl collection --create index1如果希望將數據分散到各個節點進行存儲和檢索,則需要創建多個shard,需要使用如下命令solrctl collection --create index1 -s 7 -r 3 -m 21其中-s表示設置Shard數為7,-r表示設置的replica數為3,-m表示最大shards數目(7*3)?4.創建 Lily HBase Indexer 配置
創建文件?morphline-hbase-mapper.xml?
[root@test119 index1]# cat morphline-hbase-mapper.xml <?xml version="1.0"?> <!-- table:需要索引的HBase表名稱--> <!-- mapper:用來實現和讀取指定的Morphline配置文件類,固定為MorphlineResultToSolrMapper--> <indexer table="hbase_tableName" mapper="com.ngdata.hbaseindexer.morphline.MorphlineResultToSolrMapper" read-row="never" > <!--param中的name參數用來指定當前配置為morphlineFile文件 --> <!--value用來指定morphlines.conf文件的路徑,絕對或者相對路徑用來指定本地路徑,如果是使用Cloudera Manager來管理morphlines.conf就直接寫入值morphlines.conf"--><param name="morphlineFile" value="morphlines.conf"/> <!--value="ZDTableMap",這里test3Map是自定義,接下來要使用。其他的mapper,param name等屬性默認即可--><param name="morphlineId" value="JastTableMap"/> </indexer>5.配置Morphline文件
進入CM管理界面中?Key-Value Store Indexer,修改?Morphline文件
SOLR_LOCATOR : {# Name of solr collectioncollection : hbaseindexer# ZooKeeper ensemblezkHost : "$ZK_HOST" }morphlines : [ { id : JastTableMap importCommands : ["org.kitesdk.**", "com.ngdata.**"]commands : [ {extractHBaseCells {mappings : [{inputColumn : "fn:name"outputField : "hbase_indexer_vt_fn_name" type : string source : value},{inputColumn : "fn:comments_count"outputField : "hbase_indexer_vt_fn_comments_count" type : stringsource : value},{inputColumn : "fn:text"outputField : "hbase_indexer_vt_fn_text" type : stringsource : value}]}}{ logDebug { format : "output record: {}", args : ["@{}"] } } ] } ]上面設置類型都是string(根據數據會自動轉換),如果需要設置int類型可以參考:?
?https://datamining.blog.csdn.net/article/details/103566964?
注:
id:表示當前morphlines的名稱,與上一步的value="JastTableMap"要一致importCommands:需要引入的命令包地址extractHBaseCells:該命令用來讀取HBase列數據并寫入到SolrInputDocument對象中,該命令必須包含零個或者多個mappings命令對象。mappings:用來指定HBase列限定符的字段映射。inputColumn:需要寫入到solr中的HBase列字段。值包含列族和列限定符,并用‘ : ’分開。其中列限定符也可以使用通配符*來表示,譬如可以使用c1:*表示讀取只要列族為data的所有hbase列數據,也可以通過c1:na*來表示讀取列族為c1列限定符已na開頭的字段值.outputField:用來表示morphline讀取的記錄需要輸出的數據字段名稱,該名稱必須和solr中的schema.xml文件的field節點自定義的name名稱保持一致,否則寫入不正確type:用來定義讀取HBase數據的數據類型,HBase中的數據都是以byte[]的形式保存,但是所有的內容在Solr中索引為text形式,所以需要一個方法來把byte[]類型轉換為實際的數據類型。type參數的值就是用來做這件事情的。現在支持的數據類型有:byte,int,long,string,boolean,float,double,short和bigdecimal。當然你也可以指定自定的數據類型,只需要實現com.ngdata.hbaseindexer.parse.ByteArrayValueMapper接口即可實現接口可參考:?https://datamining.blog.csdn.net/article/details/103566964?source:用來指定HBase的KeyValue那一部分作為索引輸入數據,可選的有‘value’和'qualifier',當為value的時候表示使用HBase的列值作為索引輸入,當為qualifier的時候表示使用HBase的列限定符作為索引輸入?
6.注冊 Lily HBase Indexer Configuration 和 Lily HBase Indexer Service
hbase-indexer add-indexer \ --name ZDindexer \ --indexer-conf /opt/hbase-indexer/index1/morphline-hbase-mapper.xml --connection-param solr.zk=test110:2181,test115:2181,test119:2181/solr \ --connection-param solr.collection=index1 \ --zookeeper test110:2181,test115:2181,test119:2181注:這里的name可以隨便起,solr.collection 要與上面的相同
7.重啟?Key-Value Store Indexer 服務
此時往hbase中插入數據,可以自動同步至 Solr 中,Solr Collection 為上面創建的 index1
solr查看頁面:http://ip:8983
?
三、命令匯總
1.列出所有 Hbase indexer
hbase-indexer list-indexers --zookeeper hostname:21812.刪除 Hbase indexer
hbase-indexer delete-indexer --name TESTindexer --zookeeper hostname1:2181,hostname2:2181,hostname3:21813.列出 Solr 所有 collection
solrctl collection --list4.清空 Solr collection 中所有數據
solrctl collection --deletedocs vt_index5.刪除 Solr collection?
solrctl collection --delete vt_index6.列出 Solr 所有 instancedir
solrctl instancedir --list7.刪除 Solr?instancedir
solrctl instancedir --delete vt_index8.初始化生成?instancedir 配置文件
solrctl instancedir --generate /home/jast/opt/hbase-indexer/index19.創建?instancedir
solrctl instancedir --create index1 /home/jast/opt/hbase-indexer/index110. 創建 Solr collection
solrctl collection --create index1 -s 3 -r 1 -m 311. 創建 Hbase Indexer
hbase-indexer add-indexer \ --name TESTindexer \ --indexer-conf ~/opt/hbase-indexer/morphline-hbase-mapper.xml --connection-param solr.zk=hostname1:2181,hostname2:2181,hostname3:2181/solr \ --connection-param solr.collection=index1\ --zookeeper hostname1:2181,hostname2:2181,hostname3:218112.更新 Solr?instancedir 配置
solrctl instancedir --update index1/home/jast/opt/hbase-indexer/index113.更新 Solr collection配置
solrctl collection --reload index114.更新 Hbase Indexer
hbase-indexer update-indexer -n index1?
常見問題
問題1:服務異常退出,查看日志發現沒報錯
從服務器查看日志沒有異常,通過CDH查看日志發現內存不足,在搭建集群時候,Key-Value Store Indexer 與 Solr 都要給夠相關內存,具體大小根據實際情況來測試
Key-Value Store Indexer? 的配置參數:
? ??Lily HBase Indexer 的 Java 堆棧大小(字節)
Solr 的配置參數
總結
以上是生活随笔為你收集整理的CDH 6 安装 Hbase 二级索引 Solr + Key-Value Store Indexer的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 图数据库 HugeGraph : Ind
- 下一篇: Debug和Realease版本的区别