在CentOS 8/7和Fedora 29-26上安装Apache Solr

时间:2020-02-23 14:31:07  来源:igfitidea点击:

Apache Solr是一个用Java编写的开源,容错和高度可扩展的搜索工具。 Apache Solr支持许多世界上最大的互联点的搜索和导航功能。在本教程中,我们将研究如何在CentOS 8/7/Fedora 29-26上安装Apache Solr。

安装Java

Apache Solr需要Java。如果系统上未安装Java,则如下所示安装它。

在CentOS 7上安装Java:

sudo yum install lsof java-1.8.0-openjdk  java-1.8.0-openjdk-devel
java -version

在Fedora上安装Java:

$sudo dnf install java-11-openjdk
OR
$sudo dnf install java-1.8.0-openjdk  java-1.8.0-openjdk-devel

安装Java之后,我们可以使用以下命令快速确认版本:

$java -version
java version "11.0.1" 2016-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

第2步:在CentOS 7/Fedora 29/Fedora 28上安装最新的Apache Solr

Apache Solr在CentOS和Fedora上游存储库上不可用,我们必须下载并手动安装。我们可以检查Apache Solrt的最新版本,将其保存到LATEST_VER变量中。

export LATEST_VER="8.0.0"
curl -O https://www-eu.apache.org/dist/lucene/solr/${LATEST_VER}/solr-${LATEST_VER}.tgz

解压缩下载的档案:

tar xvf solr-${LATEST_VER}.tgz

现在运行Apache Solr服务安装程序脚本来设置Solr环境。

cd solr-${LATEST_VER}/bin/
sudo ./install_solr_service.sh ~/solr-${LATEST_VER}.tgz

输出示例:

id: 'solr': no such user
Creating new user: solr
Adding system user `solr' (UID 111) ...
Adding new group `solr' (GID 116) ...
Adding new user `solr' (UID 111) with group `solr' ...
Creating home directory `/var/solr' ...

Extracting /home/vagrant/solr-8.0.0.tgz to /opt

Installing symlink /opt/solr -> /opt/solr-8.0.0 ...

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

该脚本将安装并启动Solr服务。我们可以通过运行以下命令检查状态:

$sudo systemctl status solr
● solr.service - LSB: Controls Apache Solr as a Service
   Loaded: loaded (/etc/rc.d/init.d/solr; generated)
   Active: active (running) since Mon 2016-11-19 17:23:44 UTC; 2s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 3027 ExecStart=/etc/rc.d/init.d/solr start (code=exited, status=0/SUCCESS)

Nov 19 17:23:33 fed29 su[3029]: pam_unix(su-l:session): session opened for user solr by (uid=0)
Nov 19 17:23:34 fed29 solr[3027]: *** [WARN] *** Your open file limit is currently 1024.
Nov 19 17:23:34 fed29 solr[3027]:  It should be set to 65000 to avoid operational disruption.
Nov 19 17:23:34 fed29 solr[3027]:  If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh
Nov 19 17:23:34 fed29 solr[3027]: *** [WARN] ***  Your Max Processes Limit is currently 3832.
Nov 19 17:23:34 fed29 solr[3027]:  It should be set to 65000 to avoid operational disruption.
Nov 19 17:23:34 fed29 solr[3027]:  If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh
Nov 19 17:23:34 fed29 solr[3027]: NOTE: Please install lsof as this script needs it to determine if Solr is listening on port 8983.
Nov 19 17:23:44 fed29 solr[3027]: Started Solr server on port 8983 (pid=3103). Happy searching!
Nov 19 17:23:44 fed29 systemd[1]: Started LSB: Controls Apache Solr as a Service.

确保将服务设置为在启动时启动。

$sudo systemctl enable solr
solr.service is not a native service, redirecting to systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable solr

访问Solr仪表板

默认情况下,Solr在端口8983上运行。如果我们有活动的防火墙,请允许端口8983.

sudo firewall-cmd  --permanent --add-port=8983/tcp
sudo firewall-cmd --reload

仪表板应该可以在服务器IP地址/主机名和端口" 8983"上访问。

http://<IP|Hostname>:8983

创建Solr集合

现在,我们可以创建第一个Solr集合:

sudo su - solr -c "/opt/solr/bin/solr create -c testcollection -n data_driven_schema_configs"

其中" testcollection"是要创建的集合的名称。

输出示例:

INFO - 2016-11-18 13:48:05.538; org.apache.solr.util.configuration.SSLCredentialProviderFactory; Processing SSL Credential Provider chain: env;sysprop
Created new core 'testcollection'

创建的集合可在集合左侧面板上的仪表板上找到。