solr7.2.1自带jetty的搭建

solr7 搭建

  • solr7 搭建
    • 下载解压
    • 建立中文分词器
    • 数据库导入
    • 以cloud模式启动
    • solr常用命令

下载解压

wget http://archive.apache.org/dist/lucene/solr/7.2.1/solr-7.2.1.zip


建立中文分词器

  • 找到lucene-analyzers-smartcn-7.2.1.jar并复制到webapp的lib目录下
[root@localhost ~]# cd /usr/local/solr-7.2.1/contrib/analysis-extras/lucene-libs/
[root@localhost ~]# cp lucene-analyzers-smartcn-7.2.1.jar /usr/local/solr-7.2.1/server/solr-webapp/webapp/WEB-INF/lib
  • 修改managed-shchema
[root@localhost ~]# cd /usr/local/solr-7.2.1/server/solr/configsets/_default/conf
[root@localhost conf]# vim managed-schema 

在最后加入如下配置

    
    <fieldType name="solr_cnAnalyzer" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/>
      analyzer>
      <analyzer type="query">
        <tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/>
      analyzer>
    fieldType>

数据库导入

  • 备份_default文件夹
[root@localhost solr-7.2.1]# cd /usr/local/solr-7.2.1/server/solr/configsets/
[root@localhost configsets]# cp -r _default _default-old
  • 修改_default/conf/solrconfig.xml
[root@localhost configsets]# vim _default/conf/solrconfig.xml

添加如下:
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
      <lst name="defaults">
        <str name="config">db-data-config.xmlstr>
      lst>
requestHandler>

solr7.2.1自带jetty的搭建_第1张图片

  • conf目录建立一个db-data-config.xml文件
   
   
       
   
    

<dataConfig>
    <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/taotao" user="root" password="" />
    <document>
        <entity name="bless" 
                query="SELECT a.id,a.title,a.sell_point,a.price,a.image,b.`name` category_name,c.item_desc
        FROM tb_item a
        LEFT JOIN tb_item_cat b ON a.cid = b.id
        LEFT JOIN tb_item_desc c ON a.id = c.item_id
        WHERE a.`status` = 1"
                deltaQuery="select id from tb_item where created > '${dataimporter.last_index_time}'">
            <field column="item_title" name="title" />
            <field column="item_sell_point" name="sellPoint" />
            <field column="item_price" name="price" />
            <field column="item_image" name="image" />
            <field column="item_price" name="price" />
            <field column="item_category_name" name="categoryName" />
            <field column="item_desc" name="itemDesc" />
        entity>
    document>
dataConfig>
  • 找到dist/solr-dataimporthandler-7.2.1.jar和你项目中mysql驱动包复制到solr-7.2.1/server/solr-webapp/webapp/WEB-INF/lib下
    solr7.2.1自带jetty的搭建_第2张图片

以cloud模式启动

  • 发现./solr start -e cloud报错后改用./solr start -e cloud -force
[root@localhost solr-7.2.1]# cd bin
[root@localhost bin]# ./solr start -e cloud

Welcome to the SolrCloud example!

This interactive session will help you launch a SolrCloud cluster on your local workstation.
To begin, how many Solr nodes would you like to run in your local cluster? (specify 1-4 nodes) [2]: 

Ok, let's start up 2 Solr nodes for your example SolrCloud cluster.
Please enter the port for node1 [8983]: 
[回车]
Please enter the port for node2 [7574]: 
[回车]
Creating Solr home directory /usr/local/solr-7.2.1/example/cloud/node1/solr
Cloning /usr/local/solr-7.2.1/example/cloud/node1 into
   /usr/local/solr-7.2.1/example/cloud/node2

Starting up Solr on port 8983 using command:
"/usr/local/solr-7.2.1/bin/solr" start -cloud -p 8983 -s "/usr/local/solr-7.2.1/example/cloud/node1/solr"

WARNING: Starting Solr as the root user is a security risk and not considered best practice. Exiting.
         Please consult the Reference Guide. To override this check, start with argument '-force'

ERROR: Failed to start Solr using command: "/usr/local/solr-7.2.1/bin/solr" start -cloud -p 8983 -s "/usr/local/solr-7.2.1/example/cloud/node1/solr" Exception : org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)

[root@localhost bin]# ./solr start -e cloud -force

Welcome to the SolrCloud example!

This interactive session will help you launch a SolrCloud cluster on your local workstation.
To begin, how many Solr nodes would you like to run in your local cluster? (specify 1-4 nodes) [2]: 
[回车]
Ok, let's start up 2 Solr nodes for your example SolrCloud cluster.
Please enter the port for node1 [8983]: 
[回车]
Please enter the port for node2 [7574]: 
[回车]
Solr home directory /usr/local/solr-7.2.1/example/cloud/node1/solr already exists.
/usr/local/solr-7.2.1/example/cloud/node2 already exists.

Starting up Solr on port 8983 using command:
"/usr/local/solr-7.2.1/bin/solr" start -cloud -p 8983 -s "/usr/local/solr-7.2.1/example/cloud/node1/solr" -force

Waiting up to 180 seconds to see Solr running on port 8983 [\]  
Started Solr server on port 8983 (pid=8058). Happy searching!

Starting up Solr on port 7574 using command:
"/usr/local/solr-7.2.1/bin/solr" start -cloud -p 7574 -s "/usr/local/solr-7.2.1/example/cloud/node2/solr" -z localhost:9983 -force

Waiting up to 180 seconds to see Solr running on port 7574 [|]  
Started Solr server on port 7574 (pid=8251). Happy searching!
                                                                                                              INFO  - 2018-02-19 21:43:23.535; org.apache.solr.client.solrj.impl.ZkClientClusterStateProvider; Cluster at localhost:9983 ready

Now let's create a new collection for indexing documents in your 2-node cluster.
Please provide a name for your new collection: [gettingstarted] 
taotao[输入名称并回车]
How many shards would you like to split taotao into? [2]
[回车]
How many replicas per shard would you like to create? [2] 
[回车]
Please choose a configuration for the taotao collection, available options are:
_default or sample_techproducts_configs [_default] 
[回车]
Created collection 'taotao' with 2 shard(s), 2 replica(s) with config-set 'taotao'

Enabling auto soft-commits with maxTime 3 secs using the Config API

POSTing request to Config API: http://localhost:8983/solr/taotao/config
{"set-property":{"updateHandler.autoSoftCommit.maxTime":"3000"}}
Successfully set-property updateHandler.autoSoftCommit.maxTime to 3000


SolrCloud example running, please visit: http://localhost:8983/solr 


solr常用命令

启动start
bin/solr start  -help    查看start帮助
bin/solr start        启动单机版
bin/solr start -f           前台启动
bin/solr start -p 8984        指定端口启动
bin/solr start -cloud        启动分布式版本
bin/solr start -e cloud -noprompt         -e表示要启动一个现有的例子,例子名称是cloud,cloud这个例子是以SolrCloud方式启动的
bin/solr restart          重启项目
create
如果是单机版要创建core,如果是分布式的要创建collection
bin/solr create -help     查看create帮助
bin/solr create -c abc
        abc是core或collection的名字,取决于solr是单机版还是cloud版本;刷新http://localhost:8983/solr ,可以看到core selector中多了一个abc
        abc目录的位置创建在solr.solr.home(默认是solr的server/solr目录)目录下

post提交数据生成索引
bin/post -c abc docs/
        向名为abc的core或collection提交数据,数据源在docs/目录中

删除
bin/solr delete -c abc     删除一个core或collection

删除索引
bin/post -c abc  -d "/home/matthewi/software/solr-5.4.1/docs/solr-morphlines-core/allclasses-noframe.html"
重新执行上面的搜索可以看到搜索结果的数量少了一条:numFound列

bin/post -c abc -d "*:*"
删除所有数据

停止solr
bin/solr stop -all

状态
bin/solr status

你可能感兴趣的:(搭建安装)