CDH6 高版本hbase+solr實現二級索引

之前的環境是單獨下載的CDH組件包搭建的集羣,但是因爲hadoop版本過低導致漏洞無法修復,重新搭建高版本集羣環境。

新集羣環境:

主要組件:hadoop,hbase,zookeeper,Key-Value Store Indexer

 

1.創建hbase表:

hbase shell
create 'users', { NAME => 'info', REPLICATION_SCOPE => '1' } 

2.使用CDH創建solr集合並修改配置:

1)創建solr實體配置文件本地目錄,tsolr會自動創建

# solrctl instancedir --generate /opt/tsolr

創建後會在tsolr目錄下生成一個conf文件夾,裏面是相關配置文件。


2)編輯conf文件夾裏的managed-schema文件,hbase表中需要索引的列對應managed-schema的filed節點
例:
<field name="firstname_s" type="string" indexed="true" stored="true" required="false" multiValued="false" />
   <field name="lastname_s" type="string" indexed="true" stored="true" required="false" multiValued="false" />
   <field name="age_i" type="string" indexed="true" stored="true" required="true" multiValued="false" />

注意:conf中的solrConfig.xml可以設置提交方式。設置方式參考:https://blog.csdn.net/qq_40570699/article/details/100560066


3)創建collection實例並配置文件上傳到zookeeper

# solrctl instancedir --create tsolr /opt/tsolr

注意:之前如果有創建過,需要先刪除再創建,或者覆蓋更新

(# solrctl instancedir --update tsolr /opt/tsolr)


4)上傳到zookeeper之後,其他節點就可以從zookeeper下載配置文件。接着創建collection

# solrctl collection --create tsolr -s 15 -r 2 -m 50
(紅色參數表示s表示設置Shard數爲15,-r表示設置的replica數爲2,-m表示最大shards數目,collection名稱是tsolr!)

3.創建indexer模板,並且執行indexer任務:

1.編輯 vim /opt/tsolr/users.xml
<?xml version="1.0"?>
<indexer table="indexdemo-user">
  <field name="firstname_s" value="info:firstname"/>
  <field name="lastname_s" value="info:lastname"/>
  <field name="age_i" value="info:age" type="int"/>
</indexer>

2.執行hbase-indexer
cd /opt/cloudera/parcels/CDH-6.0.0-xxxxx/bin
../hbase-indexer add-indexer -n myindexer -c demo/user_indexer.xml -cp solr.zk=flzxldyjdata1:2181,flzxldyjdata2:2181,flzxldyjdata3:2181,flzxldyjdata4:2181,flzxldyjdata5:2181/solr -cp solr.collection=collection1

 

發佈了37 篇原創文章 · 獲贊 14 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章