写本文源于,传智播客的淘淘商城实战项目。solr 搜索服务的实现。
视频中用的,比较老的 solr 4.10.3。去看了Solr 官网,吓一跳,都 8.1.1 了。
其中 7.x 系列,是长期支持版本。下载 7.2.2
不安装最新的版本,暂不说稳不稳定,在最开始学习时,相关的文档比较少。搜索时没什么参考的文章。
Solr 在5.x 后有个最大的改变。不推荐以 solr.war 部署的方式。
Solr is Now a Standalone Server. => 现在Solr是一个独立的服务器.
5.x 、6.x 、 7.x 、 8.x 的安装,差不多一样的流程。
安装前,需要安装 jdk-8u212-linux-x64.tar.gz.
安装 solr
在 root 的用户目录下,上传有 solr-7.7.2.tgz,进行解压。
[root@localhost ~]# pwd
/root
[root@localhost ~]# ll
total 539760
-rw-r--r--. 1 root root 9642757 Jun 11 08:38 apache-tomcat-8.5.35.tar.gz
-rw-r--r--. 1 root root 195013152 Jun 11 08:38 jdk-8u212-linux-x64.tar.gz
-rw-r--r--. 1 root root 1032345 Apr 23 09:58 nginx-1.16.0.tar.gz
drwxr-xr-x. 9 root root 201 Jun 12 04:25 solr-7.7.2
-rw-r--r--. 1 root root 171374430 Jun 11 22:10 solr-7.7.2.tgz
-rw-r--r--. 1 root root 175620176 Jun 11 09:11 solr-8.1.1.tgz
[root@localhost ~]# tar -xvf solr-7.7.2
solr-7.7.2/LUCENE_CHANGES.txt
solr-7.7.2/contrib/analysis-extras/lib/
solr-7.7.2/contrib/clustering/lib/
solr-7.7.2/contrib/dataimporthandler-extras/lib/
solr-7.7.2/contrib/extraction/lib/
solr-7.7.2/contrib/langid/lib/
solr-7.7.2/contrib/prometheus-exporter/conf/
solr-7.7.2/contrib/prometheus-exporter/lib/
略
从解压的 solr 文件中,将安装脚本,拷贝出来,入当前目录。好下步使用脚本安装。
[root@localhost ~]# cp solr-7.7.2/bin/install_solr_service.sh ./
[root@localhost ~]# ll
total 539760
-rw-r--r--. 1 root root 9642757 Jun 11 08:38 apache-tomcat-8.5.35.tar.gz
-rwxr-xr-x. 1 root root 12694 Jun 12 04:27 install_solr_service.sh
-rw-r--r--. 1 root root 195013152 Jun 11 08:38 jdk-8u212-linux-x64.tar.gz
-rw-r--r--. 1 root root 1032345 Apr 23 09:58 nginx-1.16.0.tar.gz
drwxr-xr-x. 9 root root 201 Jun 12 04:27 solr-7.7.2
-rw-r--r--. 1 root root 171374430 Jun 11 22:10 solr-7.7.2.tgz
-rw-r--r--. 1 root root 175620176 Jun 11 09:11 solr-8.1.1.tgz
使用脚本进行安装 。 脚本后面是,安装文件,-i 指定安装目录。 -d 指定临时文件。 -u 指定用户
安装 脚本 后面这些参考,自己 编辑 脚本文件,直接查看,就是。虽是英文,其实也不是很难。
[root@localhost ~]# ./install_solr_service.sh solr-7.7.2.tgz -i /opt -d /var/solr -u admin -s solr -p 8983 -n
We recommend installing the 'lsof' command for more stable start/stop of Solr
id: admin: no such user
Creating new user: admin
Extracting solr-7.7.2.tgz to /opt
Installing symlink /opt/solr -> /opt/solr-7.7.2 ...
Installing /etc/init.d/solr script ...
Installing /etc/default/solr.in.sh ...
Service solr installed.
Customize Solr startup configuration in /etc/default/solr.in.sh
Not starting Solr service (option -n given). Start manually with 'service solr start'
启动 solr
[root@localhost ~]# service solr start
*** [WARN] *** Your open file limit is currently 1024.
It should be set to 65000 to avoid operational disruption.
If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh
*** [WARN] *** Your Max Processes Limit is currently 1780.
It should be set to 65000 to avoid operational disruption.
If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh
NOTE: Please install lsof as this script needs it to determine if Solr is listening on port 8983.
Started Solr server on port 8983 (pid=9205). Happy searching!
访问:http://192.168.199.131:8983/solr/#/
关闭 solr
[root@localhost ~]# service solr stop
Sending stop command to Solr running on port 8983 ... waiting up to 180 seconds to allow Jetty process 9205 to stop gracefully.
[root@localhost ~]# /opt/solr/bin/solr create -c mycore
Failed to determine the port of a local Solr instance, cannot create mycore!
[root@localhost ~]# service solr start
*** [WARN] *** Your open file limit is currently 1024.
It should be set to 65000 to avoid operational disruption.
If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh
*** [WARN] *** Your Max Processes Limit is currently 1780.
It should be set to 65000 to avoid operational disruption.
If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh
NOTE: Please install lsof as this script needs it to determine if Solr is listening on port 8983.
Started Solr server on port 8983 (pid=9631). Happy searching!
[root@localhost ~]# /opt/solr/bin/solr create -c mycore
WARNING: Using _default configset with data driven schema functionality. NOT RECOMMENDED for production use.
To turn off: bin/solr config -c mycore -p 8983 -action set-user-property -property update.autoCreateFields -value false
WARNING: Creating cores as the root user can cause Solr to fail and is not advisable. Exiting.
If you started Solr as root (not advisable either), force core creation by adding argument -force