K8s环境Solr Cloud加载大文件至KeepWordFilterFactory遇阻求助
解决方案:在Bitnami Solr Cloud中加载大体积KeepWord文件
方法1:修正镜像嵌入的路径写法
Solr解析配置中的文件路径时,若使用绝对路径必须添加file://前缀,否则会被当作相对路径自动拼接/configs/coreName/前缀,导致无效路径。
- 将
keepwords.txt放入镜像内固定路径,比如/opt/bitnami/solr/server/solr/custom_resources/keepwords.txt - 在schema配置中明确指定带前缀的绝对路径:
<filter class="solr.KeepWordFilterFactory" words="file:///opt/bitnami/solr/server/solr/custom_resources/keepwords.txt" ignoreCase="true"/> - 镜像构建时确保Solr运行用户(Bitnami默认是
solr)有文件读取权限:COPY keepwords.txt /opt/bitnami/solr/server/solr/custom_resources/ RUN chown solr:solr /opt/bitnami/solr/server/solr/custom_resources/keepwords.txt
方法2:通过Kubernetes挂载大文件(无需自定义镜像)
用K8s ConfigMap或PersistentVolume挂载文件到Solr Pod,避免修改镜像:
- 创建包含keepwords.txt的ConfigMap(若文件超过1MB,建议用PersistentVolume替代):
kubectl create configmap solr-keepwords --from-file=keepwords.txt=/本地路径/keepwords.txt - 修改Bitnami Solr Chart的values.yaml,添加挂载配置:
extraVolumes: - name: solr-keepwords configMap: name: solr-keepwords extraVolumeMounts: - name: solr-keepwords mountPath: /opt/bitnami/solr/server/solr/custom_resources/keepwords.txt subPath: keepwords.txt readOnly: true - 同样在Solr配置中使用
file://前缀指定路径:file:///opt/bitnami/solr/server/solr/custom_resources/keepwords.txt
方法3:升级到Solr 9后的适配方案
Solr 9优化了大配置文件的管理,可通过Config Set API直接上传大文件:
- 上传文件到目标Config Set:
curl -X PUT "http://solr服务地址:8983/solr/admin/configs/你的ConfigSet名?action=UPLOAD&name=keepwords.txt" --data-binary @keepwords.txt -H "Content-Type: application/octet-stream" - 配置中直接引用文件名即可:
该方式绕过ZooKeeper传输大文件的限制,由Solr直接管理资源文件。<filter class="solr.KeepWordFilterFactory" words="keepwords.txt" ignoreCase="true"/>
错误原因说明
你遇到的Invalid path string "/configs/corename//opt/bitnami/..."问题,是因为未给绝对路径添加file://前缀,Solr将其识别为相对路径,自动拼接Config Set的根路径/configs/coreName/,导致出现双斜杠的无效路径格式。
内容的提问来源于stack exchange,提问作者DavidVdd
相关产品推荐
相关产品推荐

