Set up the Gremlin console to connect to a Neptune DB instance

2022年05月14日


The Gremlin Console allows you to experiment with TinkerPop graphs and queries in a REPL (read-eval-print loop) environment.

Installing the Gremlin console and connecting to it in the usual way
You can use the Gremlin Console to connect to a remote graph database. The following section walks you through installing and configuring the Gremlin Console to connect remotely to a Neptune DB instance. You must follow these instructions from an Amazon EC2 instance in the same virtual private cloud (VPC) as your Neptune DB instance.


To install the Gremlin Console and connect to Neptune

The Gremlin Console binaries require Java 8. Enter the following to install Java 8 on your EC2 instance.
sudo yum install -y java-1.8.0-devel

Enter the following to set Java 8 as the default runtime on your EC2 instance.
sudo /usr/sbin/alternatives --config java

共有 1 个提供“java”的程序。

  选项    命令
-----------------------------------------------
*+ 1           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java)

按 Enter 保留当前选项[+],或者键入选项编号:1
When prompted, enter the number for Java 8.

Download the appropriate version of the Gremlin console from the Apache web site. You can check the engine release page for the Neptune engine version you are currently running to determine which Gremlin version it supports. For example, for version 3.5.2, you can download the Gremlin console from the Apache Tinkerpop3 website onto your EC2 instance like this:
wget https://archive.apache.org/dist/tinkerpop/3.5.2/apache-tinkerpop-gremlin-console-3.5.2-bin.zip

Unzip the Gremlin Console zip file.
unzip apache-tinkerpop-gremlin-console-3.5.2-bin.zip

Change directories into the unzipped directory.
cd apache-tinkerpop-gremlin-console-3.5.2

Install the CA certificate. Gremlin Console requires a certificate to verify the remote certificate.
Download the certificate:
wget https://www.amazontrust.com/repository/SFSRootCAG2.cer

Create a directory for certificates:
mkdir /tmp/certs/

Query for the JRE path.
readlink -f $(which java)
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java

Copy Java certificates into the new directory:
cp /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/lib/security/cacerts /tmp/certs/cacerts

Add the Amazon certificate to the repository:
sudo keytool -importcert \
> -alias neptune-tests-ca \
> -keystore /tmp/certs/cacerts \
> -file /home/ec2-user/apache-tinkerpop-gremlin-console-3.5.2/SFSRootCAG2.cer \
> -noprompt \
> -storepass changeit
sudo keytool -importcert \
               -alias neptune-tests-ca \
               -keystore /tmp/certs/cacerts \
               -file  /home/ec2-user/apache-tinkerpop-gremlin-console-3.5.2/SFSRootCAG2.cer \
               -noprompt \
               -storepass changeit

证书已添加到密钥库中

In the conf subdirectory of the extracted directory, create a file named neptune-remote.yaml with the following text. Replace your-neptune-endpoint with the hostname or IP address of your Neptune DB instance. The square brackets ([ ]) are required.
Note

For information about finding the hostname of your Neptune DB instance, see the Connecting to Amazon Neptune Endpoints section.


vim conf/neptune-remote.yaml
...
hosts: [modern-toy-cluster.cluster-cn***q9.us-west-2.neptune.amazonaws.com]
port: 8182
connectionPool: { enableSsl: true,  trustStore: /tmp/certs/cacerts }
serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1, config: { serializeResultToString: true }}

In a terminal, navigate to the Gremlin Console directory (apache-tinkerpop-gremlin-console-3.5.2), and then enter the following command to run the Gremlin Console.
bin/gremlin.sh
You should see the following output:
五月 14, 2022 11:59:17 上午 java.util.prefs.FileSystemPreferences$1 run
信息: Created user preferences directory.

         \,,,/
         (o o)
-----oOOo-(3)-oOOo-----
plugin activated: tinkerpop.server
plugin activated: tinkerpop.utilities
plugin activated: tinkerpop.tinkergraph

You are now at the gremlin> prompt. You will enter the remaining steps at this prompt.

gremlin> :remote connect tinkerpop.server conf/neptune-remote.yaml
==>Configured modern-toy-cluster.cluster-cn***q9.us-west-2.neptune.amazonaws.com/10.*.*.183:8182

At the gremlin> prompt, enter the following to connect to the Neptune DB instance.
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [modern-toy-cluster.cluster-cn***q9.us-west-2.neptune.amazonaws.com/10.*.*.183:8182] - type ':remote console' to return to local mode

Enter the following to send a query to the Gremlin Graph.
gremlin> g.V().limit(1)
==>v[1]

When you are finished, enter the following to exit the Gremlin Console.
gremlin> :exit


References

Set up the Gremlin console to connect to a Neptune DB instance

Category: GraphDB Tags: public

Upvote


Downvote