溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

在CentOS下安裝Solr5.3

發(fā)布時(shí)間:2020-07-05 01:30:53 來源:網(wǎng)絡(luò) 閱讀:965 作者:UltraSQL 欄目:大數(shù)據(jù)

前言

 

Solr現(xiàn)在是一個(gè)獨(dú)立的服務(wù)器。

從Solr5.0開始,Solr不再發(fā)布為在任何Servlet容器中部署的“war”Web應(yīng)用程序包(Web Application Archive)。Solr現(xiàn)在部署為一個(gè)獨(dú)立的java服務(wù)器應(yīng)用程序,包含在Unix和Windows平臺上可以使用的啟動(dòng)和停止腳本,以及將Solr作為服務(wù)安裝到類Unix平臺的/etc/init.d下的安裝腳本。

本質(zhì)上,Solr仍然以Servlet APIs實(shí)現(xiàn),并在Jetty上運(yùn)行,但只是作為一個(gè)實(shí)現(xiàn)。部署為“webapp”到其他的Servlet容器(或其他Jetty實(shí)例)上不被支持,可能在未來的Solr 5.x版本不會工作。而可能會帶來Solr的其他改變,事實(shí)上是利用自定義網(wǎng)絡(luò)協(xié)議棧功能。


安裝JRE

 

  1. 需要Java Runtime Environment(JRE) 1.7或更高版本,先驗(yàn)證。

    # java -version
  2. 安裝可參考《在CentOS下安裝JDK8》,包含JRE。


安裝Solr5.3

 

  1. 去http://www.apache.org/dyn/closer.lua/lucene/solr/5.3.0下載Solr安裝文件solr-5.3.0.tgz。

  2. 將solr-5.3.0.tgz文件放到/tmp目錄下,執(zhí)行如下腳本:    

    # cd /tmp    
    # tar -zxvf solr-5.3.0.tgz // 解壓壓縮包
  3. 創(chuàng)建應(yīng)用程序和數(shù)據(jù)目錄

    # mkdir -p /data/solr /usr/local/solr
  4. 創(chuàng)建運(yùn)行solr的用戶并賦權(quán)

    # groupadd solr    
    # useradd -g solr solr    
    # chown -R solr.solr /data/solr /usr/local/solr
  5. 安裝solr服務(wù)

    # solr-5.3.0/bin/install_solr_service.sh solr-5.3.0.tgz -d /data/solr -i /usr/local/solr
  6. 檢查服務(wù)狀態(tài)  

    # service solr status

    將會看到如下輸出:  

    Solr process 29692 running on port 8983    
    {    
      "solr_home":"/data/solr/data/",    
      "version":"5.3.0 1696229 - noble - 2015-08-17 17:10:43",    
      "startTime":"2015-09-16T01:32:03.919Z",    
      "uptime":"0 days, 0 hours, 3 minutes, 6 seconds",    
      "memory":"89.8 MB (%18.3) of 490.7 MB"}




solr命令用法

 

  1. 定位到solr應(yīng)用程序目錄 

    # cd /usr/local/solr/solr


  2. 查看solr命令選項(xiàng)

    # ./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
# ./bin/solr start -help
Usage: solr start [-f] [-c] [-h hostname] [-p port] [-d directory] [-z zkHost] [-m memory] [-e example] [-s solr.solr.home] [-a "additional-options"] [-V]
  -f            Start Solr in foreground; default starts Solr in the background                     and sends stdout / stderr to solr-PORT-console.log
  -c or -cloud  Start Solr in SolrCloud mode; if -z not supplied, an embedded ZooKeeper                     instance is started on Solr port+1000, such as 9983 if Solr is bound to 8983
  -h <host>     Specify the hostname for this Solr instance
  -p <port>     Specify the port to start the Solr HTTP listener on; default is 8983                     The specified port (SOLR_PORT) will also be used to determine the stop port                      STOP_PORT=($SOLR_PORT-1000) and JMX RMI listen port RMI_PORT=(1$SOLR_PORT).                       For instance, if you set -p 8985, then the STOP_PORT=7985 and RMI_PORT=18985
  -d <dir>      Specify the Solr server directory; defaults to server
  -z <zkHost>   ZooKeeper connection string; only used when running in SolrCloud mode using -c                      To launch an embedded ZooKeeper instance, don't pass this parameter.
  -m <memory>   Sets the min (-Xms) and max (-Xmx) heap size for the JVM, such as: -m 4g                     results in: -Xms4g -Xmx4g; by default, this script sets the heap size to 512m
  -s <dir>      Sets the solr.solr.home system property; Solr will create core directories under                     this directory. This allows you to run multiple Solr instances on the same host                      while reusing the same server directory set using the -d parameter. If set, the                      specified directory should contain a solr.xml file, unless solr.xml exists in ZooKeeper.                      This parameter is ignored when running examples (-e), as the solr.solr.home depends                      on which example is run. The default value is server/solr.
  -e <example>  Name of the example to run; available examples:         cloud:         SolrCloud example          techproducts:  Comprehensive example illustrating many of Solr's core capabilities          dih:           Data Import Handler          schemaless:    Schema-less example
  -a            Additional parameters to pass to the JVM when starting Solr, such as to setup                     Java debug options. For example, to enable a Java debugger to attach to the Solr JVM                      you could pass: -a "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=18983"                      In most cases, you should wrap the additional parameters in double quotes.
  -noprompt     Don't prompt for input; accept all defaults when running examples that accept user input
  -V            Verbose messages from this script
# ./bin/solr create -help
Usage: solr create [-c name] [-d confdir] [-n configName] [-shards #] [-replicationFactor #] [-p port]
  Create a core or collection depending on whether Solr is running in standalone (core) or SolrCloud     mode (collection). In other words, this action detects which mode Solr is running in, and then takes      the appropriate action (either create_core or create_collection). For detailed usage instructions, do:
    bin/solr create_core -help
       or
    bin/solr create_collection –help

 

安裝solr服務(wù)腳本用法

 

  1. 運(yùn)行安裝腳本

    # /tmp/solr-5.3.0/bin/install_solr_service.sh
ERROR: Must specify the path to the Solr installation archive, such as solr-5.0.0.tgz
Usage: install_solr_service.sh path_to_solr_distribution_archive OPTIONS
  The first argument to the script must be a path to a Solr distribution archive, such as solr-5.0.0.tgz       (only .tgz or .zip are supported formats for the archive)
  Supported OPTIONS include:
    -d     Directory for live / writable Solr files, such as logs, pid files, and index data; defaults to /var/solr
    -i     Directory to extract the Solr installation archive; defaults to /opt/                The specified path must exist prior to using this script.
    -p     Port Solr should bind to; default is 8983
    -s     Service name; defaults to solr
    -u     User to own the Solr files and run the Solr process as; defaults to solr                This script will create the specified user account if it does not exist.
NOTE: Must be run as the root user

 

創(chuàng)建集合

 

在這個(gè)部分,我們創(chuàng)建一個(gè)簡單的Solr集合。


Solr可以有多個(gè)集合,但在這個(gè)示例,我們只使用一個(gè)。使用如下命令,創(chuàng)建一個(gè)新的集合。我們以solr用戶運(yùn)行以避免任何權(quán)限錯(cuò)誤。

# su - solr -c "/usr/local/solr/solr/bin/solr create -c gettingstarted -n data_driven_schema_configs"


在這個(gè)命令中,gettingstarted是集合的名字,-n指定配置集合。Solr默認(rèn)提供了3個(gè)配置集合。這里我們使用的是schemaless,意思是可以提供任意名字的任意列,類型將會被猜測。

Setup new core instance directory:   /data/solr/data/gettingstarted
Creating new core 'gettingstarted' using command:   http://localhost:8983/solr/admin/cores?action=CREATE&name=gettingstarted&instanceDir=gettingstarted
{     "responseHeader":{        "status":0,        "QTime":3247},      "core":"gettingstarted"}


你現(xiàn)在已經(jīng)創(chuàng)建了集合,并可以開始添加數(shù)據(jù)。默認(rèn)的架構(gòu)只需要提供一列:id。沒有其他默認(rèn)列,只有動(dòng)態(tài)列。

 

添加和查詢文檔

 

在這個(gè)部分,我們將瀏覽Solr Web界面,添加一些文檔到集合中。


問你使用Web瀏覽器訪問http://your_server_ip:8983/solr,Solr Web界面將會顯示為:

在CentOS下安裝Solr5.3

這個(gè)Web界面包含大量的有用信息,可以被用于調(diào)試在使用中產(chǎn)生的任何問題。


集合被劃分為核,這就是為什么在Web界面中有大量的對核的參照?,F(xiàn)在,gettingstarted只包含一個(gè)核,名為gettingstarted。在左手邊,可以看到“Core Selector”下拉菜單,我們可以選擇gettingstarted看到更多信息。

在CentOS下安裝Solr5.3

在選擇gettingstarted核之后,選擇“Documents”。文檔存儲可被Solr搜索的真實(shí)數(shù)據(jù)。因?yàn)槲覀兪褂昧艘粋€(gè)無模式的配置,我們可以使用任何列。我使用如下的JSON示例添加了一個(gè)單一文檔,通過拷貝以下到“Documents(s)”列:

{   
    "number": 1,    
    "president": "George Washington",    
    "birth_year": 1732,    
    "death_year": 1799,    
    "took_office": "1789-04-30",    
    "left_office": "1797-03-04",    
    "party": "No Party"    
}

點(diǎn)擊“Submit document”添加文檔到索引。過一會,你會看到如下信息:


添加文檔后的輸出:

Status: success   
Response:    
{    
  "responseHeader": {    
    "status": 0,    
    "QTime": 290    
  }    
}

你可以使用一個(gè)類似的或完全不同的結(jié)構(gòu)添加更多文檔,但你也可以只使用一個(gè)文檔繼續(xù)。


現(xiàn)在,選擇左邊的“Query”去查詢我們剛剛添加的文檔。保持屏幕中的默認(rèn)值,在點(diǎn)擊“Execute Query”之后,你最多看到10個(gè)文檔,依賴于你添加了多少:


查詢輸出

{   
  "responseHeader": {    
    "status": 0,    
    "QTime": 39,    
    "params": {    
      "q": "*:*",    
      "indent": "true",    
      "wt": "json",    
      "_": "1442371884598"    
    }    
  },    
  "response": {    
    "numFound": 1,    
    "start": 0,    
    "docs": [    
      {    
        "number": [    
          1    
        ],    
        "president": [    
          "George Washington"    
        ],    
        "birth_year": [    
          1732    
        ],    
        "death_year": [    
          1799    
        ],    
        "took_office": [    
          "1789-04-30T00:00:00Z"    
        ],    
        "left_office": [    
          "1797-03-04T00:00:00Z"    
        ],    
        "party": [    
          "No Party"    
        ],    
        "id": "b9b294c1-4b68-4d96-adc2-f6fb77f60932",    
        "_version_": 1512437472611532800    
      }    
    ]    
  }    
}


參考:http://lucene.apache.org/solr/quickstart.html


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI