Updated on 2024-01-08 GMT+08:00

Deploying Redis

Introduction

Remote Dictionary Server (Redis) is an open-source, in-memory, distributed, and durable key-value pair storage database written in C. Redis is a storage system with rich functions and applies to various scenarios, including caching, session storage, rankings, and real-time analysis. It is widely used and has active community support. This tutorial describes how you can deploy Redis in Huawei Cloud EulerOS 2.0.

Preparations

  • Prepare two ECSs and assign a public IP address or EIP to each ECS. One ECS functions as the master Redis node, and the other serves as the slave Redis node.
  • Ensure that inbound security group rules allow traffic to flow to the ECSs over port 6379.

Procedure

  1. Install and configure Redis.

    1. Run the following command on the two ECSs to install Redis:
      dnf install redis -y
    2. Run the following command on the two ECSs to start Redis:
      systemctl start redis

      To set Redis to automatically enable upon system boot, run the following command:

      systemctl enable redis
    3. Run the following command to check the Redis status:
      systemctl status redis

      If active (running) is displayed, Redis is started.

    4. On the master node, edit the /etc/redis.conf file and configure the following attributes:
      bind 0.0.0.0        # Replace the value with the IP address of the master node. In this example, enter any IP address.
      requirepass ******* # Set a password.
    5. On the slave node, edit the /etc/redis.conf file and configure the following attributes:
      bind 0.0.0.0                        # Replace the value with the IP address of the slave node. In this example, enter any IP address.
      requirepass *******                 # Set a password.
      slaveof <IP address of the master node> <Port of the master node>
      masterauth <Password of the master node>
    6. Run the following command on the two ECSs to restart Redis:
      systemctl restart redis

  2. Verify Redis.

    1. Run the following command on the master node to connect to Redis:
      redis-cli
      auth <Password>
    2. Run the following command to view the node information:
      127.0.0.1:6379> info replication
      # Replication
      role:master
      connected_slaves:1
      slave0:ip=x.x.x.x,port=6379,state=online,offset=4382,lag=0
      master_replid:5d68ccf7722f461cc5f004c7e96fd7c506990508
      master_replid2:0000000000000000000000000000000000000000
      master_repl_offset:4382
      second_repl_offset:-1
      repl_backlog_active:1
      repl_backlog_size:1048576
      repl_backlog_first_byte_offset:1
      repl_backlog_histlen:4382
      127.0.0.1:6379> 

The preceding configuration and Redis deployment architecture are used only for tests. Exercise caution when using them in the service environment.