插件
使用自动插件下载添加插件
您可以配置 Neo4j 部署以自动下载和安装插件。如果插件需要许可证,您必须在秘密中提供许可证。
安装 GDS 社区版 (CE)
GDS 社区版不需要许可证。要添加 GDS CE,请配置 Neo4j values.yaml 并设置 env
以下载插件
neo4j:
name: licenses
acceptLicenseAgreement: "yes"
edition: enterprise
volumes:
data:
mode: defaultStorageClass
env:
NEO4J_PLUGINS: '["graph-data-science"]'
config:
dbms.security.procedures.unrestricted: "gds.*"
安装 GDS 企业版 (EE) 和 Bloom 插件
要安装 GDS EE 和 Bloom,您必须为每个插件提供许可证。您在 Kubernetes 秘密中提供许可证。
-
创建一个包含许可证的秘密
kubectl create secret generic --from-file=gds.license,bloom.license gds-bloom-license
-
使用秘密作为 /licenses 卷挂载配置 Neo4j values.yaml 文件,并将
env
设置为下载插件neo4j: name: licenses acceptLicenseAgreement: "yes" edition: enterprise volumes: data: mode: defaultStorageClass licenses: disableSubPathExpr: true mode: volume volume: secret: secretName: gds-bloom-license items: - key: gds.license path: gds.license - key: bloom.license path: bloom.license env: NEO4J_PLUGINS: '["graph-data-science", "bloom"]' config: gds.enterprise.license_file: "/licenses/gds.license" dbms.security.procedures.unrestricted: "gds.*,apoc.*,bloom.*" server.unmanaged_extension_classes: "com.neo4j.bloom.server=/bloom,semantics.extension=/rdf" dbms.security.http_auth_allowlist: "/,/browser.*,/bloom.*" dbms.bloom.license_file: "/licenses/bloom.license"
使用自定义容器映像添加插件
在 Kubernetes 中运行的 Neo4j 中添加插件的最佳方法是创建一个包含 Neo4j 和 Neo4j 插件的新 Docker 容器镜像。这样,您可以在构建容器时确保容器的 Neo4j 版本使用正确的插件版本,并且生成的镜像包含所有 Neo4j 运行时依赖项。
Neo4j Bloom 插件需要许可证激活密钥,该密钥需要放在 Neo4j Docker 容器可以访问的目录中,例如,挂载到 /licenses(默认)。要获取有效的许可证,请联系您的 Neo4j 帐户代表或使用表单 联系 Neo4j。 |
构建基于官方 Neo4j Docker 镜像且不覆盖官方镜像的 ENTRYPOINT
和 COMMAND
的 Docker 容器镜像,是 Neo4j Helm 图表推荐使用的方法,如本例 Dockerfile 所示。
ARG NEO4J_VERSION
FROM neo4j:${NEO4J_VERSION}
# copy my-plugins into the Docker image
COPY my-plugins/ /var/lib/neo4j/plugins
# install the apoc core plugin that is shipped with Neo4j
RUN cp /var/lib/neo4j/labs/apoc-* /var/lib/neo4j/plugins
构建 Docker 镜像后,将其推送到 Kubernetes 集群可以访问的容器仓库。
CONTAINER_REPOSITORY="my-container-repository.io"
IMAGE_NAME="my-neo4j"
# export this so that it's accessible as a docker build arg
export NEO4J_VERSION=5.25.1-enterprise
docker build --build-arg NEO4J_VERSION --tag ${CONTAINER_REPOSITORY}/${IMAGE_NAME}:${NEO4J_VERSION} .
docker push ${CONTAINER_REPOSITORY}/${IMAGE_NAME}:${NEO4J_VERSION}
要使用您创建的镜像,在 Neo4j Helm 部署的 values.yaml 文件中,设置 image.customImage
以使用该镜像。有关更多详细信息,请参阅 配置自定义容器镜像。
许多插件需要额外的 Neo4j 配置才能正常工作。插件配置应在 Helm 部署的 values.yaml 文件中的 |
使用插件卷添加插件
将 Neo4j 插件添加到 Neo4j Helm 部署的另一种方法是使用 plugins
卷挂载。使用这种方法,插件 jar 文件存储在挂载到 Neo4j 容器的 /plugins
目录的持久卷上。
Neo4j Bloom 插件需要许可证激活密钥,该密钥需要放在 Neo4j Docker 容器可以访问的目录中,例如,挂载到 /licenses(默认)。要获取有效的许可证,请联系您的 Neo4j 帐户代表或使用表单 联系 Neo4j。 |
设置持久 plugins
卷的最简单方法是共享用于存储 Neo4j 数据的持久卷。以下示例展示了如何在 Neo4j Helm 部署的 values.yaml 文件中配置它。
# neo4j-values.yaml
volumes:
data:
# your data volume configuration
...
plugins:
mode: "share"
share:
name: "data"
有关配置卷挂载的不同方法的详细信息,请参阅 将卷挂载映射到持久卷。
现在,Neo4j 容器有一个由持久卷支持的空的 /plugins 目录。可以使用 kubectl cp
将插件 jar 文件复制到卷上。由于它由持久卷支持,因此即使 Neo4j pod 重启或移动,插件文件也会持久化。
Neo4j 仅在启动时加载插件。因此,您必须重新启动 Neo4j pod 才能在所有插件到位后加载它们。 |
例如
# Copy plugin files into the Neo4j container
kubectl cp my-plugins/* <namespace>/<neo4j-pod-name>:/plugins/
# Restart Neo4j
kubectl rollout restart statefulset/<neo4j-statefulset-name>
# Verify plugins are still present after restart
kubectl exec <neo4j-pod-name> -- ls /plugins
仅配置和安装 APOC 核心
APOC 核心库与 Neo4j 一起提供,位于 labs 文件夹中。
如果您只想将 APOC 核心添加到 Neo4j,则无需执行上述插件安装。相反,您可以配置 helm 部署以使用 APOC 核心,方法是在 values.yaml 文件中使用以下附加设置升级部署。
-
通过直接指向 labs 文件夹中 APOC 核心库的位置,以及加载和取消限制您需要的函数和过程来配置 APOC 核心(有关更多详细信息,请参阅 APOC 安装指南)。例如
config: server.directories.plugins: "/var/lib/neo4j/labs" dbms.security.procedures.unrestricted: "apoc.*" server.config.strict_validation.enabled: "false" dbms.security.procedures.allowlist: "apoc.math.*,apoc.cypher.*"
-
在
apoc_config
下,配置您想要的 APOC 设置,例如apoc_config: apoc.trigger.enabled: "true" apoc.jdbc.neo4j.url: "jdbc:foo:bar" apoc.import.file.enabled: "true"
-
运行
helm upgrade
以应用更改。helm upgrade <release-name> neo4j/neo4j -f values.yaml
-
在 Helm 升级滚动完成之后,使用
cypher-shell
或 Neo4j 浏览器运行以下 Cypher 查询,以验证 APOC 核心是否已配置。RETURN apoc.version()
使用 APOC-extended 为插件的别名配置凭据
从 5.11 开始,Neo4j Helm 图表支持使用挂载在提供的路径上的 Kubernetes 密钥来为插件的别名配置凭据。此功能可通过 APOC-extended 在 apoc.jdbc.<aliasname>.url
和 apoc.es.<aliasname>.url
中使用。
必须预先创建密钥,并且必须包含名为 |
在 apoc_credentials
下,配置 aliasName
、secretName
和 secretMountPath
。例如
apoc_credentials: {}
# jdbc:
# aliasName: "jdbc"
# secretName: "jdbcsecret"
# secretMountPath: "/secret/jdbcCred"
#
# elasticsearch:
# aliasName: "es"
# secretName: "essecret"
# secretMountPath: "/secret/esCred"