快速入门:为分析查询部署 Neo4j 集群

此功能从 5.14 版本开始在 Neo4j Helm Chart 中可用。

本快速入门指南演示了如何配置和部署一个特殊的 Neo4j 集群,该集群包含一个主服务器和 N 个辅助服务器来支持分析查询。主服务器处理事务工作负载,而辅助服务器配置了 Neo4j 图数据科学库 (GDS),仅用于分析工作负载。
有关在集群中使用 GDS 的信息,请参阅Neo4j 图数据科学库文档

该集群使用 Neo4j Helm Chart 部署到云或本地 Kubernetes 集群。

先决条件

在 Kubernetes 上部署 Neo4j 集群之前,您需要:

为每种类型的服务器创建值 YAML 文件

要为分析查询设置 Neo4j 集群,您需要为每种类型的服务器(主服务器和辅助服务器)创建值 YAML 文件。例如:

为主服务器创建一个值 YAML 文件,例如 primary-value.yaml

neo4j:
  name: analytics-cluster
  acceptLicenseAgreement: "yes"
  edition: enterprise
  password: my-password
volumes:
  data:
    mode: defaultStorageClass

# Disable the Neo4j load balancer and enable the internal service so that the servers can access each other:
services:
  neo4j:
    enabled: false
  internals:
    enabled: true

# Enable the analytics cluster and set the type to primary:
analytics:
  enabled: true
  type:
    name: primary

为辅助服务器创建一个值 YAML 文件,例如 secondary-gds.yaml。密码必须与主服务器相同。如果您使用的是 GDS 企业版,则还需要创建一个包含许可证文件的密钥,并将其安装为 /licenses 卷挂载。有关如何创建密钥的更多信息,请参阅安装 GDS 企业版 (EE) 和 Bloom 插件

neo4j:
  name: analytics-cluster
  acceptLicenseAgreement: "yes"
  edition: enterprise
  password: my-password
volumes:
  data:
    mode: defaultStorageClass
  # Define the volume mount for the license file:
  licenses:
    disableSubPathExpr: true
    mode: volume
    volume:
      secret:
        secretName: gds-license
        items:
          - key: gds.license
            path: gds.license

# Set the environment variables to download the plugins:
env:
  NEO4J_PLUGINS: '["graph-data-science"]'

# Set the configuration for the plugins directory and the mount for the license file:
config:
  gds.enterprise.license_file: "/licenses/gds.license"
  server.directories.plugins: "plugins"

# Disable the Neo4j load balancer and enable the internal service so that the servers can access each other:
services:
  neo4j:
    enabled: false
  internals:
    enabled: true

# Enable the analytics cluster and set the type to secondary:
analytics:
  enabled: true
  type:
    name: secondary

有关所有可用选项,请参阅自定义 Neo4j Helm Chart

安装服务器

  1. 使用上一节中创建的 neo4j-primary.yaml 文件安装单个 Neo4j 服务器。

    helm install primary neo4j/neo4j -f /path/to/neo4j-primary.yaml
  2. 使用上一节中创建的 secondary-gds.yaml 文件安装第一个辅助服务器。

    helm install gds1 neo4j/neo4j -f /path/to/secondary-gds.yaml
  3. 重复步骤 2 以部署第二个辅助服务器。使用不同的名称,例如 gds2

验证 GDS 库是否已安装和获得许可

  1. 使用 kubectl exec 命令连接到每个 gds Pod。

    kubectl exec -it gds1-0 -- bash
  2. bin 文件夹中,使用 cypher-shell 命令连接到 gds1 服务器的 system 数据库。

    cypher-shell -u neo4j -p my-password -d system -a bolt://gds1-internals.default.svc.cluster.local:7687
  3. 运行以下 Cypher 函数以验证 GDS 库是否已安装。

    RETURN gds.version();
  4. 调用 gds.isLicensed() 以验证 GDS 库是否已获得许可。

    RETURN gds.isLicensed();

    返回值必须为 true

验证集群的形成

要验证集群是否已部署并正在运行,您可以安装负载均衡器并从 Neo4j 浏览器访问 Neo4j。

  1. 将 Neo4j 负载均衡器部署到与 Neo4j 集群相同的命名空间。

    helm install lb neo4j/neo4j-load-balancer --set neo4j.name="analytics-cluster"
  2. 部署后,复制 LoadBalancer 服务的 EXTERNAL_IP。有关更多信息,请参阅从 Kubernetes 外部访问 Neo4j 集群

  3. 在 Web 浏览器中,在 http://EXTERNAL_IP:7474/browser 打开 Neo4j 浏览器,并使用您在值 YAML 文件中配置的密码登录。

  4. 运行 SHOW SERVERS 命令以验证集群是否已部署并正在运行。

  5. 运行 SHOW DATABASES 命令以验证独立服务器的类型是否为 primary,而 GDS 服务器的类型是否为 secondary