一,安装环境
硬件:虚拟机
操作系统:Centos 6.4 64位
IP:10.51.121.10
主机名:datanode-4
安装用户:root
安装系统要求:需要先安装JDK7或者以上版本,推荐JDK7U55或者以后版本。
二,安装JDK7
安装JDK7U55或者以上版本。这里安装JDK1.7.0_75。
下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html
1,下载jdk-7u75-linux-x64.tar.gz,执行:#tar -zxvf jdk-7u75-linux-x64.tar.gz
到/usr/lib目录。解压之后的目录为:/usr/lib/jdk1.7.0_75
2,在/root/.bash_profile中添加如下配置:
export JAVA_HOME=/usr/lib/jdk1.7.0_75 export PATH=$JAVA_HOME/bin:$PATH
3,使环境变量生效#source ~/.bash_profile
4,安装验证# java -version
java version “1.7.0_75”
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)
三,安装Solr
1,下载Solr5.0,下载URL:http://archive.apache.org/dist/lucene/solr/5.0.0/solr-5.0.0.tgz
2,执行:#tar -zxvf solr-5.0.0.tgz
到/root/nutch目录。解压之后的目录为:/root/nutch/solr-5.0.0
四,启动Solr服务
1,进入solr的安装目录,/root/nutch/solr-5.0.0
2,执行,#./bin/solr start -e cloud -noprompt
Welcome to the SolrCloud example!
Starting up 2 Solr nodes for your example SolrCloud cluster.
…
Started Solr server on port 8983 (pid=8404). Happy searching!
…
Started Solr server on port 7574 (pid=8549). Happy searching!
…
SolrCloud example running, please visit http://localhost:8983/solr
Solr在2个节点上运行,一个端口是8983,另一个端口是7574。并自动建立了名称为gettingstarted的collection,此collection有2个shard,每个shard有replicas。
3,在浏览器中输入:http://10.51.121.10:8983/solr/
四,建立索引
指定需要建立索引数据源,数据源可以是HTML, PDF, Microsoft Office 文件(比如 MS Word、Excel),平面文件等。
这里为solr安装目录下的docs文件夹中的文件建立索引。
1,执行#bin/post -c gettingstarted docs/
#bin/post -c gettingstarted docs/ java -classpath /solr-5.0.0/dist/solr-core-5.0.0.jar -Dauto=yes -Dc=gettingstarted -Ddata=files -Drecursive=yes org.apache.solr.util.SimplePostTool docs/ SimplePostTool version 5.0.0 Posting files to [base] url http://localhost:8983/solr/gettingstarted/update... Entering auto mode. File endings considered are xml,json,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log Entering recursive mode, max depth=999, delay=0s Indexing directory docs (3 files, depth=0) POSTing file index.html (text/html) to [base]/extract POSTing file quickstart.html (text/html) to [base]/extract POSTing file SYSTEM_REQUIREMENTS.html (text/html) to [base]/extract Indexing directory docs/changes (1 files, depth=1) POSTing file Changes.html (text/html) to [base]/extract ... 3254 files indexed. COMMITting Solr index changes to http://localhost:8983/solr/gettingstarted/update... Time spent: 0:02:27.712
2,为xml文件建立索引
#bin/post -c gettingstarted example/exampledocs/*.xml
3,为JSON文件建立索引
#bin/post -c gettingstarted example/exampledocs/*.json
4,为CSV文件建立索引
#bin/post -c gettingstarted example/exampledocs/books.csv
五,搜索
Solr可以通过REST 客户端,cURL命令,wget命令等方式来访问搜索。
1,进入http://10.51.121.10:8983/solr,选择gettingstarted_shard1_replica2,点击Query Tab,在q输入域中输入”solr”,然后点击”Execute Query”按钮,这时可以查到内容为solr的文件。
2,在Linux Shell中用cURL访问,比如:
# curl "http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=foundation"
# curl "http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=foundation" { "responseHeader":{ "status":0, "QTime":26, "params":{ "indent":"true", "q":"foundation", "wt":"json"}}, "response":{"numFound":3105,"start":0,"maxScore":0.13157843,"docs":[ { "id":"UTF8TEST", "name":["Test with some UTF-8 encoded characters"], "manu":["Apache Software Foundation"], "cat":["software", "search"], ......
3,访问http://10.51.121.10:8983/solr/gettingstarted/browse。
六,常用命令
1,solr命令有start, stop, restart, status, healthcheck, create, create_core, create_collection, delete。
# ./bin/solr
Usage: solr COMMAND OPTIONS
where COMMAND is one of: start, stop, restart, status, healthcheck, create, create_core, create_collection, delete Standalone server example (start Solr running in the background on port 8984): ./solr start -p 8984 SolrCloud example (start Solr running in SolrCloud mode using localhost:2181 to connect to ZooKeeper, with 1g max heap size and remote Java debug options enabled): ./solr start -c -m 1g -z localhost:2181 -a "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044" Pass -help after any COMMAND to see command-specific usage information, such as: ./solr start -help or ./solr stop -help
2,healthcheck命令
[root@datanode-4 solr-5.0.0]# bin/solr healthcheck -c gettingstarted { "collection":"gettingstarted", "status":"healthy", "numDocs":3296, "numShards":2, "shards":[ { "shard":"shard1", "status":"healthy", "replicas":[ { "name":"core_node2", "url":"http://10.51.121.10:8983/solr/gettingstarted_shard1_replica2/", "numDocs":1633, "status":"active", "uptime":"0 days, 0 hours, 42 minutes, 6 seconds", "memory":"36.9 MB (%7.5) of 490.7 MB"}, { "name":"core_node4", "url":"http://10.51.121.10:7574/solr/gettingstarted_shard1_replica1/", "numDocs":1633, "status":"active", "uptime":"0 days, 0 hours, 41 minutes, 44 seconds", "memory":"83.2 MB (%17) of 490.7 MB", "leader":true}]}, { "shard":"shard2", "status":"healthy", "replicas":[ { "name":"core_node1", "url":"http://10.51.121.10:8983/solr/gettingstarted_shard2_replica2/", "numDocs":1663, "status":"active", "uptime":"0 days, 0 hours, 42 minutes, 6 seconds", "memory":"37.1 MB (%7.6) of 490.7 MB"}, { "name":"core_node3", "url":"http://10.51.121.10:7574/solr/gettingstarted_shard2_replica1/", "numDocs":1663, "status":"active", "uptime":"0 days, 0 hours, 41 minutes, 44 seconds", "memory":"83.3 MB (%17) of 490.7 MB", "leader":true}]}]}