配置solr过程中遇到的问题及解决方法


1.由于缺少solr源文件报错

4718 [coreLoadExecutor-4-thread-1] WARN  org.apache.solr.core.SolrResourceLoader  ? Can’t find (or read) directory to add to classloader: ../../../contrib/extraction/lib (resolved as: /home/apache-tomcat-6.0.37/solrhome/solr/collection1/../../../contrib/extraction/lib).
4718 [coreLoadExecutor-4-thread-1] WARN  org.apache.solr.core.SolrResourceLoader  ? Can’t find (or read) directory to add to classloader: ../../../dist/ (resolved as: /home/apache-tomcat-6.0.37/solrhome/solr/collection1/../../../dist).
4718 [coreLoadExecutor-4-thread-1] WARN  org.apache.solr.core.SolrResourceLoader  ? Can’t find (or read) directory to add to classloader: ../../../contrib/clustering/lib/ (resolved as: /home/apache-tomcat-6.0.37/solrhome/solr/collection1/../../../contrib/clustering/lib).
4719 [coreLoadExecutor-4-thread-1] WARN  org.apache.solr.core.SolrResourceLoader  ? Can’t find (or read) directory to add to classloader: ../../../dist/ (resolved as: /home/apache-tomcat-6.0.37/solrhome/solr/collection1/../../../dist).
4719 [coreLoadExecutor-4-thread-1] WARN  org.apache.solr.core.SolrResourceLoader  ? Can’t find (or read) directory to add to classloader: ../../../contrib/langid/lib/ (resolved as: /home/apache-tomcat-6.0.37/solrhome/solr/collection1/../../../contrib/langid/lib).
4719 [coreLoadExecutor-4-thread-1] WARN  org.apache.solr.core.SolrResourceLoader  ? Can’t find (or read) directory to add to classloader: ../../../dist/ (resolved as: /home/apache-tomcat-6.0.37/solrhome/solr/collection1/../../../dist).
4719 [coreLoadExecutor-4-thread-1] WARN  org.apache.solr.core.SolrResourceLoader  ? Can’t find (or read) directory to add to classloader: ../../../contrib/velocity/lib (resolved as: /home/apache-tomcat-6.0.37/solrhome/solr/collection1/../../../contrib/velocity/lib).
4720 [coreLoadExecutor-4-thread-1] WARN  org.apache.solr.core.SolrResourceLoader  ? Can’t find (or read) directory to add to classloader: ../../../dist/ (resolved as: /home/apache-tomcat-6.0.37/solrhome/solr/collection1/../../../dist).
4720 [coreLoadExecutor-4-thread-1] WARN  org.apache.solr.core.SolrResourceLoader  ? Can’t find (or read) directory to add to classloader: /non/existent/dir/yields/warning (resolved as: /non/existent/dir/yields/warning).
4863 [coreLoadExecutor-4-thread-1] INFO  org.apache.solr.core.SolrConfig  ? Using Lucene MatchVersion: LUCENE_43
解决方法是把solr源文件包里面的文件夹contrib和dist复制到tomcat根目录下就行了。

[root@solr solr-4.3.1]# pwd
/home/solr-4.3.1
[root@solr solr-4.3.1]# ls
CHANGES.txt  contrib  dist  docs  example  licenses  LICENSE.txt  NOTICE.txt  README.txt  SYSTEM_REQUIREMENTS.txt

[root@solr solr-4.3.1]# cp -rf contrib/ dist/ /home/apache-tomcat-6.0.37/

2.由于缺少mmseg4j库文件报错如下:

org.apache.solr.common.SolrException: Plugin init failure for [schema.xml] fieldType "text_cn": Plugin init failure for [schema.xml] analyzer/tokenizer: Error loading class ’com.chenlb.mmseg4j.solr.MMSe
gTokenizerFactory’
at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:177)
at org.apache.solr.schema.IndexSchema.readSchema(IndexSchema.java:476)
at org.apache.solr.schema.IndexSchema.<init>(IndexSchema.java:176)
at org.apache.solr.schema.ClassicIndexSchemaFactory.create(ClassicIndexSchemaFactory.java:62)
at org.apache.solr.schema.IndexSchemaFactory.buildIndexSchema(IndexSchemaFactory.java:36)
at org.apache.solr.core.CoreContainer.createFromZk(CoreContainer.java:893)
at org.apache.solr.core.CoreContainer.create(CoreContainer.java:982)
at org.apache.solr.core.CoreContainer$2.call(CoreContainer.java:597)
at org.apache.solr.core.CoreContainer$2.call(CoreContainer.java:592)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.apache.solr.common.SolrException: Plugin init failure for [schema.xml] analyzer/tokenizer: Error loading class ’com.chenlb.mmseg4j.solr.MMSegTokenizerFactory’
at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:177)
at org.apache.solr.schema.FieldTypePluginLoader.readAnalyzer(FieldTypePluginLoader.java:362)
at org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:86)
at org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:43)
at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
... 16 more
Caused by: org.apache.solr.common.SolrException: Error loading class ’com.chenlb.mmseg4j.solr.MMSegTokenizerFactory’
at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:464)
at org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:558)
at org.apache.solr.schema.FieldTypePluginLoader$2.create(FieldTypePluginLoader.java:342)
at org.apache.solr.schema.FieldTypePluginLoader$2.create(FieldTypePluginLoader.java:335)
at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
... 20 more
解决方法是

下载mmseg4j包放到solr工程目录库中比如我的是/home/apache-tomcat-6.0.37/webapps/solr/WEB-INF/lib/

下载地址:https://code.google.com/p/mmseg4j/downloads/list

solr4.0以下版本请下载mmseg4j1.8.5以下版本,解压后复制文件mmseg4j-all-1.8.5.jar到apache-tomcat-6.0.37/webapps/solr/WEB-INF/lib/下面

solr4.0以上版本请下载mmseg4j1.9.0以上版本,解压后复制文件mmseg4j-analysis-1.9.1.jar  mmseg4j-core-1.9.1.jar  mmseg4j-solr-1.9.1.jar到apache-tomcat-6.0.37/webapps/solr/WEB-INF/lib/下面

然后重新启动tomcat即可解决。

如果版本不按上面说的配置有可能报下面的错误:

4727 [coreLoadExecutor-4-thread-1] ERROR org.apache.solr.core.CoreContainer  ?.null:java.lang.NoClassDefFoundError: org/apache/solr/analysis/BaseTokenizerFactory
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2854)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
at java.lang.ClassLoader.loadClass(ClassLoader.java:410)
at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:789)
at java.lang.ClassLoader.loadClass(ClassLoader.java:410)
at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:789)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:266)
at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:448)
at org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:558)
at org.apache.solr.schema.FieldTypePluginLoader$2.create(FieldTypePluginLoader.java:342)
at org.apache.solr.schema.FieldTypePluginLoader$2.create(FieldTypePluginLoader.java:335)
at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
at org.apache.solr.schema.FieldTypePluginLoader.readAnalyzer(FieldTypePluginLoader.java:362)
at org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:86)
at org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:43)
at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
at org.apache.solr.schema.IndexSchema.readSchema(IndexSchema.java:476)
at org.apache.solr.schema.IndexSchema.<init>(IndexSchema.java:176)
at org.apache.solr.schema.ClassicIndexSchemaFactory.create(ClassicIndexSchemaFactory.java:62)
at org.apache.solr.schema.IndexSchemaFactory.buildIndexSchema(IndexSchemaFactory.java:36)
at org.apache.solr.core.CoreContainer.createFromZk(CoreContainer.java:893)
at org.apache.solr.core.CoreContainer.create(CoreContainer.java:982)
at org.apache.solr.core.CoreContainer$2.call(CoreContainer.java:597)
at org.apache.solr.core.CoreContainer$2.call(CoreContainer.java:592)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: org.apache.solr.analysis.BaseTokenizerFactory
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
... 38 more
这是因为4.0以上的版本要适配mmseg4j1.9.0以上版本

3.由于solr找不到数据文件报错

[http-8080-1] ERROR org.apache.solr.servlet.SolrDispatchFilter  ?.null:org.apache.solr.common.SolrException: SolrCore ’collection1’ is not available due to init failure: Plugin init failure for 

请检查放在solrhome下面的配置文件solr.xml

  <cores adminPath="/admin/cores" defaultCoreName="collection1" host="${host:172.18.84.57}" hostPort="${jetty.port:8080}" hostContext="${hostContext:solr}" zkClientTimeout="${zkClientTimeout:15000}">
    <core name="collection1" instanceDir="collection1" />
  </cores>
标红的是您的core文件夹名称,确认和实际的一样,一般在这个文件夹下面:

[root@solr solr]# pwd
/home/apache-tomcat-6.0.37/solrhome/solr
[root@solr solr]# ls
backup  bin  collection1  README.txt  solr.xml  zoo.cfg
修改成一致并确保有权限读取和执行就行。

4.应该注意的是要把solr源文件里面的jar包尽量都复制到apache-tomcat-6.0.37/webapps/solr/WEB-INF/lib/下面以免由于缺少jar包而无法正常运行。

总结:遇到问题一个一个的解决不怕问题多就怕你没思路。要冷静对待一个一个的突破,按照自己的思路一个一个来再蛋疼的问题都能解决。

QQ截图20131107111056.pngQQ截图20131107111041.png


Whatever is worth doing is worth doing well.