title: Solr 使用中遇到的问题
tags: [Sdudoc, solr, linux]
categories: 技术
前言
笔者使用的Solr版本是solr-8.11.0
正文
启动时警告
*** [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 4096.
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.shNOTE: Please install lsof as this script needs it to determine if Solr is listening on port 8983.
可以看到这里有两个警告和一个提示。
其中第一个警告是说当前最大打开文件数为1024,为了防止操作终端,应该设置为65000
笔者首先检查了本机的限制:
ulimit -a
----
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 63405
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 4096
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
----
可以清楚的看到 open files 的限制为 1024
修改限制至65000 (记得切换至root用户,否则没有权限修改)
ulimit -n 65000
为了保证每次系统启动时,都可以设置ulimit值至65000,笔者将ulimit指令加到了 /etc/profile 中
echo ulimit -n 65000 >> /etc/profile
----
source /etc/profile
利用上面的方法,我们也可以将最大用户进程数设置为65000
注意,这里设置的是当前用户的最大进程数,所以应当切换至对应的用户执行以下操作
echo ulimit -u 65000 >> /etc/profile
----
source /etc/profile
最后一个,安装lsof,在root用户下执行:
yum install lsof
使用中遇到问题
插入数据时报错
test代码片段如下:
TestDocument testDocument = new TestDocument();
UpdateResponse response = solrClient.addBean(TEST_CORE_NAME, testDocument);
response = solrClient.commit(TEST_CORE_NAME);
在测试插入文档到solr的core中时报错:
org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://211.87.232.198:8983/solr: Expected mime type application/octet-stream but got text/html. Sorry, Page Not Found
观察后发现,报错的位置在于commit处,查看源码发现,如果在url中没有指明core,则需要在add
的时候和commit
的时候都需要指明core
...
response = solrClient.commit(TEST_CORE_NAME);
中文分词不理想
笔者使用时发现solr对于中文的分词不够理想,故决定使用其他的分词器,这里笔者采用的是IK-Analyzer 链接:下载链接
将 jar 包添加至solr目录下的 server/solr-webapp/webapp/WEB-INF/lib 中
再向 server/solr/[core_name]/conf 下的 managed-schema 配置文件中添加配置:
<fieldType name="text_ik" class="solr.TextField">
<analyzer type="index" class="org.wltea.analyzer.lucene.IKAnalyzer" useSmart="false"/>
<analyzer type="query" class="org.wltea.analyzer.lucene.IKAnalyzer" useSmart="false"/>
</fieldType>
重启solr服务即可。