Building simple application services of solr

Keywords: Java solr Tomcat xml

Environment: Centos7 + jdk1.8 + solr-7.7.2 + tomcat-8.5.43

Centos7 download address: https://www.jianshu.com/p/a63f47e096e8

jdk1.8 download address: https://www.oracle.com/java/technologies/javase-jdk8-downloads.html

solr-7.7.2 download address: http://archive.apache.org/dist/lucene/solr/

tomcat-8.5.43 download address: http://archive.apache.org/dist/tomcat/tomcat-8/v8.5.43/bin/

Part I: configuring solr service in tomcat

1. Extract solr-7.7.2, enter server/webapps, copy webapp file to webapps of tomcat, and change the name to Solr for access

  

2. Add to tomcat container

    

3. Add the package that solr depends on to the WEB-INF/lib file in solr project

3.1 add all packages under lib/ext under server

   

3.2 add 6 dependent packages under the lib folder of the server

     

4. Create solrhome folder as the directory of index library under usr/local

     

5. Copy contrib and dist under solr-7.7.2 to solrhome

     

6. Copy all files under solr under the server-7.7.2 directory to solrhome directory

     

7. Create the starting core library in solrhome directory and name it new_core [customized folder conforming to project specification]

    

8. Copy the conf folder of server / Solr / configsets / ﹣ default under the directory solr-7.7.2 to the new﹣ core directory created

  

9. Log file

9.1 in solr project of Tomcat [path: tomcat-8.5.43/webapps/solr/WEB_INF /] create a new classes folder

9.2 copy log4j2.xml under solr-7.7.2/server/resources to the classes folder

10. Modify the solr project web.xml file under tomcat-8.5.43

 

<env-entry> 
  <env-entry-name>solr/home</env-entry-name>
  <env-entry-value>/usr/local/solrhome</env-entry-value>
  <env-entry-type>java.lang.String</env-entry-type>
</env-entry>

11. Note safety constraints

HTTP Status 403 - Access to the requested resource has been denied.

12. Start tomcat, access path: http://127.0.0.1:8080/solr/index.html 

Precautions:

1. In order to avoid some Chinese code problems of requests and returns in the program, we need to edit tomcat's configuration file server.xml

<Connector port="8080" protocol="HTTP/1.1"
            useBodyEncodingForURI="true" URIEncoding="UTF-8"
            connectionTimeout="20000"
            redirectPort="8443" />

2. Starting tomcat will result in the following error:

2.1 error content:

WARN false x:ljf_dev SolrConfig Couldn't add files from /opt/solrhome/ljf_dev/../../../../contrib/extraction/lib filtered by .*\.jar to classpath: /opt/solrhome/ljf_dev/../../../../contrib/extraction/lib
2019/1/9 Forenoon 11:01:16
WARN falsex:ljf_dev SolrConfig  Couldn't add files from /opt/solrhome/ljf_dev/../../../../dist filtered by solr-cell-\d.*\.jar to classpath: /opt/solrhome/ljf_dev/../../../../dist

2.2 error reason:

The above error is that we can't load those jar packages. These jar packages are still in the files we unzipped. It can't be found. First, we find our configuration file, and then modify the path it looks for.
The configuration file is solrconfig.xml in conf under the core directory

We can see that the default configuration path is: this path is solr's installation path, and we can change it to absolute path

  <lib dir="${solr.install.dir:../../../..}/contrib/extraction/lib" regex=".*\.jar" />
  <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-cell-\d.*\.jar" />

  <lib dir="${solr.install.dir:../../../..}/contrib/clustering/lib/" regex=".*\.jar" />
  <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-clustering-\d.*\.jar" />

  <lib dir="${solr.install.dir:../../../..}/contrib/langid/lib/" regex=".*\.jar" />
  <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-langid-\d.*\.jar" />

  <lib dir="${solr.install.dir:../../../..}/contrib/velocity/lib" regex=".*\.jar" />
  <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-velocity-\d.*\.jar" />

2.3 solutions:

Put those jar packages in a fixed path, and then change the path in the configuration file to absolute path

#Profile under backup
cp  /usr/local/solrhome/new_core/conf/solrconfig.xml  /user/local/solrhome/new_core/conf/solrconfig.xml.bak
#Copy the dependent files to the solr project of tomcat
cp  -r /opt/solr-7.7.2/dist/     /opt/tomcat-8.5.43/webapps/solr/
cp  -r /opt/solr-7.7.2/contrib/     /opt/tomcat-8.5.43/webapps/solr/

//Then change the configuration file / usr/local/solrhome/new_core/conf/solrconfig.xml to an absolute path. The following is the modified path.
  <lib dir="/opt/tomcat-8.5.43/webapps/solr/contrib/extraction/lib" regex=".*\.jar" />
  <lib dir="/opt/tomcat-8.5.43/webapps/solr/dist/" regex="solr-cell-\d.*\.jar" />

  <lib dir="/opt/tomcat-8.5.43/webapps/solr/contrib/clustering/lib/" regex=".*\.jar" />
  <lib dir="/opt/tomcat-8.5.43/webapps/solr/dist/" regex="solr-clustering-\d.*\.jar" />

  <lib dir="/opt/tomcat-8.5.43/webapps/solr/contrib/langid/lib/" regex=".*\.jar" />
  <lib dir="/opt/tomcat-8.5.43/webapps/solr/dist/" regex="solr-langid-\d.*\.jar" />

  <lib dir="/opt/tomcat-8.5.43/webapps/solr/contrib/velocity/lib" regex=".*\.jar" />
  <lib dir="/opt/tomcat-8.5.43/webapps/solr/dist/" regex="solr-velocity-\d.*\.jar" />

So restart tomcat without warning.

 

--So far, the first part of solr configuration is completed

 

Source:

https://blog.csdn.net/weixin_44124307/article/details/96362431

Posted by renegade44 on Mon, 16 Mar 2020 01:26:27 -0700