Solr是一个高性能,采用Java5开发,基于Lucene的全文搜索服务器。同时对其进行了扩展,提供了比Lucene更为丰富的查询语言,同时实现了可配置、可扩展并对查询性能进行了优化,并且提供了一个完善的功能管理界面,是一款非常优秀的全文搜索引擎。它是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口。用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文件,生成索引;也可以通过Http Get操作提出查找请求,并得到XML格式的返回结果。
1、下载

[root@hdp01 ~]# wget http://mirrors.hust.edu.cn/apache/lucene/solr/7.2.0/solr-7.2.0.tgz
--将安装脚本install_solr_service.sh解压出来
[root@hdp01 ~]# tar -xzf solr-7.2.0.tgz solr-7.2.0/bin/install_solr_service.sh --strip-components=2

2、安装
必须使用root用户进行安装。

[root@hdp01 ~]# ./install_solr_service.sh /u02/software/solr/solr-7.2.0.tgz -i /u01/solr -d /u01/solr/data/ -p 8983 -u hadoop -s solr

Stopping Solr instance if exists ...

/u01/solr not found! Please check the SOLR_INSTALL_DIR setting in your /etc/init.d/solr script.

Extracting /u02/software/solr/solr-7.2.0.tgz to /u01/solr
Installing symlink /u01/solr/solr -> /u01/solr/solr-7.2.0 ...
Installing /etc/init.d/solr script ...
Service solr installed.
Customize Solr startup configuration in /etc/default/solr.in.sh
Warning: Available entropy is low. As a result, use of the UUIDField, SSL, or any other features that require
RNG might not work properly. To check for the amount of available entropy, use 'cat /proc/sys/kernel/random/entropy_avail'.

Waiting up to 180 seconds to see Solr running on port 8983 [\]  
Started Solr server on port 8983 (pid=1814). Happy searching!

Found 1 Solr nodes: 

Solr process 1814 running on port 8983
{
  "solr_home":"/u01/solr/data/data",
  "version":"7.2.0 bca54cad5a9f6a80800944fd5bd585b68acde8c8 - jpountz - 2017-12-14 16:17:54",
  "startTime":"2017-12-29T06:52:21.126Z",
  "uptime":"0 days, 0 hours, 0 minutes, 8 seconds",
  "memory":"43.4 MB (%8.8) of 490.7 MB"}

-i :表示solr文件夹要释放的地址
-d:表示solr相关数据的存放地址
-u:是指用户,默认为solr,这里使用hadoop
-s:表示服务器名称,默认为solr
安装的过程中,会在系统创建solr服务并启动。

[root@hdp01 u01]# systemctl status solr.service
● solr.service - LSB: Controls Apache Solr as a Service
   Loaded: loaded (/etc/rc.d/init.d/solr; bad; vendor preset: disabled)
   Active: active (exited) since Fri 2017-12-29 15:01:08 CST; 4min 50s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 3460 ExecStop=/etc/rc.d/init.d/solr stop (code=exited, status=0/SUCCESS)
  Process: 3626 ExecStart=/etc/rc.d/init.d/solr start (code=exited, status=0/SUCCESS)

Dec 29 15:01:04 hdp01 systemd[1]: Starting LSB: Controls Apache Solr as a Service...
Dec 29 15:01:04 hdp01 su[3628]: (to hadoop) root on none
Dec 29 15:01:05 hdp01 solr[3626]: Warning: Available entropy is low. As a result, use of the UUIDField, SSL, or any other features that require
Dec 29 15:01:05 hdp01 solr[3626]: RNG might not work properly. To check for the amount of available entropy, use 'cat /proc/sys/kernel/random/entropy_avail'.
Dec 29 15:01:07 hdp01 solr[3626]: [110B blob data]
Dec 29 15:01:07 hdp01 solr[3626]: Started Solr server on port 8983 (pid=3746). Happy searching!
Dec 29 15:01:08 hdp01 solr[3626]: [14B blob data]
Dec 29 15:01:08 hdp01 systemd[1]: Started LSB: Controls Apache Solr as a Service.

3、Zookeeper创建目录

[root@hdp01 ~]#  cd /u01/solr/server/scripts/cloud-scripts/
[root@hdp01 ~]#  chmod +x zkcli.sh
[hadoop@hdp01 ~]$ /u01/solr/server/scripts/cloud-scripts/zkcli.sh -zkhost hdp01:2181 -cmd makepath /solr

4、编辑solr.in.sh

[root@hdp01 ~]# vi /u01/solr/bin/solr.in.sh 
--修改ZK_HOST变量,如下:
ZK_HOST="hdp01:2181,hdp02:2181,hdp03:2181,hdp04:2181/solr"
--修改时区
SOLR_TIMEZONE="UTC+08:00"

5、修改solr的环境变量

[root@hdp01 ~]#  vi /etc/init.d/solr
SOLR_INSTALL_DIR="/u01/solr"
SOLR_ENV="/u01/solr/bin/solr.in.sh"
如果不修改SOLR_ENV值,solr在启动的过程中不会成功注册到zookeeper服务中。

6、创建日志文件目录

[root@hdp01 ~]#  mkdir /u01/solr/server/logs
[root@hdp01 ~]#  chmod 777 /u01/solr/server/logs
如果不对目录设置权限,在启动solr的时候会报无法写文件错误。因为这里是以hadoop用户启动的。

7、重启solr服务

[root@hdp01 ~]#  systemctl stop solr
[root@hdp01 ~]#  systemctl start solr
[root@hdp01 ~]#  systemctl status solr
[root@hdp01 ~]# systemctl status solr
● solr.service - LSB: Controls Apache Solr as a Service
   Loaded: loaded (/etc/rc.d/init.d/solr; bad; vendor preset: disabled)
   Active: active (exited) since Fri 2017-12-29 15:16:07 CST; 10min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 5537 ExecStart=/etc/rc.d/init.d/solr start (code=exited, status=0/SUCCESS)

Dec 29 15:16:02 hdp01 systemd[1]: Starting LSB: Controls Apache Solr as a Service...
Dec 29 15:16:02 hdp01 su[5539]: (to hadoop) root on none
Dec 29 15:16:03 hdp01 solr[5537]: /u01/solr/bin/solr: line 2021: /u01/solr/bin/solr-8983.pid: Permission denied
Dec 29 15:16:03 hdp01 solr[5537]: Warning: Available entropy is low. As a result, use of the UUIDField, SSL, or any other features that require
Dec 29 15:16:03 hdp01 solr[5537]: RNG might not work properly. To check for the amount of available entropy, use 'cat /proc/sys/kernel/random/entropy_avail'.
Dec 29 15:16:07 hdp01 solr[5537]: [146B blob data]
Dec 29 15:16:07 hdp01 solr[5537]: Started Solr server on port 8983 (pid=5657). Happy searching!
Dec 29 15:16:07 hdp01 solr[5537]: [14B blob data]
Dec 29 15:16:07 hdp01 systemd[1]: Started LSB: Controls Apache Solr as a Service.

通过访问服务器的8983端口即可打开web管理界面,如下图所示:
Installing Solr On Oracle Linux 7.4_第1张图片
8、检查Zookeeper注册

[hadoop@hdp01 ~]$ zkCli.sh
[zk: localhost:2181(CONNECTED) 0] ls /
[hivesrv2, zookeeper, yarn-leader-election, oozie, hive_zookeeper_namespace, solr, services, hbase]
[zk: localhost:2181(CONNECTED) 1] ls /solr
[configs, overseer, aliases.json, live_nodes, collections, overseer_elect, security.json, clusterstate.json, autoscaling, autoscaling.json]
[zk: localhost:2181(CONNECTED) 2] ls /solr/live_nodes
[192.168.120.96:8983_solr]
[zk: localhost:2181(CONNECTED) 3] ls /solr/configs   
[_default]
[zk: localhost:2181(CONNECTED) 4] ls /solr/configs/_default
[managed-schema, protwords.txt, solrconfig.xml, synonyms.txt, stopwords.txt, lang, params.json]