vesoft-inc / nebula-python

Client API of Nebula Graph in Python
193 stars 78 forks source link

Connect to nebula server from another server #103

Closed herman72 closed 3 years ago

herman72 commented 3 years ago

I connect from another server to nebula server via this code:

from nebula2.Config import Config
from nebula2.mclient import MetaCache
from nebula2.gclient.net import ConnectionPool
from nebula2.sclient.GraphStorageClient import GraphStorageClient

config = Config()
config.max_connection_pool_size = 10

connection_pool = ConnectionPool()
ok = connection_pool.init([('192.168.10.100', 9669)], config)
session = connection_pool.get_session('admin', 'pass')
meta_cache = MetaCache([('192.168.10.100', 9559)],50000)

## for instance "192.168.10.100"  is ip address of nebula server

return for ok: true and after that I can execute query like "SHOW SPACES" but when I use graph_storage_client = GraphStorageClient(meta_cache) it returns this error:

Create storage connection failed: socket error connecting to host 127.0.0.1, port 9779 (('127.0.0.1', 9779)): ConnectionRefusedError(111, 'Connection refused')

what can I do?

wey-gu commented 3 years ago

Dear @herman72,

This error refers to storage-client cannot reach storaged via '127.0.0.1', 9779.

The storage client gets to know the stroaged interface via meta-client instance, and it's assumed(configured out-of-box in like nebula-docker-compose)not exposed outside of the nebula graph cluster(not like the graphd and metad).

If the python application only needs to do nGQL/openCypher queries(not the vertices scanning), we only need the graph-client.

If you indeed need the storage-client, corresponding network configuration should be done to ensure the storaged is accessible from where your python client is running on.

If you would like to first-time quickly try and play with everything(including storage-client) with a docker-compose deployed nebula cluster(not willing to change anything in the compose yaml file), you can try running your client from a container with the same network of the docker-compose like:

assumed the network name is nebula-docker-compose_nebula-net


$ docker run -dit --name ng-python --network nebula-docker-compose_nebula-net ubuntu:latest bash

$ docker exec -it ng-python bash $ apt update $ apt install python3 python3-pip $ pip3 install nebula2-python==2.0.0 python



Thanks!
herman72 commented 3 years ago

Dear @herman72,

This error refers to storage-client cannot reach storaged via '127.0.0.1', 9779.

The storage client gets to know the stroaged interface via meta-client instance, and it's assumed(configured out-of-box in like nebula-docker-compose)not exposed outside of the nebula graph cluster(not like the graphd and metad).

If the python application only needs to do nGQL/openCypher queries(not the vertices scanning), we only need the graph-client.

If you indeed need the storage-client, corresponding network configuration should be done to ensure the storaged is accessible from where your python client is running on.

If you would like to first-time quickly try and play with everything(including storage-client) with a docker-compose deployed nebula cluster(not willing to change anything in the compose yaml file), you can try running your client from a container with the same network of the docker-compose like:

assumed the network name is nebula-docker-compose_nebula-net

$ docker run -dit --name ng-python --network nebula-docker-compose_nebula-net ubuntu:latest bash

$ docker exec -it ng-python bash
$ apt update
$ apt install python3 python3-pip
$ pip3 install nebula2-python==2.0.0
python

Thanks!

Thanks!

wey-gu commented 3 years ago

thank you, closing it, if you consider it's not yet resolved, please feel free to reopen it, thanks.