Help Center> GeminiDB> GeminiDB Influx API> Best Practices> Buying and Connecting to a GeminiDB Influx Instance
Updated on 2024-02-07 GMT+08:00

Buying and Connecting to a GeminiDB Influx Instance

This section describes how to buy a GeminiDB Influx instance and uses a Linux ECS as an example to describe how to connect to the instance over a private network.

Step 1: Buy a GeminiDB Influx Instance

  1. Log in to the management console.
  2. In the service list, choose Databases > GeminiDB Influx API.
  3. On the Instances page, click Buy DB Instance.
  4. Click Buy DB Instance, select a billing mode, and configure instance parameters. Then, click Next and complete subsequent operations.

    Figure 1 Basic information
    Figure 2 Selecting specifications
    Figure 3 Setting a password

  5. View the purchased GeminiDB Influx instance.

    Figure 4 Successful purchase

Step 2: Buy an Instance

  1. Log in to the management console.
  2. In the service list, choose Compute > Elastic Cloud Server. On the Elastic Cloud Server console, click Buy ECS.

    Figure 5 Logging in to the ECS console

  3. Configure basic settings and click Next: Configure Network. Make sure that the ECS is in the same region, AZ, VPC, and security group as the GeminiDB Influx instance you created.

    Figure 6 Basic settings
    Figure 7 Selecting specifications
    Figure 8 Selecting an image

  4. Configure the ECS network and click Next: Configure Advanced Settings. Make sure that the ECS is in the same VPC and security group as the GeminiDB Influx instance.

    • If security group rules allow access from the ECS, you can connect to the instance using the ECS.
    • If the security group rules do not allow access from the ECS, add an inbound rule to the security group.
    Figure 9 Network settings
    Figure 10 Selecting an EIP

  5. Configure a password for the ECS and click Next: Confirm.

    Figure 11 Advanced settings

  6. Confirm the configurations and click Submit.

    Figure 12 Confirming the configurations

  7. View the purchased ECS.

Step 3: Connect to the GeminiDB Influx Instance

  1. On the ECS console, log in to the ECS using the remote login option.

    Figure 13 Remote login

  2. Enter the username and password of the ECS.

    Figure 14 Entering the username and password

  3. Download the InfluxDB client.

    Method 1:

    wget https://dl.influxdata.com/influxdb/releases/influxdb-1.7.9-static_linux_amd64.tar.gz

    Method 2:

    Download the InfluxDB client package using your browser and upload the package to the ECS.

  4. Decompress the client package.

    tar -xzf influxdb-1.7.9-static_linux_amd64.tar.gz

  5. Connect to your instance in the directory where the InfluxDB client is located.

    1. Run the following command to go to the InfluxDB directory:

      cd influxdb-1.7.9-1

    2. Connect to the GeminiDB Influx instance.

      ./influx -ssl -unsafeSsl -username '<DB_USER>' -password '<DB_PWD>' -host <DB_HOST> -port <DB_PORT>

      Example:

      ./influx -ssl -unsafeSsl -username 'rwuser' -password '<DB_PWD>' -host 192.xx.xx.xx -port 8635

      Table 1 Required description

      Parameter

      Description

      <DB_USER>

      Username of the administrator account. The default value is rwuser.

      On the Instances page, locate the instance and click its name. In the DB Information area on the Basic Information page, you can find the administrator username.

      <DB_PWD>

      Administrator password

      <DB_HOST>

      Load balancer address of the instance to be connected.

      The load balancer address is in the open beta test (OBT) phase. To use it, contact customer service.

      Scenario 1:

      If you have obtained a load balancer address before creating an instance, you can view that the load balancer address is selected by default on the instance creation page.

      After the instance is created, click its name to go to the Basic Information page and obtain the load balancer IP address in the Network Information area.

      Scenario 2:

      If you have already created an instance, you can contact customer service to assign a load balancer IP address to the instance.

      Then you can click the instance name to view the load balancer IP address in the Network Information area on the Basic Information page.

      <DB_PORT>

      Port for accessing the instance.

      Click the name of the instance to go to the Basic Information page. In the Network Information area, you can find the database port.

  6. If information similar to the following is displayed, the connection was successful.

    Connected to https://host:port version 1.7.4
    InfluxDB shell version: 1.7.9
    >

Basic Syntax

  • Database syntax
    • Create a database.

      create_database_stmt = "CREATE DATABASE" db_name

      [ WITH

      [ retention_policy_duration ]

      [ retention_policy_replication ]

      [ retention_policy_shard_group_duration ]

      [ retention_policy_name ]

      ] .

      The commands in square brackets ([]) are optional.

      Example:

      • Creating database mydb

        CREATE DATABASE "mydb"

      • Creating database mydb, configuring retention policy myrp to retain data for 1 day, keeping 1 a copy, and setting the storage duration for shardGroup to 30 minutes

        CREATE DATABASE "mydb" WITH DURATION 1d REPLICATION 1 SHARD DURATION 30m NAME "myrp"

      • Creating database mydb and using the default retention policy, myrp

        CREATE DATABASE "mydb" WITH NAME "myrp"

    • Query databases.

      SHOW DATABASES

    • Switch to another database.

      USE db_name

    • Delete a database.

      DROP DATABASE "db_name"

  • RETENTION POLICY
    • Create a retention policy and ensure that the policy name does not contain periods (,), colons (:), semicolons (;), or dots (.).

      create_retention_policy_stmt = "CREATE RETENTION POLICY" policy_name on_clause

      retention_policy_duration

      retention_policy_replication

      [ retention_policy_shard_group_duration ]

      [ "DEFAULT" ] .

      The commands in square brackets ([]) are optional.

      Example:

      • Creating a data retention policy

        CREATE RETENTION POLICY "10m_events" ON "somedb" DURATION 60m REPLICATION 2

      • Creating a data retention policy and setting it as the default retention policy

        CREATE RETENTION POLICY "10m_events" ON "somedb" DURATION 60m REPLICATION 2 DEFAULT

      • Creating a data retention policy and specifying the storage duration for shardGroup

        CREATE RETENTION POLICY "10m_events" ON "somedb" DURATION 60m REPLICATION 2 SHARD DURATION 30m

    • View a retention policy.

      show retention policies on <database name>

      If you specify both parameters retention_policy_duration and retention_policy_shard_group_duration, ensure that the former parameter has a greater value than the latter.

    • Delete a retention policy.

      DROP RETENTION POLICY policy_name ON db_name

    • Modify a retention policy.

      Alter_retention_policy_stmt = "ALTER RETENTION POLICY" policy_name on_clause

      retention_policy_option

      [ retention_policy_option ]

      [ retention_policy_option ]

      [ retention_policy_option ] .

      The commands in square brackets ([]) are optional.

      Example:

      • Modifying the default retention policy

        ALTER RETENTION POLICY "1h_cpu" ON "mydb" DEFAULT

      • Modifying the retention period and number of copies

        ALTER RETENTION POLICY "policy1" ON "somedb" DURATION 1h REPLICATION 4

  • Adding data

    insert into <retention policy> measurement,tagKey=tagValue fieldKey=fieldValue timestamp

    When a data record is inserted, the system will automatically create measurements as required.

    • Use the default retention policy.

      insert demo,name=LiSi math=99,english=90,language=95

      Add a data record, where measurement is demo, tag is name, and there are three fields math, english, and language.

    • Use a specific retention policy.

      insert into rp_1_hours demo,name=ZhangSan math=99,english=90,language=95

  • Querying data
    • Query data from the default retention policy.

      select * from demo where time < xxx and time > xxx

    • Query data from a specific retention policy.

      select * from rp_1_hours.demo where time < xxx and time > xxx

      Remember to specify a time range in the query statement.

  • Modifying data

    When you modify data using INSERT, if all tags and timestamps are the same, the existing data will be overwritten.

  • Deleting data

    Set a proper RETENTION POLICY as required to automatically delete data.

  • HELP command
    • Run the HELP command to view all supported commands.
      Figure 15 Viewing all supported commands
    • HELP <COMMAND> is used to query the usage of a command.

      Example: HELP DESC