开发环境说明:

ambari v2.6.1

Solr v5.5.5

笔者使用的ambari来自动化安装的Solr

一、org.apache.solr.common.SolrException

报错:

1
audit_logs_shard0_replica1: org.apache.solr.common.SolrException:org.apache.solr.common.SolrException: /opt/ambari_infra_solr/data/audit_logs_shard0_replica1/data/index/write.lock

分析:

解决方法:

  • 在infra-solr所在机器,执行:chown -R infra-solr:hadoop /opt/ambari_infra_solr/data/
  • 重启infra-solr服务

问题得到解决。

二、Can’t find resource ‘solr-data-config.xml’

报错:

使用Solr web UI上面的dataimport选项时,配置文件会报错:

1
<str>Can't find resource 'solr-data-config.xml' in classpath or '/configs/audit_logs', cwd=/usr/lib/ambari-infra-solr/server</str>

问题分析:

意思就是说,在/configs/audit_logs目录下找不到solr-data-config.xml这个文件。

点击Solr页面的Files选项,确实没有solr-data-config.xml文件。如图所示:

那么这些文件的来源在哪里呢?答案是Zookeeper

SolrCloud是基于SolrZookeeper的分布式搜索方案,它的主要思想是使用Zookeeper作为集群的配置信息中心。所以Collection的配置文件都来源于Zookeeper

解决办法:

Solr为我们提供了一个上传、修改、查看Zookeeper里面Znode信息的脚本,我们可以使用该脚本zkcli.sh来上传solr-data-config.xml文件。该文件路径:/usr/lib/ambari-infra-solr/server/scripts/cloud-scripts/zkcli.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!-- 
文件名称:solr-data-config.xml
文件作用:用于配置mysql相关信息,将mysql数据导入Solr中
-->
<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://node96.xdata:3309/test" user="root" password="root123"/>
<document>
<entity name="mysql_import_solr"
query="select id, name, address from solr_test_info">
<field column="id" name="id" />
<field column="name" name="name" />
<field column="address" name="address" />
</entity>
</document>
</dataConfig>

solr-data-config.xml上传到Zookeeper指定目录,执行下列命令:

1
/usr/lib/ambari-infra-solr/server/scripts/cloud-scripts/zkcli.sh -zkhost node96.xdata:2181,node97.xdata:2181,node98.xdata:2181 -cmd putfile /infra-solr/configs/ranger_audits/solr-data-config.xml solr-data-config.xml

点击页面的Reload按钮,来重新加载配置文件,再次点击Configuration,发现报错消失,solr-data-config.xml内容被显示,问题得到解决。