Requirements
root@pts/6 $ java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
refer to solr system requirements
Installation solr
這篇主要是以單實例Solr為說明
# download new version
wget https://mirrors.tuna.tsinghua.edu.cn/apache/lucene/solr/6.3.0/solr-6.3.0.zip
# init directory about solr
# separate installation folder and data folder
mkdir /TestDisk/solrtest/{installation,data}
# installation
root@pts/6 $ solr-6.3.0/bin/install_solr_service.sh solr-6.3.0.zip \
-d /TestDisk/solrtest/data/ -i /TestDisk/solrtest/installation \
-p 8985 -s lcsolr
Extracting solr-6.3.0.zip to /TestDisk/solrtest/installation
Installing symlink /TestDisk/solrtest/installation/lcsolr -> /TestDisk/solrtest/installation/solr-6.3.0 ...
Installing /etc/init.d/lcsolr script ...
Installing /etc/default/lcsolr.in.sh ...
Service lcsolr installed.
Customize Solr startup configuration in /etc/default/lcsolr.in.sh
Waiting up to 180 seconds to see Solr running on port 8985 [\]
Started Solr server on port 8985 (pid=17625). Happy searching!
Found 1 Solr nodes:
Solr process 17625 running on port 8985
{
"solr_home":"/TestDisk/solrtest/data/data",
"version":"6.3.0 a66a44513ee8191e25b477372094bfa846450316 - shalin - 2016-11-02 19:52:42",
"startTime":"2016-12-26T11:35:08.023Z",
"uptime":"0 days, 0 hours, 0 minutes, 8 seconds",
"memory":"84 MB (%17.1) of 490.7 MB"}
install_solr_service.sh
參數(shù)說明:
安裝腳本自身必須是root
運行才行
- -d solr數(shù)據(jù)數(shù)據(jù)目錄,比如存放logs,pid文件,core目錄等等旬痹。默認(rèn)在
/var/solr
- -i solr程序安裝目錄晨缴,默認(rèn)在
/opt
。安裝目錄必須先創(chuàng)建好远搪。 - -p 執(zhí)行solr綁定的端口劣纲,默認(rèn)是
8983
端口。 - -s solr服務(wù)的名稱谁鳍,默認(rèn)是
solr
癞季。可以指定別的倘潜,比如上面的lcsolr
- -u solr服務(wù)運行或者solr文件擁有者的用戶绷柒,默認(rèn)是
solr
。也只可以指定別的涮因,如果指定的不存在怎會先創(chuàng)建相關(guān)用戶 - -n solr安裝完畢之后不啟動solr服務(wù)
如果對于安裝的時候參數(shù)不熟悉導(dǎo)致的Joke就像 這個錯誤
solr實際啟動之后的主界面如圖
solr-main-page.png
Solr basic usage
create core
創(chuàng)建Core的時候建議用命令行來創(chuàng)建辉巡,這樣會更方便。
因為web界面創(chuàng)建Core蕊退,默認(rèn)要求 installdir
和 datadir
要必須先存在郊楣,而且 要求 solrconfig.xml
也必須能被找到。
語法:
## 因為我使用了不用的端口瓤荔,所以這里加上-p
bin/solr create -c james [-p 8985]
舉例:
root@pts/6 $ su - solr -c '/TestDisk/solrtest/installation/lcsolr/bin/solr create -c james -p 8985'
Copying configuration to new core instance directory:
/TestDisk/solrtest/data/data/james
Creating new core 'james' using command:
http://localhost:8985/solr/admin/cores?action=CREATE&name=james&instanceDir=james
{
"responseHeader":{
"status":0,
"QTime":2119},
"core":"james"}
結(jié)果如下:
solr-core.png
core詳情頁
solr-core-index.png
下面的例子只給出具體的命令净蚤,不做截圖展示
另外給出來的URL
可以在瀏覽器中執(zhí)行,也可以在命令行用如下的方式
curl certain-url
select from core
http://192.168.100.2:8985/solr/james/select?q=id:2031961177&wt=json&indent=true
delete one record from core
http://192.168.100.2:8985/solr/james/update/?stream.body=<delete><id>2031961722</id></delete>&stream.contentType=text/xml;charset=utf-8&commit=true
truncate core
http://192.168.100.2:8985/solr/james/update/?stream.body=<delete><query>*:*</query></delete>&stream.contentType=text/xml;charset=utf-8&commit=true
公眾號: DailyJobOps