Use the Gremlin console to connect to a Graph Database instance
This topic describes how to use the Gremlin console to connect to and manage a Graph Database (GDB) instance.
Preparations
Before you perform the following operations, make sure that your GDB instance and your Elastic Compute Service (ECS) instance are deployed in the same virtual private cloud (VPC):
The Gremlin console requires Java 8. If Java 8 is not installed, run the following command.
sudo yum install java-1.8.0-develIf your ECS instance has multiple Java versions, set Java 8 as the default. For example:
sudo /usr/sbin/alternatives --config javaThere are four programs that provide Java.
+ 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre/bin/java) 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.el7_5.x86_64-debug/jre/bin/java) 3 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.191-2.6.15.4.el7_5.x86_64/jre/bin/java) 4 /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/javaDownload the latest version of the Gremlin console from the official Apache Tinkerpop website.
wget https://archive.apache.org/dist/tinkerpop/3.4.4/apache-tinkerpop-gremlin-console-3.4.4-bin.zipUnzip the file and change to the apache-tinkerpop-gremlin-console-3.4.4 folder.
unzip apache-tinkerpop-gremlin-console-3.4.4-bin.zip cd apache-tinkerpop-gremlin-console-3.4.4Create a configuration file named
conf/gdb-remote.yamlto connect the Gremlin console to the GDB instance. In the file:Replace
${your_gdb_endpoint}with the domain name of your GDB instance.Replace
${username}with the username for your GDB instance.Replace
${password}with the password for your GDB instance.hosts: [ ${your_gdb_endpoint} ] port: 8182 username: ${username} password: ${password} serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0, config: { serializeResultToString: true } }
Establish a connection
From the Gremlin console home directory, run the
./bin/gremlin.shcommand to start the console. The output is similar to the following:\,,,/ (o o) -----oOOo-(3)-oOOo----- plugin activated: tinkerpop.server plugin activated: tinkerpop.utilities plugin activated: tinkerpop.tinkergraph gremlin>Run the following command to connect to the GDB instance. Do not omit the leading colon.
:remote connect tinkerpop.server conf/gdb-remote.yamlThe output shows the host and port of the connected GDB instance.
==>Configured gds-uf6rge6e35594khg150010.graphdb.rds.aliyuncs.com/192.X.X.X:XXXXRun the following command to switch to remote mode. In remote mode, all Gremlin Domain-Specific Language (DSL) statements that you enter in the console are sent to the remote GDB instance. Do not omit the leading colon.
:remote consoleThe output is similar to the following:
==>All scripts will now be sent to Gremlin Server - [iz2ze30qqhwn3ba5mu2qgiz/172.X.X.X:XXXX] - type ':remote console' to return to local modeYou can now run Gremlin statements. To analyze the performance of a statement, append .profile() to it. For example:
g.V().count().profile()The default timeout is 30 seconds. To change the timeout period, run the following command. The time unit is milliseconds.
:remote config timeout 60000