Updated on 2024-10-30 GMT+08:00

Connecting to an Instance Using an EIP Bound to a Load Balancer (Recommended)

This section describes how to access a GeminiDB Redis instance over a public network by creating a load balancer and binding it to an EIP. To prevent single points of failure (SPOFs) in the production environment and implement load balancing, you are advised to connect to the GeminiDB Redis instance using an EIP bound to a load balancer.

To connect to a GeminiDB Redis instance over a public network, use a public domain name to ensure instance reliability. For details, see Connecting to an Instance Using a Public Domain Name.

Creating and Configuring a Dedicated Load Balancer

  1. Purchase a dedicated load balancer. For details, see Creating a Dedicated Load Balancer. Pay attention to the following:

    • When creating a flavor, you need to select the TCP/UDP network.
    • In the network configuration, Cross-VPC Backend must be enabled so that backend IP addresses can be added to the load balancer.
    • You need to use a new or existing EIP to support public network access.

  1. Add a listener. For details, see Adding a TCP Listener. Pay attention to the following:

    Figure 1 Adding a listener

    • When configuring a listener, select the TCP protocol to and the 6379 port, which is commonly used by Redis.
    • When adding a backend server, click the Cross-VPC Backend Servers tab and then click Add Cross-VPC Backend Server. Configure the load balancer address and port number of the GeminiDB Redis instance in the cross-VPC backend IP address.
    • Enable the health check.

  2. Create a VPC peering connection and select the local VPC and peer VPC.

    Local VPC: specifies the VPC to which the ELB belongs.

    • If the selected VPC and GeminiDB Redis are in the same VPC, set the peer VPC to a VPC where no ELB is located.
    • If the selected VPC and GeminiDB Redis are not in the same VPC, set the peer VPC to the VPC where the GeminiDB Redis instance resides.

    For details, see Creating a VPC Peering Connection to Connect Two VPCs in the Same Account.

  3. Click the name of the VPC peering connection to go to its details page.

    Figure 2 VPC peering connection

  4. Click Route Tables.

    Figure 3 Route table

  5. Configure local and peer routes for the VPC peering connection.

    1. Local route: Click Add Route. In the displayed Add Route dialog box, set Destination to the value of Peer VPC CIDR Block of the VPC peering connection, set Next Hop Type to VPC peering connection, set Next Hop to the VPC peering connection created in 3, and click OK.
    2. Peer route: Click Add Route. In the displayed Add Route dialog box, set Destination to the value of Local VPC CIDR Block of the VPC peering connection, set Next Hop Type to VPC peering connection, set Next Hop to the VPC peering connection created in 3, and click OK.

  6. Perform a health check on the load balancer address of GeminiDB Redis. Click the Listeners tab. If the health check result is Healthy, the address is available.

After you create a dedicated load balancer, you can access the GeminiDB Redis instance using the service address displayed in the Basic Information area.

Figure 4 Service address

Procedure

  1. Log in to the ECS. For details, see Logging In to an ECS in Getting Started with Elastic Cloud Server.
  2. Download the Redis client.

    Method 1

    Run the following command to download the Redis client.

    wget http://download.redis.io/releases/redis-6.2.0.tar.gz

    Method 2

    Download the Redis client and upload it to the ECS.

  3. Decompress the client package.

    tar -xzf redis-6.2.0.tar.gz

  4. Connect to the DB instance in the src directory.

    cd redis-6.2.0
    make
    cd src
    ./redis-cli -h <DB_HOST> -p <DB_PORT> -a <DB_PWD>

    Example:

    ./redis-cli -h 192.168.0.208 -p 8635 -a <DB_PWD>
    Table 1 Parameter description

    Parameter

    Description

    <DB_HOST>

    EIP bound to the instance to be connected.

    To obtain the EIP, go to the Instance Management page and click the target instance name. The EIP can be found in the EIP column in the Node Information area on the Basic Information page.

    If the instance you bought has multiple nodes, you can bind the EIP to any node to connect to the instance.

    If a message is displayed indicating that no EIP has been bound to the instance, bind an EIP to the instance by following Binding and Unbinding an EIP.

    <DB_PORT>

    Port for accessing the target instance. Configure this parameter based on service requirements.

    To obtain the port number, perform the following steps:

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

    <DB_PWD>

    Administrator password set when you buy a GeminiDB Redis instance

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

    IP:port>