Help Center> Distributed Cache Service> Best Practices> Using ELB for Public Access to DCS Across VPCs

Using ELB for Public Access to DCS Across VPCs

Currently, DCS Redis 4.0 or 5.0 instances cannot be bound with elastic IP addresses (EIPs) and cannot be accessed over public networks directly. This section describes how to use Elastic Load Balancing (ELB) to access a single-node, master/standby, or Proxy Cluster instance or a node in a Redis Cluster instance from the public network across VPCs.

Due to cluster node address translation, you cannot access a Redis Cluster as whole. You can only access individual nodes in the cluster.

The following figure shows the process for accessing DCS through ELB.

Figure 1 Process for accessing DCS through ELB

Configurations

  1. Buy a DCS Redis instance. Record the IP address and port number of the instance.
  2. Create a dedicated load balancer.

    • Public network access is supported by dedicated load balancers and not by shared load balancers.
    • For Specification, select Network load balancing (TCP/UDP).
    • If your DCS Redis instance is not in the same VPC as the load balancer, enable Cross-VPC Backend for the load balancer.

  3. Add a TCP listener to the dedicated load balancer.

    1. When adding a backend server, click the Cross-VPC Backend Servers tab and then click Add Cross-VPC Backend Server.
    2. In the Add Cross-VPC Backend Server dialog box, enter the IP address and port number of your DCS instance.

  4. Perform a health check on the IP address of the DCS instance by referring to Configuring a Health Check for a Dedicated Load Balancer. If the health check result is Healthy, the added cross-VPC backend IP address can be used.

  5. Create a VPC or use an existing one.
  6. Create a VPC peering connection. For the local VPC, select the VPC whose CIDR block contains the private IPv4 address of your load balancer. For the peer VPC, select the VPC whose CIDR block contains the IP address of your DCS instance.

    If your load balancer and DCS instance are in the same VPC, skip 6 to 9.

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

  8. Click Route Tables.

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

    1. Click Add Route. In the displayed Add Route dialog box, set Destination to the value of Peer VPC CIDR Block mentioned in 6, set Next Hop Type to VPC peering connection, retain the default setting for Next Hop, and click OK.
    2. Click Add Route. In the displayed Add Route dialog box, set Destination to the value of Local VPC CIDR Block mentioned in 6, set Next Hop Type to VPC peering connection, retain the default setting for Next Hop, and click OK.

Connecting to the DCS Instance Through ELB

  • Connecting to a node in a Redis Cluster DCS instance through ELB
    1. A Redis Cluster contains multiple master/replica pairs. In 3, you can add the IP address and port number of any master or replica node for the cross-VPC backend server.

    2. View the basic information of the load balancer created in 2.

    3. Buy an ECS, log in to it, and install the Redis client by referring to redis-cli.
    4. On the Redis client, connect to the DCS instance using the IP address and port number configured in 3. If you use the EIP and port number of the load balancer, an error will be reported.

  • Connecting to a single-node, master/standby, or Proxy Cluster DCS instance through ELB
    1. View the IPv4 EIP and port number of the load balancer created in 2.

    2. Buy an ECS, log in to it, and install the Redis client by referring to redis-cli.
    3. Use redis-cli to access the load balancer using its EIP and port number (which is 80).

    4. Write a key through ELB.

    5. Log in to the DCS console. On the Cache Manager page, choose More > Connect to Redis in the row that contains the DCS instance created in 1. Check whether the key written in 4 exists.