09、Solr实战:CDH集群配置solrcloud

一、目的

CDH集群配置solr和单机虚拟配置solr还是非常不同的,烦人的目录是很令人头疼。在创建集群实例过程中碰了很多坑,好不容易搭建好,在此记录一下,以防下次采坑。

二、环境

1、 CDH5.15.2;

三、配置步骤

1、 生成collection实例配置文件:;

指定配置文件临时目录

solrctl instancedir --generate /opt/tmp

2、 上传文件到zookeeper,其他节点就可以从zookeeper下载配置文件;

上传命令注意cdh的solr路径

cd /opt/cloudera/parcels/CDH/lib/solr/bin
./zkcli.sh -zkhost ip1:2181,ip2:2181,ip3:2181/solr -cmd upconfig -confdir /opt/tmp/conf -confname myconf

上传文件报错:ERROR Could not read configuration file from URL [file:./log4j.properties],原因是缺少log4j.properties

解决参考博客:https://blog.csdn.net/u010886217/article/details/90091281

3、 创建实例;

solrctl --solr http://ip1:8983/solr/  collection --create collection1 -s 2

(1)报错

<?xml version="1.0" encoding="UTF-8"?> <response> <lst name="responseHeader"> <int name="status"> 0</int> <int name="QTime"> 16140</int> </lst> <lst name="failure"> <str> org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException:Error CREATEing SolrCore 'collection1_shard2_replica1': Unable to create core [collection1_shard2_replica1] Caused by: Could not find configName for collection collection1 found:[managedTemplate, schemalessTemplate, managedTemplateSecure, predefinedTemplate, predefinedTemplateSecure, schemalessTemplateSecure]</str> <str> org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException:Error CREATEing SolrCore 'collection1_shard1_replica1': Unable to create core [collection1_shard1_replica1] Caused by: Could not find configName for collection collection1 found:[managedTemplate, schemalessTemplate, managedTemplateSecure, predefinedTemplate, predefinedTemplateSecure, schemalessTemplateSecure]</str> </lst> </response>

(2)原因:尽管把配置文件上传zookeeper,但是因为创建实例时没有指定配置文件目录,默认是读取zookeeper的/solr/configs下的目录,如下是没有的

[zk: localhost:2181(CONNECTED) 8] ls /solr/configs/
schemalessTemplateSecure   myconf                     managedTemplate            schemalessTemplate         
managedTemplateSecure      predefinedTemplate         predefinedTemplateSecure   

因为上传的配置目录是/solr/configs/myconf

[zk: localhost:2181(CONNECTED) 8] ls /solr/configs/myconf
[currency.xml, mapping-FoldToASCII.txt, protwords.txt, scripts.conf, synonyms.txt, stopwords.txt, velocity, _schema_analysis_synonyms_english.json, admin-extra.html, update-script.js, solrconfig.xml.secure, _schema_analysis_stopwords_english.json, solrconfig.xml, admin-extra.menu-top.html, elevate.xml, schema.xml, clustering, mapping-ISOLatin1Accent.txt, spellings.txt, xslt, _rest_managed.json, lang, admin-extra.menu-bottom.html]

(3)解决:上传指定collection.configName属性

collection.configName=myconf

参考:http://archive.apache.org/dist/lucene/solr/ref-guide/apache-solr-ref-guide-4.10.pdf

(4)具体创建实例命令可以参考

https://blog.csdn.net/u010886217/article/details/90632907

4、 创建实例,指定collection.configName!;

http://i-j3knf9ce:8983/solr/admin/collections?action=CREATE&name=collection1&numShards=1&replicationFactor=2&collection.configName=myconf

成功

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">5134</int>
</lst>
<lst name="success">
<lst>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">4524</int>
</lst>
<str name="core">collection1_shard1_replica1</str>
</lst>
<lst>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">5010</int>
</lst>
<str name="core">collection1_shard1_replica2</str>
</lst>
</lst>
</response>

*

5、 检查;

*

四、总结

1、 所有问题看官方文档;

http://archive.apache.org/dist/lucene/solr/ref-guide/apache-solr-ref-guide-4.10.pdf

2、 CDH真实目录很乱,需要掌握核心目录;

3、 solr的日志位置;

tail -f /var/log/solr/solr-cmf-solr-SOLR_SERVER-...(hostname).log.out
显示
--------10 11:08:28,919 ERROR (OverseerThreadFactory-4-thread-5)-----o.a.s.c.OverseerCollectionMessageHandler: Error from shard: http://i-21jclmdn:8983/solr
org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: Error CREATEing SolrCore 'collection1_shard1_replica1': Unable to create core [collection1_shard1_replica1] Caused by: Could not find configName for collection collection1 found:[managedTemplate, schemalessTemplate, managedTemplateSecure, predefinedTemplate, predefinedTemplateSecure, schemalessTemplateSecure]
at org.apache.solr.client.solrj.impl.HttpSolrServer.executeMethod(HttpSolrServer.java:623)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:229)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:225)
at org.apache.solr.handler.component.HttpShardHandler$1.call(HttpShardHandler.java:158)
at org.apache.solr.handler.component.HttpShardHandler$1.call(HttpShardHandler.java:120)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

版权声明:本文不是「本站」原创文章,版权归原作者所有 | 原文地址: