您的位置:首页 > 其它

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

2015-08-12 19:58 537 查看
总结solr的下载、安装、启动和建立索引的过程。

下载:
官网查找最新版本的下载地址:http://lucene.apache.org/solr/

# wget http://mirror.bit.edu.cn/apache/lucene/solr/5.2.1/solr-5.2.1.tgz
解压:
# 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

Creating new collection 'gettingstarted' using command:

http://192.168.0.31:8983/solr/admin/collections?action=CREATE&name=gettingstarted&numShards=2&replicationFactor=2&maxShardsPerNode=2&collection.configName=gettingstarted

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
最后那个参数:文档或文档所在的目录

查看具体的索引结果:
http://192.168.0.31:8983/solr/gettingstarted/browse
其他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"

更多参数说明:/article/2598125.html

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

启动Cloud参考文档:http://lucene.apache.org/solr/quickstart.html

DIH创建索引的方法:
https://cwiki.apache.org/confluence/display/solr/Uploading+Structured+Data+Store+Data+with+the+Data+Import+Handler

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的博客)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: