Solr(5.2.1)安装、启动和建立索引

本文详细介绍Solr的下载、安装、启动流程及如何建立索引。包括Cloud模式与Standalone模式启动步骤、查看实例状态、文档索引方法等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

总结solr的下载、安装、启动和建立索引的过程。

下载:
官网查找最新版本的下载地址:http://lucene.apache.org/solr/
解压:
# tar zxvf solr-5.2.1.tgz

如果是下载zip文件,解压:
# unzip solr-5.2.1.zip

确保系统中已经安装了JRE1.7或以上版本

Cloud模式启动:
查看启动命令的参数:
# bin/solr --help
  • -e:example,启动一个自带的实例
  • -noprompt:不提示输入参数,所有都是缺省的

启动一个自带例子(solrCloud):
# bin/solr start -e cloud -noprompt
提示摘要:
Waiting to see Solr listening on port 8983 [/]  
Started Solr server on port 8983 (pid=10344). Happy searching!
Waiting to see Solr listening on port 7574 [/]  
Started Solr server on port 7574 (pid=10502). Happy searching!
Connecting to ZooKeeper at localhost:9983
Uploading /opt/app/solr-5.2.1/server/solr/configsets/data_driven_schema_configs/conf for config gettingstarted to ZooKeeper at localhost:9983

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

上面链接就是Solr的管理界面(把localhost替换成真实ip),如果打不开,可能是端口被防火墙禁用了:

查看端口开放状态:
> iptables -S
添加端口:
> iptables -I INPUT -p tcp --dport 8983 -j ACCEPT 

(SUSE添加防火墙端口):
> vi /etc/sysconfig/SuSEfirewall2
FW_SERVICES_EXT_TCP=”22″中添加端口
> rcSuSEfirewall2 restart


这样,就启动了一个下图的实例:


查看该实例的状态:
# bin/solr healthcheck -c gettingstarted

为文档建索引:
# bin/post -c gettingstarted docs/
或:
# bin/post -c gettingstarted example/exampledocs/*.xml
  • -c gettingstarted:collection
  • 最后那个参数:文档或文档所在的目录

查看具体的索引结果:
其他collection的链接:
http://<ip>:8983/solr/<collection_name>/browse

搜索方法例子:
curl "http://localhost:8983/solr/collection1/select? wt=json&indent=true& q=foundation"
curl "http://localhost:8983/solr/collection1/select? wt=json&indent=true& q=name:foundation"

停止solr:
bin/solr stop -all
删除启动时创建的目录:
rm -Rf example/cloud/


DIH创建索引的方法:

Standalone模式启动:
启动:$ bin/solr start
此时,solr会在后台启动,监听8983端口。启动成功后提示:
Started Solr server on port 8983 (pid=8756). Happy searching!
(注:可能要先修改为可可执行文件:$ chmod +x solr)

查看端口是否已经在监听:$ netstat -lnp

相关命令:
$ bin/solr -help (命令概况)
$ bin/solr start -help (start命令详情)
$ bin/solr start -f (非后台启动)
$ bin/solr start -p 8984 (指定端口启动)
$ bin/solr stop -p 8983 (停止一个后台运行的solr,注:需要指定端口号,停止非后台运行的solr可以用ctrl+c)
$ bin/solr stop -all (停止所有后台运行的solr)
$ bin/solr -e techproducts (启动例子techproducts,可用的例子还有:dih, schemaless, cloud)

访问管理界面 http://<ip>:8983/solr/
注:可能需要先在防火墙中打开8983端口
此时,界面显示“No cores available”,需要创建一个core。

创建一个core:
$ ./solr create -c <name>

创建的core所在路径:./server/solr/<core_name>,solr启动的时候会搜索./server/solr下的子目录,如果其中有core.properties文件,就当做一个core来启动。

加入文件并建立索引:
$ ./post -c <core_name> <file_dir>/<file_name>

(原创文章,转载请注明转自Clement-Xu的博客)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值