图数据库NebulaGraph介绍和安装部署

目录

一、NebulaGraph是什么

二、NebulaGraph架构

Graph服务

Meta服务

Storage服务

数据存储格式

点存储格式

边存储格式

三、NebulaGraph安装部署

单机硬件要求

使用rpm包安装

配置文件

启动服务

服务日志

验证服务是否启动成功

设置开机自启

配置metad开机自启脚本

配置graphd开机自启脚本

配置storaged开机自启脚本

 加载自启脚本

设置开机自启

注册Storage服务

下载NebulaGraph Console

连接NebulaGraph

验证注册

四、NebulaGraph Studio简介和安装

NebulaGraph Studio简介

使用rpm包安装

下载Studio 3.7.0

安装Studio 3.7.0

验证部署

登录Studio系统


一、NebulaGraph是什么

NebulaGraph是一款优秀的国产开源的分布式图数据库, 支持千亿点和万亿边规模海量存储,查询可以做到毫秒级延迟性能优异。NebulaGraph是一个典型的图数据库,可以高效存储点、边及两者属性,适用的场景包括欺诈监测、实时推荐、知识图谱、社交网络等。其特点和优势如下:

  1. 高性能  底层使用C++编写,提供毫秒级查询,数据规模越大优势越明显。
  2. 易扩展 采用shared-nothing的分布式架构,可以将数据分片存储在多台机器上,实现水平扩展和负载均衡,支持不停机扩缩容。
  3. 易用性 提供类SQL的查询语言nGQL,兼容OpenCypher,易学易用,支持Java、Python、C++ 和 Go 等流行编程语言的客户端易开发。

 NebulaGraph官网链接:NebulaGraph

二、NebulaGraph架构

NebulaGraph是存算分离的架构,包括三种服务:Graph服务、Meta服务和Storage服务,架构图如下:

NebulaGraph architecture

Graph服务

Graphd服务由nebula-graphd进程提供,负责处理客户端查询请求,分为解析查询nGQL语句、校验nGQL语句、生成执行计划和根据执行计划进行执行四个步骤,查询引擎处理流程如下:

The architecture of the Graph Service

 Graph服务收到查询请求后,按照如下模块依次处理:

  1. Parser:词法语法解析模块。

  2. Validator:语义校验模块。

  3. Planner:执行计划与优化器模块。

  4. Executor:执行引擎模块。

Meta服务

Meta服务由nebula-metad进程提供,负责管理用户账号和权限、管理分片位置、图空间、Schema和TTL等信息。Meta集群基于Raft共识算法保证数据的一致性,Raft是强领导算法,任何时间点都只有一个leader,当leader宕机或发生网络分区时会进行leader选举,新leader由所有follower多数派投票决定。所以,Meta集群中只有一个进程是leader,其余都是follower,也只有leader能够对客户端提供读写服务,follower用于复制leader wal日志和选举新leader,Meta服务架构如下:

The architecture of the Meta Service

Storage服务

Storage服务由nebula-storaged进程提供,负责存储数据,支持高可用和水平扩展。Storage集群基于Raft协议,分为Storage interface层,Consensus层和Store Engine层,其技术架构如下:

image

最底层存储引擎是单机版自研KVStore,默认使用RocksDB作为本地存储,支持多个图空间物理隔离。

为了防止数据迁移影响线上业务只支持手动负载均衡。

数据存储格式

图存储的主要数据是点和边,KVStore是把点和边的信息作为key,点和边的属性信息存成value,属性可作为高效过滤条件。

点存储格式

3.x版本比2.x版本多了一个不含TagID和value的key。

The vertex format of storage service

各个字段说明如下:

点存储格式说明
字段 说明
Type key 类型。长度为 1 字节。
PartID

数据分片编号。长度为 3 字节。此字段主要用于 Storage 负载均衡(balance)时方便根据前缀扫描整个分片的数据。

VertexID

点 ID。当点 ID 类型为 int 时,长度为 8 字节;当点 ID 类型为 string 时,长度为创建图空间时指定的fixed_string长度。

TagID

点关联的 Tag ID。长度为 4 字节。

SerializedValue 序列化的 value,用于保存点的属性信息。

边存储格式

 The edge format of storage service

各个字段说明如下:

边存储格式说明
字段 说明
Type key 类型。长度为 1 字节。
PartID

数据分片编号。长度为 3 字节。此字段主要用于 Storage 负载均衡(balance)时方便根据前缀扫描整个分片的数据。

VertexID

点 ID。前一个VertexID在出边里表示起始点 ID,在入边里表示目的点 ID;后一个VertexID出边里表示目的点 ID,在入边里表示起始点 ID。

Edge type

边的类型。大于 0 表示出边,小于 0 表示入边。长度为 4 字节。

Rank

用来处理两点之间有多个同类型边的情况。用户可以根据自己的需求进行设置,例如存放交易时间、交易流水号等。长度为 8 字节。

PlaceHolder 预留字段。长度为 1 字节。
SerializedValue 序列化的 value,用于保存点的属性信息。

三、NebulaGraph安装部署

在测试环境进行单机安装部署,使用root用户登录,部署1个metad进程,1个storaged进程和1个graphd进程。

单机硬件要求

类型 要求
内核版本 3.9+
CPU架构 x86_64
CPU核数 4
内存 8GB

硬盘

10GB,SSD

使用rpm包安装

下载最新3.6.0 release版本,选Centos7对应版本

wget https://oss-cdn.nebula-graph.com.cn/package/3.6.0/nebula-graph-3.6.0.el7.x86_64.rpm
wget https://oss-cdn.nebula-graph.com.cn/package/3.6.0/nebula-graph-3.6.0.el7.x86_64.rpm.sha256sum.txt

执行安装命令

[root@node3 apps]# rpm -ivh nebula-graph-3.6.0.el7.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:nebula-graph-3.6.0-1             ################################# [100%]

默认安装位置为/usr/local/nebula

[root@node3 apps]# ll /usr/local/nebula
total 16
drwxr-xr-x 2 root root  106 Aug 24 17:34 bin
-rw-r--r-- 1 root root    8 Aug 24 18:36 cluster.id
drwxr-xr-x 4 root root   33 Aug 24 18:36 data
drwxr-xr-x 2 root root 4096 Aug 24 18:34 etc
drwxr-xr-x 2 root root 4096 Aug 24 18:36 logs
drwxr-xr-x 2 root root   82 Aug 24 17:36 pids
drwxr-xr-x 2 root root  202 Aug 24 17:34 scripts
drwxr-xr-x 3 root root   23 Aug 24 17:34 share

配置文件

默认所有配置文件位于/usr/local/nebula/etc,nebula-graphd.conf,nebula-metad.conf和nebula-storaged.conf为启动默认加载的配置文件。

[root@node3 apps]# ll /usr/local/nebula/etc
total 64
-rw-r--r-- 1 root root 5077 Aug 24 17:34 nebula-graphd.conf
-r--r--r-- 1 root root 5077 Jul 20 11:23 nebula-graphd.conf.default
-r--r--r-- 1 root root 4855 Jul 20 11:23 nebula-graphd.conf.production
-rw-r--r-- 1 root root 1973 Aug 24 17:34 nebula-metad.conf
-r--r--r-- 1 root root 1973 Jul 20 11:23 nebula-metad.conf.default
-r--r--r-- 1 root root 1976 Jul 20 11:23 nebula-metad.conf.production
-rw-r--r-- 1 root root 5965 Aug 24 17:34 nebula-storaged.conf
-r--r--r-- 1 root root 5965 Jul 20 11:23 nebula-storaged.conf.default
-r--r--r-- 1 root root 6240 Jul 20 11:23 nebula-storaged.conf.production
-r--r--r-- 1 root root 2096 Jul 20 11:23 nebula-storaged-listener.conf.production

启动服务

NebulaGraph使用nebula.service启动服务,执行后依次启动metad服务,graphd服务和storaged服务。

[root@node3 apps]# /usr/local/nebula/scripts/nebula.service start all
[INFO] Starting nebula-metad...
[INFO] Done
[INFO] Starting nebula-graphd...
[INFO] Done
[INFO] Starting nebula-storaged...
[INFO] Done

服务日志

默认所有日志文件位于/usr/local/nebula/logs,如果启动异常可查看相应error日志。

[root@node3 apps]# ll /usr/local/nebula/logs/
total 200
-rw-r--r-- 1 root root     0 Aug 24 17:36 graphd-stderr.log
-rw-r--r-- 1 root root     0 Aug 24 17:36 graphd-stdout.log
-rw-r--r-- 1 root root     0 Aug 24 17:36 metad-stderr.log
-rw-r--r-- 1 root root     0 Aug 24 17:36 metad-stdout.log
lrwxrwxrwx 1 root root    54 Aug 24 17:36 nebula-graphd.INFO -> nebula-graphd.node3.root.log.INFO.20230824-173614.1660
-rw-r--r-- 1 root root  1206 Aug 24 17:36 nebula-graphd.node3.root.log.INFO.20230824-173614.1660
lrwxrwxrwx 1 root root    54 Aug 24 17:36 nebula-metad.ERROR -> nebula-metad.node3.root.log.ERROR.20230824-173614.1591
lrwxrwxrwx 1 root root    53 Aug 24 17:36 nebula-metad.INFO -> nebula-metad.node3.root.log.INFO.20230824-173614.1591
-rw-r--r-- 1 root root   323 Aug 24 17:36 nebula-metad.node3.root.log.ERROR.20230824-173614.1591
-rw-r--r-- 1 root root 81570 Aug 24 17:54 nebula-metad.node3.root.log.INFO.20230824-173614.1591
-rw-r--r-- 1 root root   323 Aug 24 17:36 nebula-metad.node3.root.log.WARNING.20230824-173614.1591
lrwxrwxrwx 1 root root    56 Aug 24 17:36 nebula-metad.WARNING -> nebula-metad.node3.root.log.WARNING.20230824-173614.1591
lrwxrwxrwx 1 root root    57 Aug 24 17:36 nebula-storaged.ERROR -> nebula-storaged.node3.root.log.ERROR.20230824-173617.1729
lrwxrwxrwx 1 root root    56 Aug 24 17:36 nebula-storaged.INFO -> nebula-storaged.node3.root.log.INFO.20230824-173614.1729
-rw-r--r-- 1 root root  8309 Aug 24 17:54 nebula-storaged.node3.root.log.ERROR.20230824-173617.1729
-rw-r--r-- 1 root root 25196 Aug 24 17:54 nebula-storaged.node3.root.log.INFO.20230824-173614.1729
-rw-r--r-- 1 root root 17605 Aug 24 17:54 nebula-storaged.node3.root.log.WARNING.20230824-173614.1729
lrwxrwxrwx 1 root root    59 Aug 24 17:36 nebula-storaged.WARNING -> nebula-storaged.node3.root.log.WARNING.20230824-173614.1729
-rw-r--r-- 1 root root     0 Aug 24 17:36 storaged-stderr.log
-rw-r--r-- 1 root root     0 Aug 24 17:36 storaged-stdout.log

验证服务是否启动成功

[root@node3 apps]# /usr/local/nebula/scripts/nebula.service status all
[INFO] nebula-metad(de9b3ed): Running as 1591, Listening on 9559
[INFO] nebula-graphd(de9b3ed): Running as 1660, Listening on 9669
[WARN] nebula-storaged after v3.0.0 will not start service until it is added to cluster.
[WARN] See Manage Storage hosts:ADD HOSTS in https://docs.nebula-graph.io/
[INFO] nebula-storaged(de9b3ed): Running as 1729, Listening on 9779

出现WARN信息,因为从3.0.0版本起, 配置文件中添加的 Storage 主机无法直接读写,配置文件的作用仅仅是将 Storage 主机注册至 Meta 服务中。必须使用ADD HOSTS命令后,才能正常读写 Storage 主机,下一步需要注册Storage服务。

设置开机自启

配置metad开机自启脚本

编辑配置文件/lib/systemd/system/metad.service

[root@node3 ~]# vim /lib/systemd/system/metad.service
[Unit]
Description=metad
After=network.target

[Service]
Type=forking
Restart=always
RestartSec=5s
PIDFile=/usr/local/nebula/pids/nebula-metad.pid
ExecStart=/usr/local/nebula/scripts/nebula.service start metad
ExecReload=/usr/local/nebula/scripts/nebula.service restart metad
ExecStop=/usr/local/nebula/scripts/nebula.service stop metad
PrivateTmp=true

[Install]
WantedBy=multi-user.target

配置graphd开机自启脚本

编辑配置文件/lib/systemd/system/graphd.service

[root@node3 ~]# vim /lib/systemd/system/graphd.service
[Unit]
Description=graphd
After=network.target

[Service]
Type=forking
Restart=always
RestartSec=5s
PIDFile=/usr/local/nebula/pids/nebula-graphd.pid
ExecStart=/usr/local/nebula/scripts/nebula.service start graphd
ExecReload=/usr/local/nebula/scripts/nebula.service restart graphd
ExecStop=/usr/local/nebula/scripts/nebula.service stop graphd
PrivateTmp=true

[Install]
WantedBy=multi-user.target

配置storaged开机自启脚本

编辑配置文件/lib/systemd/system/storaged.service

[root@node3 ~]# vim /lib/systemd/system/storaged.service
[Unit]
Description=storaged
After=network.target

[Service]
Type=forking
Restart=always
RestartSec=5s
PIDFile=/usr/local/nebula/pids/nebula-storaged.pid
ExecStart=/usr/local/nebula/scripts/nebula.service start storaged
ExecReload=/usr/local/nebula/scripts/nebula.service restart storaged
ExecStop=/usr/local/nebula/scripts/nebula.service stop storaged
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 加载自启脚本

systemctl daemon-reload

设置开机自启

systemctl enable metad.service
systemctl enable graphd.service
systemctl enable storaged.service

注册Storage服务

首先需要连接到NebulaGraph,再执行添加Storage主机(ADD HOSTS),并确认主机都处于在线状态。

下载NebulaGraph Console

通过命令行客户端NebulaGraph Console连接NebulaGraph,从github下载最新的版本。

wget https://github.com/vesoft-inc/nebula-console/releases/download/v3.5.0/nebula-console-linux-amd64-v3.5.0

重命名nebula-console客户端

mv nebula-console-linux-amd64-v3.5.0 nebula-console

连接NebulaGraph

使用God缺省账号密码root/nebula连接NebulaGraph

# ./nebula-console -addr 192.168.5.12 -P 9669 -u root -p nebula
(root@nebula) [(none)]> ADD HOSTS 192.168.5.12:9779
Execution succeeded (time spent 2.218ms/33.088291ms)

Thu, 24 Aug 2023 18:16:18 CST

# 验证是否添加成功
(root@nebula) [(none)]> show hosts;
+----------------+------+-----------+--------------+----------------------+------------------------+---------+
| Host           | Port | Status    | Leader count | Leader distribution  | Partition distribution | Version |
+----------------+------+-----------+--------------+----------------------+------------------------+---------+
| "192.168.5.12" | 9779 | "OFFLINE" | 0            | "No valid partition" | "No valid partition"   |         |
+----------------+------+-----------+--------------+----------------------+------------------------+---------+
Got 1 rows (time spent 1.059ms/9.404375ms)

Thu, 24 Aug 2023 18:16:32 CST

注意此处Status为"OFFLINE",表示状态不在线添加失败了,原因是要添加的主机IP和配置文件nebula-storaged.conflocal_ip必须一致。修改配置文件如下:

[root@node3 logs]# vim /usr/local/nebula/etc/nebula-storaged.conf
--local_ip=192.168.5.12

# 重启服务使生效
[root@node3 logs]# /usr/local/nebula/scripts/nebula.service restart storaged
[INFO] Stopping nebula-storaged...
[INFO] Done
[INFO] Starting nebula-storaged...
[INFO] Done

# curl验证当前配置是否生效
[root@node3 logs]# curl --silent http://192.168.5.12:19779/flags |  grep local_ip
local_ip="192.168.5.12"

验证注册

Status为ONLINE则表示注册成功。

(root@nebula) [(none)]> show hosts;
2023/08/24 18:36:26 [INFO] Successfully reconnect to host: 192.168.5.12, port: 9669
+----------------+------+----------+--------------+----------------------+------------------------+---------+
| Host           | Port | Status   | Leader count | Leader distribution  | Partition distribution | Version |
+----------------+------+----------+--------------+----------------------+------------------------+---------+
| "192.168.5.12" | 9779 | "ONLINE" | 0            | "No valid partition" | "No valid partition"   | "3.6.0" |
+----------------+------+----------+--------------+----------------------+------------------------+---------+
Got 1 rows (time spent 2.576ms/18.787666ms)

四、NebulaGraph Studio简介和安装

NebulaGraph Studio简介

NebulaGraph Studio是一款开源图数据库Web可视化工具,搭配NebulaGraph使用,提供数据建模、数据导入、nGQL查询等一站式服务。

使用rpm包安装

下载Studio 3.7.0

wget https://oss-cdn.nebula-graph.com.cn/nebula-graph-studio/3.7.0/nebula-graph-studio-3.7.0.x86_64.rpm
wget https://oss-cdn.nebula-graph.com.cn/nebula-graph-studio/3.7.0/nebula-graph-studio-3.7.0.x86_64.rpm.sha256

安装Studio 3.7.0

需求提前安装好lsof工具,安装好Studio会自动启动

[root@node3 apps]# rpm -ivh nebula-graph-studio-3.7.0.x86_64.rpm
Preparing...                          ################################# [100%]
Start installing NebulaGraph Studio now...
Updating / installing...
   1:nebula-graph-studio-3.7.0-1      ################################# [100%]
NebulaGraph Studio has been installed.
Created symlink from /etc/systemd/system/multi-user.target.wants/nebula-graph-studio.service to /usr/lib/systemd/system/nebula-graph-studio.service.
NebulaGraph Studio started automatically.

验证部署

浏览器地址栏输入http://192.168.5.12:7001,打开登录页面,如下表示部署成功。

登录Studio系统

配置数据库连接信息,输入graphd IP地址,默认端口9669,账号密码使用root/nebula,进入欢迎主页。

猜你喜欢

转载自blog.csdn.net/BlogPan/article/details/132480670