Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Distributed Cache Service/ Best Practices/ Network Connection/ Using Nginx for Public Access to DCS

Using Nginx for Public Access to DCS

Updated on 2024-12-31 GMT+08:00

Overview

Currently, Huawei Cloud DCS Redis 4.0 and later cannot be bound with elastic IP addresses (EIPs) and cannot be accessed over public networks directly.

This section describes how to access a single-node, master/standby, read/write splitting, or Proxy Cluster DCS Redis 4.0, 5.0, or 6.0 instance by using a jump server. This solution cannot be used to access a Redis Cluster instance over public networks.

As shown in Figure 1, the ECS where Nginx is installed is a jump server. The ECS is in the same VPC as the DCS Redis instances and can access the DCS Redis instances through the subnet IP addresses. After an EIP is bound to the ECS, the ECS can be accessed over the public network. Nginx can listen on multiple ports and forward requests to different DCS Redis instances.

Figure 1 Accessing DCS Redis instances in a VPC by using Nginx
NOTE:

Do not use public network access in the production environment. Client access exceptions caused by poor public network performance will not be included in the SLA.

Buying an ECS

  1. Obtain the VPC where the DCS Redis instance is deployed.

    As shown in the following figure, the master/standby instance is deployed in the vpc-demo VPC.
    Figure 2 DCS Redis instance details

  2. Buy an ECS. Configure the ECS with the vpc-demo VPC, bind an EIP to the ECS, and select the bandwidth as required.

    Figure 3 ECS details

Installing Nginx

After buying an ECS, install Nginx on the ECS. The following uses CentOS 7.x as an example to describe how to install Nginx. The commands vary depending on the OS.

  1. Run the following command to add Nginx to the Yum repository:

    sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

  2. Run the following command to check whether Nginx has been added successfully:

    yum search nginx

  3. Run the following command to install Nginx:

    sudo yum install -y nginx

  4. Run the following command to install the stream module:

    yum install nginx-mod-stream --skip-broken

  5. Run the following commands to start Nginx and set it to run automatically upon system startup:

    sudo systemctl start nginx.service
    sudo systemctl enable nginx.service

  6. In the address box of a browser, enter the server address (the EIP of the ECS) to check whether Nginx is installed successfully.

    If the following page is displayed, Nginx has been installed successfully.

Setting Up Nginx

After installing Nginx, configure request forwarding rules to specify the ports that Nginx listens on and the DCS Redis instances that Nginx forwards requests to.

  1. Open and modify the configuration file.

    cd /etc/nginx
    vi nginx.conf

    The following is a configuration example. To access multiple DCS Redis instances over public networks, configure multiple server sections and configure the DCS Redis instance connection addresses for proxy_pass.

    stream {
        server {
            listen 8080;
            proxy_pass 192.168.0.5:6379;
        }
        server {
            listen 8081;
            proxy_pass 192.168.0.6:6379;
        }
    }
    NOTE:

    Set proxy_pass to the IP address of the DCS Redis instance in the same VPC. You can obtain the IP address from the Connection area on the DCS instance details page.

    Figure 4 Adding Nginx configurations

  2. Restart Nginx.

    service nginx restart

  3. Verify whether Nginx has been started.

    netstat -an|grep 808
    Figure 5 Starting Nginx and verifying the start

    If Nginx is listening on ports 8080 and 8081, Nginx has been started successfully.

(Optional) Persistent Connections

If persistent connections ("pconnect" in Redis terminology) are required for public network access, add the following configuration in Configuring Nginx:
  • Timeout of a connection from Nginx to the server
    stream {
        server {
            listen 8080;
            proxy_pass 192.168.0.5:6379;
            proxy_socket_keepalive on;
            proxy_timeout 60m;
            proxy_connect_timeout 60s;
        }
        server {
            listen 8081;
            proxy_pass 192.168.0.6:6379;
            proxy_socket_keepalive on;
            proxy_timeout 60m;
            proxy_connect_timeout 60s;
        }
    }

    The default value of proxy_timeout is 10m (10 minutes). You can set it to 60m or other values as required. For details about this parameter, see the Nginx official website.

  • Timeout of a connection from the client to Nginx
    http {
        keepalive_timeout 3600s;
    }

    The default value of keepalive_timeout is 75s. You can set it to 3600s or other values as required. For details about this parameter, see the Nginx official website.

Accessing DCS Redis Instances Using Nginx

  1. Log in to the ECS console and check the security group rules of the ECS that serves as the jump server. Ensure that access over ports 8080 and 8081 is allowed.

    1. Click the ECS name to go to the details page.
    2. On the Security Groups tab page, click Modify Security Group Rule. The security group configuration page is displayed.
    Figure 6 Checking the ECS security group
    Figure 7 Adding an inbound rule for the security group

  2. In the public network environment, open the redis-cli and run the following command to check whether the login and query are successful.

    NOTE:

    Ensure that redis-cli has been installed in the public network environment by referring to redis-cli.

    ./redis-cli -h {myeip} -p {port} -a {mypassword}

    In the preceding command, {myeip} indicates the host connection address, which should be replaced with the EIP of the ECS. Replace {port} with the listening port of Nginx.

    As shown in the following figures, the two listening ports are 8080 and 8081, which correspond to two DCS Redis instances.

    Figure 8 Accessing the first DCS Redis instance using Nginx
    Figure 9 Accessing the second DCS Redis instance using Nginx

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback