安装环境
[root@yfm05 data]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
[root@yfm05 data]# java -version
java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)
solr下载地址:https://archive.apache.org/dist/lucene/solr/
我这里下载的是solr-8.8.1.tgz
mkdir /data/solr && cd /data/solr
tar -zxvf solr-8.8.1.tgz
cd solr-8.8.1/bin
启动
./solr start -p 8983 -force
浏览器访问
http://192.168.199.105:8983/
solr和tomcat整合
vi /etc/profile
export SOLR_INSTALL_HOME=/data/solr/solr-8.8.1
export PATH=$SOLR_INSTALL_HOME/bin:$PATH
source /etc/profile
solr应用在SOLR_ROOT/server/solr-webapp/webapp,把solr应用复制到tomcat的webapps下,将命名为solr
cp -r /data/solr/solr-8.8.1/server/solr-webapp/webapp /data/tomcat/apache-tomcat-7.0.107/webapps/solr
拷贝jar文件
cp -r /data/solr/solr-8.8.1/server/lib/ext/* /data/tomcat/apache-tomcat-7.0.107/webapps/solr/WEB-INF/lib
cp /data/solr/solr-8.8.1/server/lib/metrics-* /data/tomcat/apache-tomcat-7.0.107/webapps/solr/WEB-INF/lib/
mkdir -p /data/solr/solrhome
配置tomcat→webApp→solr→WEB_INF下的web.xml
添加配置(指定solr数据源的位置)
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/data/solr/solrhome</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
注释一下配置(目的是防止tomcat 403问题)
<security-constraint>
<web-resource-collection>
<web-resource-name>Disable TRACE</web-resource-name>
<url-pattern>/</url-pattern>
<http-method>TRACE</http-method>
</web-resource-collection>
<auth-constraint/>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Enable everything but TRACE</web-resource-name>
<url-pattern>/</url-pattern>
<http-method-omission>TRACE</http-method-omission>
</web-resource-collection>
</security-constraint>
mkdir -p /data/solr/solrhome/logs
把solr安装包中的server→resources文件下的配置文件拷贝到tomcat→webApp→solr→WEB_INF→classes文件夹下(如果没有classes文件夹,请创建)
cp -r /data/solr/solr-8.8.1/server/resources/* /data/tomcat/apache-tomcat-7.0.107/webapps/solr/WEB-INF/classes
需要分别修改log4j2的两个配置文件,需要把所有${sys:solr.log.dir}修改为自己的指定的真实路径
启动tomcat,查看tomcat日志
2021-03-29 19:03:27.239 ERROR (localhost-startStop-1) [ ] o.a.s.c.SolrCore null:org.apache.solr.common.SolrException: solr.xml does not exist in /data/solr/solrhome cannot start Solr
at org.apache.solr.core.SolrXmlConfig.fromFile(SolrXmlConfig.java:160)
at org.apache.solr.core.SolrXmlConfig.fromSolrHome(SolrXmlConfig.java:200)
at org.apache.solr.servlet.SolrDispatchFilter.loadNodeConfig(SolrDispatchFilter.java:317)
at org.apache.solr.servlet.SolrDispatchFilter.createCoreContainer(SolrDispatchFilter.java:285)
at org.apache.solr.servlet.SolrDispatchFilter.init(SolrDispatchFilter.java:184)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:262)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:106)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4973)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5672)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1007)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:983)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:639)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1296)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:2037)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Mar 29, 2021 7:03:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory [/data/tomcat/apache-tomcat-7.0.107/webapps/solr] has finished in [25,468] ms
cp -r /data/solr/solr-8.8.1/server/solr/* /data/solr/solrhome
重启tomcat
Mar 30, 2021 10:17:45 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [LoadAdminUI] in context with path [/solr] threw exception [Filter execution threw an exception] with root cause
java.lang.NoSuchMethodError: javax.servlet.ServletInputStream.isFinished()Z
at org.apache.solr.servlet.SolrDispatchFilter.consumeInputFully(SolrDispatchFilter.java:465)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:453)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:357)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:492)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:165)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1201)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:654)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:317)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
记得带上index.html,坑了我好久,很多文章都没带
访问http://192.168.199.105:8080/solr/index.html#/
若有问题,换tomcat8试试
下载地址:http://tomcat.apache.org/