问题描述
我想知道如何让 neo4j 与 Google Compute Engine 一起工作.有没有人做过这个?您遇到了哪些问题?
给你,
基本设置
- 安装和设置
gcloud
- 安装py2neo
- 创建您的 GCE 实例(https://console.developers.google.com/project/PROJECT_APPID/compute/instancesAdd) 使用镜像(debian-7-wheezy-v20141021,Debian GNU/Linux 7.7 (wheezy) amd64 构建于 2014-10-21 或 ANY)
- SSH 你的实例
gcloud compute ssh INSTANCE_NAME --zone AVAILABLE_ZONES
-->AVAILABLE_ZONES - 在 GCE 中下载并安装
neo4j
- 您可能需要安装 java(修复)和 lsof(修复:apt-get install lsof
).
GCE 配置
(可选),添加 neo4j https 支持
将 neo4j 端口 7474 列入白名单(更多关于网络和防火墙)>
从 github用户名:密码>
gcloud compute firewall-rules create neo4j --network default --allow tcp:7474
玩转
- 启动neo4j服务器
./bin/neo4j start
- 检查您正在运行的实例@
http://IP_ADDRESS:7474/
一旦 py2neo
安装和服务器启动,尝试一些 pycode 来测试它
>>从 py2neo.neo4j 导入 GraphDatabaseService,CypherQuery>># 建立到本地图数据库的链接.>># 当 () 留空时默认为 http://localhost:7474/db/data/>>图 = GraphDatabaseService('http://IP_ADDRESS:7474/db/data/')>>CypherQuery(graph, "CREATE (n {name:'Example'}) RETURN n;").execute()
以上python设置/代码,你也可以在GAE中使用.
参考文献
Appengine + Neo4j
from py2neo import neo4jGRAPH_DB = neo4j.GraphDatabaseService('http://uname:psswd@localhost:7474/db/data/')如果 IS_PROD:GRAPH_DB = neo4j.GraphDatabaseService('http://uname:psswd@host:port/db/data/')def _execute(查询):"执行所有neo4j查询并返回Record对象列表.返回:返回 Record 对象的列表."尝试:结果 = neo4j.CypherQuery(GRAPH_DB, query).execute()# logging.info(result.data)返回结果除了 neo4j.CypherError 作为错误:logging.error(error.exception)除了 DeadlineExceededError 作为死:logging.warn(死)除了 urlfetch_errors.InternalTransientError 作为 tra_error:logging.warn(tra_error)除了 httplib.HTTPException 作为 exp:logging.warn(exp)除了作为 soc 的 neo4j.http.SocketError:logging.warn(soc)
I'm wondering how one would get neo4j to work with Google Compute Engine. Has anybody done this? What problems did you encounter?
Here you go,
Basic Setup
- Install and setup
gcloud
- Install py2neo
- Create your GCE Instance (https://console.developers.google.com/project/PROJECT_APPID/compute/instancesAdd) using image (debian-7-wheezy-v20141021, Debian GNU/Linux 7.7 (wheezy) amd64 built on 2014-10-21 or ANY)
- SSH your instance
gcloud compute ssh INSTANCE_NAME --zone AVAILABLE_ZONES
--> AVAILABLE_ZONES - Download and Install
neo4j
in GCE - You may need to install java(Fix) and lsof (Fix:apt-get install lsof
).
Configuration for GCE
(Optional), Add neo4j https support
Whitelist neo4j port 7474 (More on Networking and Firewalls)
Add security username:password from github
gcloud compute firewall-rules create neo4j --network default --allow tcp:7474
Play around
- Start neo4j server
./bin/neo4j start
- Check your running instances @
http://IP_ADDRESS:7474/
Once py2neo
Installed and server started, try some pycode to test it
>> from py2neo.neo4j import GraphDatabaseService, CypherQuery
>> # Set up a link to the local graph database.
>> # When () left blank defaults to http://localhost:7474/db/data/
>> graph = GraphDatabaseService('http://IP_ADDRESS:7474/db/data/')
>> CypherQuery(graph, "CREATE (n {name:'Example'}) RETURN n;").execute()
Above python setup / code, you can use it in GAE as well.
References
- Check pricing of GCE.
- py2neo Cookbook
- Compute Instances
- gcloud compute
Edit: Appengine + Neo4j
from py2neo import neo4j
GRAPH_DB = neo4j.GraphDatabaseService(
'http://uname:psswd@localhost:7474/db/data/')
if IS_PROD:
GRAPH_DB = neo4j.GraphDatabaseService(
'http://uname:psswd@host:port/db/data/')
def _execute(query):
"""Execute all neo4j queries and return list of Record objects.
Returns:
Returns list of Record objects.
"""
try:
result = neo4j.CypherQuery(GRAPH_DB, query).execute()
# logging.info(result.data)
return result
except neo4j.CypherError as error:
logging.error(error.exception)
except DeadlineExceededError as dead:
logging.warn(dead)
except urlfetch_errors.InternalTransientError as tra_error:
logging.warn(tra_error)
except httplib.HTTPException as exp:
logging.warn(exp)
except neo4j.http.SocketError as soc:
logging.warn(soc)
这篇关于您如何设置 neo4j 以与 Google Compute Engine 配合使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!