Docker安装Solr和IK,以及数据导入。

 https://blog.csdn.net/bskfnvjtlyzmv867/article/details/81623416 此链接较本文更简单

一:在docker 中安装Solr

    docker下载solr镜像

docker pull solr

    2.启动solr镜像

docker run --name mysolr  -d -p 18983:8983 -t solr

     1. run 运行容器

     2. -d 代表后台运行

     3. -p 容器端口和宿机端口映射

     4. --name 容器名称

     5. solr 镜像名称

   

    3.新建core

docker exec -it --user=solr mysolr bin/solr create_core -c ik_core

    4.为了方便后续修改配置,将容器 solr 文件拷贝本地 /usr/local/solr/ 路径下

docker cp mysolr:/opt/solr/ /usr/local/ # 容器拷贝宿主机

     5.进入/opt/solr/server/solr-webapp/webapp/WEB-INF/lib添加jar包

        ik-analyzer-7.4.0.jar

        mysql-connector-java-8.0.11.jar

        solr-dataimporthandler-7.4.0.jar

        solr-dataimporthandler-extras-7.4.0.jar

        ik-analyzer-7.4.0.jar地址ik-analyzer

在/usr/local/mysolr/solr/dist文件夹下以下jar包拷贝到/usr/local/solr/server/solr-webapp/webapp/WEB-INF/lib/
solr-dataimporthandler-7.4.0.jar、
solr-dataimporthandler-extras-7.4.0.jar

/usr/local/solr/dist$ 
sudo cp solr-dataimporthandler* /usr/local/solr/server/solr-webapp/webapp/WEB-INF/lib/
  

    6. 将本地 /usr/local/solr/ 路径下jar包 复制到容器 solr 

docker cp  /usr/local/solr/server/solr-webapp/webapp/WEB-INF/lib/solr-dataimporthandler-extr
as-7.4.0.jar  mysolr:/opt/solr/server/solr-webapp/webapp/WEB-INF/lib/solr-dataimporthandler-
extras-7.4.0.jar

docker cp  /usr/local/solr/server/solr-webapp/webapp/WEB-INF/lib/solr-dataimporthandler-7.4.
0.jar  mysolr:/opt/solr/server/solr-webapp/webapp/WEB-INF/lib/solr-dataimporthandler-7.4.0.
jar

docker cp  /usr/local/solr/server/solr-webapp/webapp/WEB-INF/lib/mysql-connector-java-5.1.4
6.jar  mysolr:/opt/solr/server/solr-webapp/webapp/WEB-INF/lib/mysql-connector-java-5.1.46.j
ar

docker cp  /usr/local/solr/server/solr-webapp/webapp/WEB-INF/lib/ik-analyzer-7.4.0.jar  mys
olr:/opt/solr/server/solr-webapp/webapp/WEB-INF/lib/ik-analyzer-7.4.0.jar

    7.进入/opt/solr/server/solr/ik_core/conf,新建data-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<dataConfig>
    <dataSource name="source1" type="JdbcDataSource"
              driver="com.mysql.jdbc.Driver"
              url="jdbc:mysql://***.**.**.**:3306/*****"
              user="****"
              password="******"
              batchSize="-1" />
    <document>
        <entity name="service_info" dataSource="source1"
            query="SELECT id,title,business_type_id,category_id , service_price , service_time,service_desc,service_area,
            cover,click_count,create_by,create_date,del_flag FROM service_info where del_flag = 1">
            <field column='id' name='id' />
            <field column='title' name='title' />
            <field column='business_type_id' name='business_type_id' />
            <field column='category_id' name='category_id' />
            <field column='service_price' name='service_price' />
            <field column='service_time' name='service_time' />
            <field column='service_desc' name='service_desc' />
            <field column='service_area' name='service_area' />
            <field column='cover' name='cover' />
            <field column='click_count' name='click_count' />
            <field column='create_by' name='create_by' />
            <field column='create_date' name='create_date' />
            <field column='del_flag' name='del_flag' />
        </entity>
    </document>
</dataConfig>

    8.配置managed-schema,加入IK分词

<!-- ik分词器 -->
    <fieldType name="text_ik" class="solr.TextField">  
        <analyzer type="index" useSmart="false"  class="org.wltea.analyzer.lucene.IKAnalyzer" />
        <analyzer type="query" useSmart="true"  class="org.wltea.analyzer.lucene.IKAnalyzer" />
    </fieldType> 
    <field name='id' type="string" indexed="true" stored="true"/>
    <field name='title' type="text_ik" indexed="true" stored="true" omitNorms = "false" omitTermFreqAndPositions ="false"/>
    <field name='business_type_id' type="string" indexed="true" stored="true"/>
    <field name='category_id' type="string" indexed="true" stored="true"/>
    <field name='service_price' type="string" indexed="true" stored="true"/>
    <field name='service_time' type="string" indexed="true" stored="true"/>
    <field name='service_desc' type="text_ik" indexed="true" stored="true"/>
    <field name='service_area' type="text_ik" indexed="true" stored="true"/>
    <field name='cover' type="string" indexed="true" stored="true"/>
    <field name='click_count' type="string" indexed="true" stored="true"/>
    <field name='create_by' type="string" indexed="true" stored="true"/>
    <field name='create_date' type="string" indexed="true" stored="true"/>
    <field name='del_flag' type="string" indexed="true" stored="true"/>

   9.配置solrconfig.xml

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">

       <lst name="defaults">

          <str name="config">data-config.xml</str>

       </lst>

</requestHandler>

    10.重启solr容器

docker restart mysolr

   11.登录http://ip:18983/solr/导入数据

 
Docker安装Solr和IK,以及数据导入。
 

     

相关推荐