<div id="article_content" class="article_content">
<p><br> </p> <h3>ElasticSearch的River机制</h3> <p>ElasticSearch自身提供了一个River机制,用于同步数据。</p> <p>这里能够找到官方眼下推荐的River:</p> <p><a target="_blank" href="http://www.elasticsearch.org/guide/en/elasticsearch/rivers/current/">http://www.elasticsearch.org/guide/en/elasticsearch/rivers/current/</a><br> </p> <p>可是官方没有提供HBase的River。</p> <p>事实上ES的River很easy,就是一个用户打包好的jar包,ES负责找到一个node,并启动这个River。假设node失效了。会自己主动找另外一个node来启动这个River。</p><p></p> <p></p> <pre code_snippet_id="520284" snippet_file_name="blog_20141115_1_5215483" name="code" class="java">public interface RiverComponent { RiverName riverName(); } public interface River extends RiverComponent {
/**
* Called whenever the river is registered on a node, which can happen when:
* 1) the river _meta document gets indexed
* 2) an already registered river gets started on a node
*/
void start();
/**
* Called when the river is closed on a node, which can happen when:
* 1) the river is deleted by deleting its type through the delete mapping api
* 2) the node where the river is allocated is shut down or the river gets rerouted to another node
*/
void close();
}</pre><br>
<p></p> <h4>Elasticsearch-HBase-River</h4> <p></p> <p></p> <p>github上有两个相关的项目:</p> <p><a target="_blank" href="https://github.com/mallocator/Elasticsearch-HBase-River">https://github.com/mallocator/Elasticsearch-HBase-River</a><br> </p> <p>这个项目事实上非常easy。在River里用定时器启动一个HBase的Scanner,去扫描数据,并把数据插到ES里。</p><p>和自己手动写代码去扫描差点儿相同。</p> <p><a target="_blank" href="https://github.com/posix4e/Elasticsearch-HBase-River">https://github.com/posix4e/Elasticsearch-HBase-River</a><br> </p> <p>这个项目利用了HBase的Replication机制。模拟了一个Hbase Replication的结点,然后同步数据到ES里。</p> <p>可是这个项目是基于Hbase0.94的,实现的功能有限。</p> <p>Hbase0.94和HBase0.98 的API变化非常大,基本不可用,并且作者也说了不能用于生产环境。</p> <h3>HBase的Relication机制</h3> <p>能够參考官方文档和cloudera的一些博客文章:<br> <a target="_blank" href="http://hbase.apache.org/book.html#cluster_replication">http://hbase.apache.org/book.html#cluster_replication </a><br> <a target="_blank" href="http://blog.cloudera.com/blog/2012/07/hbase-replication-overview-2/">http://blog.cloudera.com/blog/2012/07/hbase-replication-overview-2/</a><br> </p> <p>HBase的Relication机制,事实上和Mysql的同步机制非常像,HBase的每一个Region Server都会有WAL Log,当Put/Delete时。都会先写入到WAL Log里。然后后台有线程会把WAL Log随机发给Slave的Region Server。而Slave的Region Server会在zookeeper上记录自己同步到的位置。</p> <p><br> </p> <h3>HBase同步数据到Solr的方案:Lily HBase Indexer</h3> <p>Cloudera内置的Cloudera Search实际上就是这个Lily Hbase Indexer:</p> <p><a target="_blank" href="https://github.com/NGDATA/hbase-indexer">https://github.com/NGDATA/hbase-indexer </a><br> </p> <p>这个项目就是利用了HBase的Replication功能,把HBase数据改动(Put。Delete)都抽像成为一系列Event,然后就能够同步到Solr里了。</p> <p>这个项目抽象出了一个子项目:HBase Side-Effect Processor。</p> <p><a target="_blank" href="https://github.com/NGDATA/hbase-indexer/blob/master/hbase-sep/README.md">https://github.com/NGDATA/hbase-indexer/blob/master/hbase-sep/README.md</a><br> </p> <p>让用户能够自己写Listener来处理Event。</p><p></p> <p><br> </p> <h3>HBase数据同步到ElasticSearch的终于方案</h3> <p>考虑了上面的东东。所以决定基于HBase Side-Effect Processor。来自己写简单的程序同步数据到ES里。</p> <p>事实上代码是很easy的。參考下Demo里的LoggingConsumer就好了。</p> <p>https://github.com/NGDATA/hbase-indexer/blob/master/hbase-sep/hbase-sep-demo/src/main/java/com/ngdata/sep/demo/LoggingConsumer.java<br> </p> <p></p> <pre code_snippet_id="520284" snippet_file_name="blog_20141115_2_5395135" name="code" class="java"> private static class EventLogger implements EventListener { @Override public void processEvents(List<SepEvent> sepEvents) { for (SepEvent sepEvent : sepEvents) { System.out.println("Received event:"); System.out.println(" table = " + Bytes.toString(sepEvent.getTable())); System.out.println(" row = " + Bytes.toString(sepEvent.getRow())); System.out.println(" payload = " + Bytes.toString(sepEvent.getPayload())); System.out.println(" key values = "); for (KeyValue kv : sepEvent.getKeyValues()) { System.out.println(" " + kv.toString()); } } } }</pre><br> <br> <p></p> <h3>其他的一些东东:</h3> <h4>ElasticSearch 和Solr cloud的比較</h4> <p>从网上找到的帖子,讨论比較多的是12年,貌似后面就比較少了。</p> <p>https://github.com/superkelvint/solr-vs-elasticsearch <br> http://stackoverflow.com/questions/2271600/elasticsearch-sphinx-lucene-solr-xapian-which-fits-for-which-usage <br> </p> <p>http://www.quora.com/Why-Cloudera-search-is-built-on-Solr-and-not-Elasticsearch Cloudera-Search为什么选择Solr而不是ElasticSearch</p> <p><br> </p> <p>个人倾向于ElasticSearch,由于从流行度来看。ES正在超越solr cloud:</p> <p><img src="http://img.blog.csdn.net/20141115155207293?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGVuZ3l1bmFiYw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt=""><br> </p> <p>Logstash + ElasticSearch + Kibana的完整日志收集分析工具链,也有非常多公司在用。</p> <p><br> </p> <p><br> </p>
</div>
来源:oschina
链接:https://my.oschina.net/u/4356599/blog/3549417