【问题标题】:I cannot index my database with solr. I always get `Indexing failed. Rolled back all changes.`我无法用 solr 索引我的数据库。我总是得到`索引失败。回滚所有更改。`
【发布时间】:2016-10-17 16:15:33
【问题描述】:

我无法使用 solr (4.0) 索引我的 mysql 数据库。我总是得到Indexing failed. Rolled back all changes. 我已经查看了以前的答案,但我无法弄清楚这是什么问题。我在 Docker(乘客 phusion 和 ubuntu 14.04)容器中运行它。有任何想法吗?我已经花了几天时间试图弄清楚这一点。

码头工人撰写

version: '2'

services:
  search:
    env_file: .env
    build: .
    ports:
      - "8080:8080"
    volumes:
      - ~/.m2:/root/.m2
      # - ~/.solr:/data/solr/
      - ./docker:/home/app/docker
  db:
    env_file: .env
    image: mysql:5.6
    ports:
      - "3307:3306"

SOLR_HOME

ls -l /data/solr/collection1/conf/
-rw-r--r-- 1 tomcat7 tomcat7  7601 Oct 17 15:35 data-config.xml
-rw-r--r-- 1 tomcat7 tomcat7     0 Oct 17 15:35 dataimport.properties
-rw-r--r-- 1 tomcat7 tomcat7   561 Oct 17 15:35 log4j.properties
-rw-r--r-- 1 tomcat7 tomcat7   707 Oct 17 15:35 log4j.xml
-rw-r--r-- 1 tomcat7 tomcat7 12302 Oct 17 15:35 schema.xml
-rw-r--r-- 1 tomcat7 tomcat7   479 Oct 17 15:35 solrconfig-qf.xml
-rw-r--r-- 1 tomcat7 tomcat7 41383 Oct 17 15:35 solrconfig.xml
-rw-r--r-- 1 tomcat7 tomcat7   148 Oct 17 15:35 solrcore.properties
-rw-r--r-- 1 tomcat7 tomcat7   138 Oct 17 15:35 solrcore.properties.template

Solr 管理员

data-config.xml https://gist.github.com/anonymous/ce99aa9277f0295a2a52768fb7866e6a

<dataConfig>
  <dataSource name="db" type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/datacite" user="root"
    password="" readonly="true"
    batchSize="-1" />
  <!-- for batchSize=-1 see DIH FAQ -->
  <dataSource name="field" type="FieldReaderDataSource" />
  <document>
    <!-- SOLR-2104 -->
    <!-- using delta import as proposed in http://wiki.apache.org/solr/DataImportHandlerDeltaQueryViaFullImport -->

Sorl 核心属性

mds.db.url=jdbc:mysql://localhost:3306/datacite?useUnicode=true&characterEncoding=UTF8
mds.db.user=datacite
mds.db.password=
mds.testprefix=10.5072

Solrconfig.xml

<!-- AutoCommit

     Perform a hard commit automatically under certain conditions.
     Instead of enabling autoCommit, consider using "commitWithin"
     when adding documents.

     http://wiki.apache.org/solr/UpdateXmlMessages

     maxDocs - Maximum number of documents to add since the last
               commit before automatically triggering a new commit.

     maxTime - Maximum amount of time in ms that is allowed to pass
               since a document was added before automaticly
               triggering a new commit.
     openSearcher - if false, the commit causes recent index changes
     to be flushed to stable storage, but does not cause a new
     searcher to be opened to make those changes visible.
  -->
 <autoCommit>
   <maxTime>15000</maxTime>
   <openSearcher>false</openSearcher>
 </autoCommit>

<!-- softAutoCommit is like autoCommit except it causes a
     'soft' commit which only ensures that changes are visible
     but does not ensure that data is synced to disk.  This is
     faster and more near-realtime friendly than a hard commit.
  -->
 <!--
   <autoSoftCommit>
     <maxTime>1000</maxTime>
   </autoSoftCommit>
  -->

<!-- Update Related Event Listeners

     Various IndexWriter related events can trigger Listeners to
     take actions.

     postCommit - fired after every commit or optimize command
     postOptimize - fired after every optimize command
  -->
<!-- The RunExecutableListener executes an external command from a
     hook such as postCommit or postOptimize.

     exe - the name of the executable to run
     dir - dir to use as the current working directory. (default=".")
     wait - the calling thread waits until the executable returns.
            (default="true")
     args - the arguments to pass to the program.  (default is none)
     env - environment variables to set.  (default is none)
  -->
<!-- This example shows how RunExecutableListener could be used
     with the script based replication...
     http://wiki.apache.org/solr/CollectionDistribution
  -->
<!--
   <listener event="postCommit" class="solr.RunExecutableListener">
     <str name="exe">solr/bin/snapshooter</str>
     <str name="dir">.</str>
     <bool name="wait">true</bool>
     <arr name="args"> <str>arg1</str> <str>arg2</str> </arr>
     <arr name="env"> <str>MYVAR=val1</str> </arr>
   </listener>
  -->

<!-- Enables a transaction log, currently used for real-time get.
     "dir" - the target directory for transaction logs, defaults to the
        solr data directory.  -->
<updateLog>
  <str name="dir">/data/solr/collection1/data</str>
</updateLog>

  <dataDir>/data/solr/collection1/data</dataDir>


  <lib dir="../../../contrib/dataimporthandler/lib/" regex=".*\.jar" />

  <lib dir="../../../dist/" regex="solr-dataimporthandler-\d.*\.jar" />

  <lib dir="../../../lib/" regex="mysql-connector-java-5.0.8-bin.jar" />

  <requestHandler name="/admin/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">
      <str name="config">data-config.xml</str>
    </lst>
    <lst name="invariants">
      <str name="db.url">jdbc:mysql://localhost:3306/datacite?useUnicode=true&amp;amp;characterEncoding=UTF8</str>
      <str name="db.user">root</str>
      <str name="db.password"></str>
      <str name="testprefix">10.5072</str>
    </lst>
  </requestHandler>

【问题讨论】:

  • 您能提供更多信息吗? 1. 日志(整个错误堆栈跟踪,而不仅仅是错误消息)。 2. 您的 SQL 查询 3. 您按照哪些步骤导入数据? 4. 它会立即失败吗? 5. 您希望导入多少条记录。禁用autoSoftCommit,因为它是批量插入(现在它每秒执行一次softCommit)。
  • 看看你的物理内存,你的第二张截图,Solr Admin UI。磁盘快满了。
  • @jay (1) 实际上我无法找到有关该错误的更多信息。 tomcat 日志 (catalina.) 没有显示任何错误,solr 管理界面中的日志始终显示为空,只是一个旋转的轮子。我提到的消息是我得到的唯一反馈。你有什么地方建议我可以看看吗? (3) 对不起,我不知道你在这个问题上是什么意思? (4) 每次我运行 solr full import 时都会失败。它没有索引,索引为空。 (5) 1000s mysql数据库大小为500Mb。谢谢
  • @jay (2) 完整的 [data-config.xml](gist.github.com/anonymous/ce99aa9277f0295a2a52768fb7866e6a)
  • mysql 是否真的在与您的 Solr 安装相同的 docker 容器中运行? 127.0.0.1 可能不是您实际 MySQL 服务器的 ip。您能否从命令行在 Solr 所在的 docker 实例上 连接到 MySQL,并使用提供的详细信息发出查询? (而且 Solr 4.0 已经过时了)

标签: mysql docker solr solr4 dataimporthandler


【解决方案1】:

问题是我没有连接到 mysql 数据库。 mysql 数据库主机错误。感谢@MatsLindh,我弄明白了。

在 docker compose 中,services 的名称是其主机 的名称。因此,就我而言,mysql 数据库主机的名称是db(请参阅上面问题中的 docker compose)。我的错误是我在环境变量中将 mysql 数据库主机的名称设置为 $DB_HOST = localhost。

当我尝试从 solr 容器连接到 mysql 容器时,我意识到了这一点。我不得不这样做

mysql --host=db --user=root --password= datacite

因为

mysql --host=localhost --user=root --password= datacite

没有工作。

就是这样。 在 docker compose 中执行此操作时检查数据库主机的名称。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-15
    • 2013-08-06
    • 2016-10-08
    • 2011-01-06
    • 2011-10-02
    相关资源
    最近更新 更多