Linux(CentOS)上安裝使用solr6.X

Linux(CentOS)上安裝使用solr6.X

安裝solr

1.下載tgz包linux

方法一:apache

在本地先下載tgz包,而後經過ssh工具上傳到linux服務器上指定的路徑中.服務器

方法二:app

使用命令:wget 下載地址直接經過服務器到網上下載less

 

下載solr的tgz包的路徑:ssh

http://apache.fayea.com/lucene/solr/5.5.3/solr-5.5.3.tgz  5.x版本socket

http://apache.fayea.com/lucene/solr/6.3.0/solr-6.3.0.tgz  6.x版本ide

(因爲外國網站下載慢,這裏有個我雲盤的安裝包:http://pan.baidu.com/s/1pLexOmR工具

2.解壓網站

命令:tar zxvf solr的tgz包路徑

解壓完後會出現一個solr的文件夾

 

3.建立應用程序和數據目錄

# mkdir -p /data/solr /usr/local/solr -- /data/solr是數據目錄  /usr/local/solr是程序目錄

4.建立運行solr的用戶並賦權

# groupadd solr      -- 建立solr用戶組

# useradd -g solr solr    -- 建立用戶並指定用戶組

# chown -R solr.solr /data/solr /usr/local/solr -- 將文件夾之中的文件擁有者改爲指定的用戶

5.安裝solr服務

# solr-5.3.0/bin/install_solr_service.sh solr-5.3.0.tgz -d /data/solr -i /usr/local/solr

6.檢查服務狀態 

# service solr status

 

使用solr

查看solr命令選項

# ./bin/solr

 

Solr命令格式:

#./solr option[參數]  

示例:

#./solr start -p 8984  --使用指定的端口號啓動solr服務

# ./solr start -help

格式: 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 : 在前臺啓動solr服務;默認是在後臺啓動的

  -c / -cloud : 使用solrColud模式啓動solr服務,若是沒有提供-z選項,那麼一個嵌入式的zookeeper實例將以solr的port號加1000位端口號啓動,如9983,10083

  -h <host>: 指定solr實例的主機名

  -p <port>: 指定solr啓動的端口號,默認是8983,也將用來進站口stop_port =($ solr_port-1000)和JMX RMI監聽端口rmi_port =(1+$solr_port)。例如,若是你設置P 8985,而後stop_port = 7985 rmi_port = 18985

  -d <dir>: 指定Solr服務器目錄;

  -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

#.bin/solr create_core -help

Usage: solr create_core [-c core] [-d confdir] [-p port]

  -c <core> :待建立的core索引庫的名稱

  -d <confdir>:  Configuration directory to copy when creating the new core, built-in options are:

    basic_configs: Minimal Solr configuration data_driven_schema_configs: Managed schema with field-guessing support enabled sample_techproducts_configs: Example configuration with many optional features enabled to demonstrate the full power of Solr If not specified, default is: data_driven_schema_configs Alternatively, you can pass the path to your own configuration directory instead of using one of the built-in configurations, such as: bin/solr create_core -c mycore -d /tmp/myconfig

-p <port>     Port of a local Solr instance where you want to create the new core If not specified, the script will search the local system for a running Solr instance and will use the port of the first server it finds.

#./bin/solr create_collection –help

Usage: solr create_collection [-c collection] [-d confdir] [-n configName] [-shards #] [-replicationFactor #] [-p port]

  -c <collection>         Name of collection to create

  -d <confdir>            Configuration directory to copy when creating the new collection, built-in options are:

      basic_configs: Minimal Solr configuration  data_driven_schema_configs: Managed schema with field-guessing support enabled sample_techproducts_configs: Example configuration with many optional features enabled to demonstrate the full power of Solr If not specified, default is: data_driven_schema_configs. Alternatively, you can pass the path to your own configuration directory instead of using one of the built-in configurations, such as: bin/solr create_collection -c mycoll -d /tmp/myconfig .By default the script will upload the specified confdir directory into Zookeeper using the same name as the collection (-c) option. Alternatively, if you want to reuse an existing directory or create a confdir in Zookeeper that can be shared by multiple collections, use the -n option

  -n <configName>  Name the configuration directory in Zookeeper; by default, the configurationwill be uploaded to Zookeeper using the collection name (-c), but if you want to use an existing directory or override the name of the configuration in Zookeeper, then use the -c option.

  -shards <#>    Number of shards to split the collection into; default is 1

  -replicationFactor <#>  Number of copies of each document in the collection, default is 1 (no replication)

  -p <port>               Port of a local Solr instance where you want to create the new collection If not specified, the script will search the local system for a running Solr instance and will use the port of the first server it finds.

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

Copying configuration to 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":3481},

  "core":"gettingstarted"}

 

界面操做solr core

添加數據:

 

 

選中documents,進到操做對話框中,將指定格式的數據輸到Documents輸入框中,點擊submit便可新增索引.

成功提示:

查詢數據:

選中Query,在操做對話框中點擊Execute Query便可查詢指定條件的全部索引

 

刪除數據:

Documents中輸入:<delete><query>*:*</query></delete><commit/>

-- 刪除查詢到的索引

 

修改數據

和增長數據是同樣的操做,不過id已經存在,這時就會作更新

更新前:

 

更新語句:

 

更新後:

 

代碼的操做見:https://my.oschina.net/wxdl/blog/698922

分詞器的集成

下載分詞器,能夠參考https://my.oschina.net/wxdl/blog/698601

將下載好的分詞器上傳到linux服務器中solr安裝目錄下的

 

打開分詞器的jar包(用zip打開),找到如下3個文件:

 

將這3個文件拷貝到WEB-INF下的classes目錄中:

 

注:classes目錄不必定會有,沒有的時候本身建立

分詞器的使用

集成以後能夠到索引庫的conf目錄下的配置文件中配置FieldType:

而後到界面上從新reload一下:

這時應該就生效了:

 

相關文章
相關標籤/搜索