目录
nebula安装
最小集群安装
1、下载nebula graph(多线程下载)
yum install axel
axel -a -n 10 https://oss-cdn.nebula-graph.com.cn/package/2.0.1/nebula-graph-2.0.1.el7.x86_64.rpm
cp *~
cd /data/mlamp/workspace/nebulagraph
安装
rpm -ivh nebula-graph-2.0.1.el7.x86_64.rpm
2、修改三个配置文件(三台服务器)nebula-metad.conf、nebula-graphd.conf、nebula-storaged.conf
vim /usr/local/nebula/etc/nebula-metad.conf
--local_conf=true
--meta_server_addrs=172.19.208.25:9559,172.19.208.20:9559,172.19.208.42:9559
--local_ip=172.19.208.25(本机ip)
--ws_ip=172.19.208.25(本机ip)
vim /usr/local/nebula/etc/nebula-graphd.conf
--local_conf=true
--meta_server_addrs=172.19.208.25:9559,172.19.208.20:9559,172.19.208.42:9559
--local_ip=172.19.208.25(本机ip)
--ws_ip=172.19.208.25(本机ip)
vim /usr/local/nebula/etc/nebula-storaged.conf
--local_conf=true
--meta_server_addrs=172.19.208.25:9559,172.19.208.20:9559,172.19.208.42:9559
--local_ip=172.19.208.25(本机ip)
--ws_ip=172.19.208.25(本机ip)
3、启动(三台服务器)
/usr/local/nebula/scripts/nebula.service start all
4、下载 nebula-console
wget https://github.com/vesoft-inc/nebula-console/releases/download/v2.0.1/nebula-console-linux-amd64-v2.0.1
mv nebula-console-linux-amd64-v2.0.1 nebula-console
chmod 111 nebula-console
### 9996 graphd is 9669
./nebula-console --addr=172.19.208.25 --port=9669 -u user -p password
show hosts
show spaces
验证
5、下载 studio
axel -a -n 10 https://oss-cdn.nebula-graph.com.cn/nebula-graph-studio/nebula-graph-studio-2.2.1-7.x86_64.rpm
安装
rpm -i nebula-graph-studio-2.2.1-7.x86_64.rpm
安装 nodejs
版本不匹配,卸载npm
npm uninstall npm -g
版本不匹配,卸载nodejs
yum remove nodejs npm -y
安装nodejs
下载nodejs(/usr/local)
wget https://nodejs.org/dist/v14.16.0/node-v14.16.0-linux-x64.tar.xz
mv node-v14.16.0-linux-x64 nodejs
软连
ln -s /usr/local/nodejs/bin/node /usr/bin/node
ln -s /usr/local/nodejs/bin/npm /usr/bin/npm
启动studio
/usr/local/nebula-graph-studio/scripts
chmod +x *
start.sh
stop.sh
nebula graph studio
登陆地址 http://x.x.x.x:7180/
三台服务器 数据库
host
172.19.208.25:9669
172.19.208.20:9669
172.19.208.42:9669
用户名:user(默认未开启)
密码:password(默认未开启)
go环境搭建
1、下载
wget wget https://golang.google.cn/dl/go1.16.6.linux-amd64.tar.gz
tar -zxvf go1.16.6.linux-amd64.tar.gz
2、配置环境
vim /etc/profile.d/go.sh
PATH=$PATH:/data/mlamp/workspace/go/bin
source /etc/profile.d/go.sh
vim /etc/profile.d/gopath.sh
GOPATH=/data/mlamp/workpace/gopath
source /etc/profile.d/gopath.sh
3、验证go环境
echo $GOPATH
4、配置 nebula模块
直接go get github.com/vesoft-inc/nebula-go/v2 报错
设置代理
go env -w GOPROXY=https://goproxy.cn
go env -w GO111MODULE=auto
go get github.com/vesoft-inc/nebula-go/v2
生成mod文件
go mod init nebula.go
编译
go bulid nebula.go
5、运行
go run nebula.go
附go连接nebula代码(官方)
package main
import (
"fmt"
nebula "github.com/vesoft-inc/nebula-go/v2"
)
const (
address = "172.19.208.25"
// The default port of Nebula Graph 2.x is 9669.
// 3699 is only for testing.
port = 9669
username = "root"
password = "nebula"
)
// Initialize logger
var log = nebula.DefaultLogger{}
func main() {
hostAddress := nebula.HostAddress{Host: address, Port: port}
hostList := []nebula.HostAddress{hostAddress}
// Create configs for connection pool using default values
testPoolConfig := nebula.GetDefaultConf()
// Initialize connection pool
pool, err := nebula.NewConnectionPool(hostList, testPoolConfig, log)
if err != nil {
log.Fatal(fmt.Sprintf("Fail to initialize the connection pool, host: %s, port: %d, %s", address, port, err.Error()))
}
// Close all connections in the pool
defer pool.Close()
// Create session
session, err := pool.GetSession(username, password)
if err != nil {
log.Fatal(fmt.Sprintf("Fail to create a new session from connection pool, username: %s, password: %s, %s",
username, password, err.Error()))
}
// Release session and return connection back to connection pool
defer session.Release()
checkResultSet := func(prefix string, res *nebula.ResultSet) {
if !res.IsSucceed() {
log.Fatal(fmt.Sprintf("%s, ErrorCode: %v, ErrorMsg: %s", prefix, res.GetErrorCode(), res.GetErrorMsg()))
}
}
{
// Prepare the query
createSchema := "CREATE SPACE IF NOT EXISTS basic_example_space(vid_type=FIXED_STRING(20)); " +
"USE basic_example_space;" +
"CREATE TAG IF NOT EXISTS person(name string, age int);" +
"CREATE EDGE IF NOT EXISTS like(likeness double)"
// Excute a query
resultSet, err := session.Execute(createSchema)
if err != nil {
fmt.Print(err.Error())
return
}
checkResultSet(createSchema, resultSet)
}
// Drop space
{
query := "DROP SPACE IF EXISTS basic_example_space"
// Send query
resultSet, err := session.Execute(query)
if err != nil {
fmt.Print(err.Error())
return
}
checkResultSet(query, resultSet)
}
fmt.Print("\n")
log.Info("Nebula Go Client Basic Example Finished")
}
互相交流,共同进步