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