一,安裝環境
硬件:虛擬機
操作系統: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}]}]}