Huawei Cloud Yaoyun Server L instance evaluation | Install Redis from source code for remote connection

Table of contents

1. Purchase a Yunyao Cloud Server L instance

1.1 Select Yunyao Cloud Server L instance configuration

2.2 Yunyao Cloud Server L instance

2. Download the redis installation package

3. Compile the source code

4. Run Redis

5. Set up auto-start at boot

6. Remote connection to Redis

6.1 Install redis client

6.2 Remote connection

7. Summary


I have recently used ⌈Yunyao Cloud Server L Instance⌋ and  found it to be very easy to use. ⌈Yunyao Cloud Server L Instance⌋ is  smart and non-stuck, has excellent price and is easy to use, is easier to get started, and is very worry-free to manage. This article mainly introduces how to use ⌈Yunyao Cloud Server L Instance⌋ , and install the Redis database through source code in ⌈Yunyao Cloud Server L Instance⌋ , set up auto-start at boot, and connect remotely. Let’s take a look.

1. Purchase a Yunyao Cloud Server L instance

1.1 Select Yunyao Cloud Server L instance configuration

Click the link below to enter the ⌈Yunyao Cloud Server L Instance⌋ purchase page .  

https://console.huaweicloud.com/smb/?region=cn-east-3&locale=zh-cn#/create/hecs-light?period=month_1&plan=basic_v1

The page looks like this.

Here, the default mode is selected for the region and application image. Of course, you can choose application image and system image according to your own needs.

As shown above, the instance specification is 2 cores | 2G. Of course, you can choose the appropriate configuration and different memory sizes according to your needs, including 2G, 4G, and 8G. You can also add data disk EVS and turn on the host. Secure HSS, enable cloud backup, etc.

  

As shown above , select the purchase duration, select the configuration, and click ⌈Buy Now⌋ .

As shown above, you need to check the agreement license, then click to pay to enter the following page.

As shown above, the specific order information is displayed, select the Huawei Cloud voucher, and click to pay online. After successful payment, you will enter the following interface.

2.2 Yunyao Cloud Server L instance

If the payment is successful, a ⌈Yunyao Cloud Server L instance⌋ will be created , as shown on the page.

As shown above, it shows that the creation of ⌈Yunyao Cloud Server L instance⌋ is completed. You can see that the running status is Running. You can click Remote Login to log in.  

Click on the right side of remote login... to display operations such as renewal, activation of automatic renewal, password reset, unsubscription, etc. Here, reset the password first, and then log in as shown below.

  You can also log in via CloudShell as shown below.

 After entering, you can operate in the terminal.

2. Download the redis installation package

First, you need to go to the Redis official website to download the Redis source code package, click to enter the official website , and click Download 7.0.10 to download, as shown in the red box in the figure below.

Or execute the following command to download directly, as shown below.

As you can see above, the download speed is very fast. After the download is complete, execute the following command to decompress the source code package.

root@hcss-ecs-f276:~# tar -zxvf 7.0.10.tar.gz

As shown below, decompression is complete. 

3. Compile the source code

Install the environment required for compilation.

root@hcss-ecs-f276:~# sudo apt install build-essential -y

Execute the above command to install and compile the software packages that C/C++ depends on, such as: gcc, g++, make, etc.

Execute the following command to compile the source code.

root@hcss-ecs-f276:~/redis-7.0.10# sudo make -j4

After executing the command, the following is displayed. 

 

To install redis, execute the following command.

root@hcss-ecs-f276:~/redis-7.0.10# sudo make PREFIX=/usr/local/redis install

After executing the command, the following is displayed. 

​ 

Install redis to the /usr/local/redis directory. 

4. Run Redis

Execute the following command to place redis-server and redis-cli in the system path (/usr/bin).

root@hcss-ecs-f276:~/redis-7.0.10# ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis-cli
root@hcss-ecs-f276:~/redis-7.0.10# ln -s /usr/local/redis/bin/redis-server /usr/bin/redis-server

The above command is to establish a soft connection, let /usr/bin/redis-cli point to /usr/local/redis/bin/redis-cli, let /usr/bin/redis-server point to /usr/local/redis/bin/redis -server.

Configure redis-server, copy the redis.conf configuration file in the source directory to the installation directory, and execute the following command.

root@hcss-ecs-f276:~# sudo cp redis-7.0.10/redis.conf /usr/local/redis/

 Modify the redis.conf file as follows.

#(1)修改 1
# 注释掉 bind 127.0.0.1 -::1 允许远程连接
#bind 127.0.0.1 -::1

# (2)修改2
# 将 daemonize no 修改为 daemonize yes,设置后台运行
daemonize yes

# (3)修改3
# 指定 log 文件路径
logfile "/var/log/redis-server.log"

# (4)修改4
# 设置登录密码
requirepass 123456

Start redis-server and execute the following command.

root@hcss-ecs-f276:~# sudo redis-server /usr/local/redis/redis.conf
root@hcss-ecs-f276:~# ps -ef | grep redis
root       24488       1  0 21:22 ?        00:00:00 redis-server *:6379
root       24495   19372  0 21:23 pts/1    00:00:00 grep --color=auto redis
root@hcss-ecs-f276:~#

To access through the client, execute the following command.

root@hcss-ecs-f276:~# redis-cli
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> 
root@hcss-ecs-f276:~#

Auth is followed by the login password set in the configuration file redis.conf. Enter ping. If PONG is returned, the connection to the Redis server is successful.

Close redis-server and execute the following command.

root@hcss-ecs-f276:~#  redis-cli
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> shutdown
not connected> 
root@hcss-ecs-f276:~# ps -ef | grep redis
root       26321   26241  0 22:05 pts/3    00:00:00 grep --color=auto redis
root@hcss-ecs-f276:~#

5. Set up auto-start at boot

Copy the startup script redis_init_script to the directory /etc/init.d/redis and execute the command as shown below.

root@hcss-ecs-f276:~# sudo cp redis-7.0.10/utils/redis_init_script /etc/init.d/redis

Modify the /etc/init.d/redis file as follows. 

REDISPORT=6379
#EXEC=/usr/local/bin/redis-server
# 修改 redis-server 路径,之前的配置已经放置到系统路径 /usr/bin 下。
EXEC=/usr/bin/redis-server
# 修改 redis-cli 路径,之前的配置已经放置到系统路径 /usr/bin 下。
#CLIEXEC=/usr/local/bin/redis-cli
CLIEXEC=/usr/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

In the above code, CONF represents the path of the configuration file to be read. You need to create the redis directory in the /etc directory, copy redis.conf to /etc/redis/ and rename it to 6379.conf. Execute the following command to configure.

root@hcss-ecs-f276:~# vim /etc/init.d/redis 
root@hcss-ecs-f276:~# sudo mkdir /etc/redis
root@hcss-ecs-f276:~# sudo cp /usr/local/redis/redis.conf /etc/redis/6379.conf
root@hcss-ecs-f276:~#

Add redis to enable auto-start and start the redis service. Execute the command as shown below.

root@hcss-ecs-f276:~# sudo update-rc.d -f redis defaults
root@hcss-ecs-f276:~# systemctl start redis
root@hcss-ecs-f276:~# systemctl status redis
● redis.service - LSB: Redis data structure server
     Loaded: loaded (/etc/init.d/redis; generated)
     Active: active (exited) since Wed 2023-09-13 21:28:29 CST; 14s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 24809 ExecStart=/etc/init.d/redis start (code=exited, status=0/SUCCESS)
        CPU: 1ms

Sep 13 21:28:29 hcss-ecs-f276 systemd[1]: Starting LSB: Redis data structure server...
Sep 13 21:28:29 hcss-ecs-f276 redis[24809]: /var/run/redis_6379.pid exists, process is already running or crashed
Sep 13 21:28:29 hcss-ecs-f276 systemd[1]: Started LSB: Redis data structure server.
root@hcss-ecs-f276:~#

6. Remote connection to Redis

6.1 Install redis client

Click to download the redis client and select the corresponding file to download.

6.2 Remote connection

After the installation is complete, click New Connection and fill in the configuration as shown below.

After clicking OK, the connection is successful, and the interface is as shown below.

7. Summary

By purchasing and using ⌈Yunyao Cloud Server L Instance⌋ , and compiling and installing Redis through source code in ⌈Yunyao Cloud Server L Instance⌋ , and finally connecting to Redis remotely, using ⌈Yunyao Cloud Server L Instance⌋ is very convenient and efficient. There is no lag during use, it is easier to get started, and management is worry-free. If you need it, come and try it out.

Guess you like

Origin blog.csdn.net/nyist_zxp/article/details/132864483