快速入门:部署 Neo4j 集群用于分析查询
本快速入门展示了如何配置和部署一个特殊的 Neo4j 集群,该集群包含一个主服务器和 N 个辅助服务器,以支持分析查询。主服务器处理事务工作负载,而辅助服务器则配置有 Neo4j 图数据科学库 (GDS),仅用于分析工作负载。
有关在集群中使用 GDS 的信息,请参阅 Neo4j 图数据科学库文档。
该集群使用 Neo4j Helm chart 部署到云端或本地 Kubernetes 集群。
先决条件
在 Kubernetes 上部署 Neo4j 集群之前,您需要:
-
一个正在运行的 Kubernetes 集群,并且已安装
kubectl
命令行工具并配置为与您的集群通信。更多信息请参见 快速入门:部署集群 → 先决条件。 -
Neo4j 企业版 的有效许可证。更多信息请参见 安装 GDS 企业版 (EE) 和 Bloom 插件。
-
(可选)GDS 企业版 的有效许可证。要安装许可插件,您必须在 Kubernetes secret 中提供许可证文件,并将其挂载为 /licenses 卷。有关如何创建 secret 的更多信息,请参见 安装 GDS 企业版 (EE) 和 Bloom 插件。
为每种类型的服务器创建一个值 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 企业版,您还需要使用许可证文件创建一个 secret,并将其挂载为 /licenses 卷。有关如何创建 secret 的更多信息,请参见 安装 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。
安装服务器
-
使用上一节中创建的 neo4j-primary.yaml 文件安装单个 Neo4j 服务器
helm install primary neo4j/neo4j -f /path/to/neo4j-primary.yaml
-
使用上一节中创建的 secondary-gds.yaml 文件安装第一个辅助服务器
helm install gds1 neo4j/neo4j -f /path/to/secondary-gds.yaml
-
重复第 2 步以部署第二个辅助服务器。使用不同的名称,例如 gds2。
验证 GDS 库是否已安装并获得许可
-
使用
kubectl exec
命令连接到每个gds
podkubectl exec -it gds1-0 -- bash
-
从 bin 文件夹,使用
cypher-shell
命令连接到gds1
服务器的system
数据库cypher-shell -u neo4j -p my-password -d system -a bolt://gds1-internals.default.svc.cluster.local:7687
-
运行以下 Cypher 函数以验证 GDS 库是否已安装
RETURN gds.version();
-
调用
gds.isLicensed()
以验证 GDS 库是否已获得许可RETURN gds.isLicensed();
返回的值必须是
true
。
验证集群形成
要验证集群是否已部署并正在运行,您可以安装负载均衡器并从 Neo4j Browser 访问 Neo4j。
-
将 Neo4j 负载均衡器部署到与 Neo4j 集群相同的命名空间
helm install lb neo4j/neo4j-load-balancer --set neo4j.name="analytics-cluster"
-
部署后,复制 LoadBalancer 服务的
EXTERNAL_IP
。更多信息请参见 从 Kubernetes 外部访问 Neo4j 集群。 -
在网页浏览器中,打开 Neo4j Browser,网址为 http://EXTERNAL_IP:7474/browser,并使用您在值 YAML 文件中配置的密码登录。
-
验证集群是否已部署并正在运行
SHOW SERVERS;
+------------------------------------------------------------------------------------------------------------------------------------------+ | name | address | state | health | hosting | +------------------------------------------------------------------------------------------------------------------------------------------+ | "16cd6e9c-aa5a-4737-8ed5-e0df36ce52d3" | "gds2.default.svc.cluster.local:7687" | "Free" | "Available" | ["system"] | | "bafbe254-a8a2-498d-9b60-6b3fd0124045" | "primary.default.svc.cluster.local:7687" | "Enabled" | "Available" | ["neo4j", "system"] | | "f1478d5d-1718-4430-a9b6-26fe9695ca30" | "gds1.default.svc.cluster.local:7687" | "Free" | "Available" | ["system"] | +------------------------------------------------------------------------------------------------------------------------------------------+
输出显示辅助服务器处于
free
状态,并且仅托管system
数据库。
启用辅助服务器以支持分析查询
为了在辅助服务器上支持分析查询,您需要启用它们并更改 neo4j
数据库拓扑以包含它们。
-
在 Neo4j Browser 中,启用辅助服务器以支持分析查询
ENABLE SERVER "f1478d5d-1718-4430-a9b6-26fe9695ca30"; ENABLE SERVER "16cd6e9c-aa5a-4737-8ed5-e0df36ce52d3";
-
更改数据库拓扑以包含辅助服务器
ALTER DATABASE neo4j SET TOPOLOGY 1 PRIMARY 2 SECONDARY;
-
检查
neo4j
数据库的状态以确认更改SHOW DATABASE neo4j;
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | name | type | aliases | access | address | role | writer | requestedStatus | currentStatus | statusMessage | default | home | constituents | +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | "neo4j" | "standard" | [] | "read-write" | "primary.default.svc.cluster.local:7687" | "primary" | TRUE | "online" | "online" | "" | TRUE | TRUE | [] | | "neo4j" | "standard" | [] | "read-write" | "gds1.default.svc.cluster.local:7687" | "secondary" | FALSE | "online" | "online" | "" | TRUE | TRUE | [] | | "neo4j" | "standard" | [] | "read-write" | "gds2.default.svc.cluster.local:7687" | "secondary" | FALSE | "online" | "online" | "" | TRUE | TRUE | [] | +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
-
检查所有服务器的状态
SHOW SERVERS;
+------------------------------------------------------------------------------------------------------------------------------------------+ | name | address | state | health | hosting | +------------------------------------------------------------------------------------------------------------------------------------------+ | "16cd6e9c-aa5a-4737-8ed5-e0df36ce52d3" | "gds2.default.svc.cluster.local:7687" | "Enabled" | "Available" | ["neo4j", "system"] | | "bafbe254-a8a2-498d-9b60-6b3fd0124045" | "primary.default.svc.cluster.local:7687" | "Enabled" | "Available" | ["neo4j", "system"] | | "f1478d5d-1718-4430-a9b6-26fe9695ca30" | "gds1.default.svc.cluster.local:7687" | "Enabled" | "Available" | ["neo4j", "system"] | +------------------------------------------------------------------------------------------------------------------------------------------+