Docker에서 Provate 서브넷에 구성된 Neptune에 연결
4618 단어 NeptuneAWSAmazonNeptune
컨디션
대략적인 절차
.ssh/config
에서 포트 전달 설정.ssh/
를 설치ssh/config에 포트 전송 쓰기
Host neptune
HostName 踏み台EC2のPublicIP
User ec2-user
IdentityFile ~/.ssh/EC2の鍵ファイル.pem
GatewayPorts yes
LocalForward 8182 接続したいNeptuneクラスターエンドポイント:8182
Docker file 준비
어쨌든 python 3.6 의 공식 이미지를 사용한다.
FROM python:3.6
RUN apt-get update -y && apt-get upgrade -y
RUN apt-get install autossh -y
RUN mkdir /root/.ssh
docker-compose.준비
부족한 점은 보충해 주세요.
내가 한 일
.ssh/config
를 장착/root/.sshdummy
gremlin-python
이 https://localhost
로 연결되면 오류가 발생할 수 있기 때문이다.version: '3'
services:
gremlin:
command: >
/bin/bash -c "cp /root/.sshdummy/config /root/.ssh/ &&
cp /root/.sshdummy/EC2の鍵ファイル.pem /root/.ssh/ &&
chmod 600 /root/.ssh/EC2の鍵ファイル.pem &&
autossh neptune -f -N &&
/bin/bash"
volumes:
- ~/.ssh:/root/.sshdummy
-
extra_hosts:
- "Neptuneクラスターエンドポイント:127.0.0.1"
먼저 접속 확인
docker-compose run gremlin
그리고 들어가서 아래를 두드려 보세요.curl https://Neptuneクラスターのエンドポイント:8182
> {"requestId":"28b45dc4-842c-c129-2d4d-******","detailedMessage":"no gremlin script supplied","code":"MissingParameterException"}
다녀왔습니다.연결 가능합니다.gremlin-python으로 볼게요.
매크로 패키지를 설치합니다.
pip install gremlinpython
저는 현재 역'네타아'노선 검색 서비스를 제공하는 회사에서 일하고 있기 때문에 역 데이터와 노선 데이터를 네타넷에 불러와 간단한 노선 검색을 하고 싶습니다.가까스로 차트 DB를 사용해 N 정점~N 정점의 경로를 검색했다.
from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.structure.graph import VertexProperty
import time
graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection('wss://Neptuneクラスターのエンドポイント:8182/gremlin','g'))
# 出発地点
origin = g.V().has('station', '県コードキー', '県コード').has('駅種別キー', 駅種別).sample(10).toList()
# 到着地点
destination = g.V().has('station', '県コードキー', '県コード').has('駅種別キー', 駅種別).sample(10).toList()
# 頂点IDの配列化
origin_ids = [x.id for x in origin]
destination_ids = [x.id for x in destination]
start_time = time.time()
result = g.V().hasId(*origin_ids).repeat(__.outE().hasLabel('特定の辺のラベルのみ').inV().simplePath()).until(__.hasId(*destination_ids)).path().limit(100).map(__.unfold().hasLabel('station').values('name').fold())
for path in result.toList():
print('->'.join(path))
print(time.time() - start_time)
결실大崎広小路->五反田->戸越->中延
大崎広小路->戸越銀座->荏原中延->旗の台->荏原町->中延
青物横丁->新馬場->北品川->品川->大崎->五反田->大崎広小路
大崎広小路->五反田->大崎->大井町->下神明->戸越公園->中延
〜〜〜〜 省略 〜〜〜〜〜
代田橋->笹塚->新宿->四ツ谷->御茶ノ水->秋葉原->浅草橋->両国->錦糸町->押上
大崎広小路->五反田->大崎->品川->新橋->東銀座->銀座->東京->上野->日暮里->新三河島
青物横丁->新馬場->北品川->品川->新橋->東銀座->銀座->東京->上野->日暮里->新三河島
代田橋->笹塚->新宿->池袋->板橋->十条(東京都)->赤羽->尾久->上野->日暮里->新三河島0.43123531341552734(←処理時間
다 됐습니다.주의할 점
Neptune에서 사용하는 Gremlin은 완전히 호환된다고 할 수 없습니다.
Reference
이 문제에 관하여(Docker에서 Provate 서브넷에 구성된 Neptune에 연결), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/RyujiKawazoe/items/abc52fd11c49b0ae897d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)