编程知识 cdmana.com

[azure redis cache] Linux VM uses port 6380 (SSL mode) to connect to azure redis (redis cli & stunnel)

Problem description

stay Azure Redis In the official documents of , This paper introduces the in Windows Next , How to use redis-cli.exe Connect Redis, Contains how to configure stunnel Made by 6380,SSL Way to connect to Redis Cache. The quotation is as follows :

by redis-cli.exe Enable access

Use Azure Cache for Redis when , Only... Is enabled by default TLS port (6380). redis-cli.exe  Command line tools do not support TLS.  The command line tool can be used in two configuration ways :

  1. Enable non TLS port (6379) - This configuration is not recommended , Because in this configuration , The system goes through TCP Send the access key in clear text .  This change may affect access to the cache .  Consider this configuration only when accessing the test cache .

  2. Download and install  stunnel.

    function stunnel GUI Start To start the server .

    Right click stunnel The server's taskbar icon , And then click “ Show log window ” .

    stay stunnel“ Log window ” Menu , single click “ To configure ” > “ Edit the configuration ”, Open the current profile .

    stay “ Service definition ” Part of it goes down redis-cli.exe Add the following .  take  yourcachename  Replace with the actual cache name .

    [redis-cli]
    client = yes
    accept = 127.0.0.1:6380
    connect = yourcachename.redis.cache.chinacloudapi.cn:6380

    Save and close the profile .

    stay stunnel“ Log window ” The menu , single click “ To configure ” > “ Reload configuration ” .

 

This paper is faced with the following situation : Use Linux VM How to connect to Azure Redis, adopt SSL The way (6380) Or not SSL The way (6379)

 

Preparation conditions

  • Azure Redis
  • Linux VM
  • redis-cli
  • stunnel4

 

Operation steps

First step : install Redis-cli

sudo apt-get update

sudo apt-get install redis-tools

notes :redis-tools It contains redis-cli Tools and others reids Tools

 

The second step : install stunnel4

because redis-cli.exe  The tool does not support TLS( adopt 6380 Port connection ), So use stunnel To connect to Redis Of 6380 port . The current use is the second 4 Version of stunnel, stay Linux The installation commands in are as follows :

sudo apt-get install stunnel4

Be careful :

If you want to use non SSL port 6379 function Redis, under these circumstances , You do not need to use stunnel, And you can Azure Redis Turn on non SSL Port, directly use the following command to access :

redis-cli -p 6379 -a <access key> -h <yourcachename.redis.cache.chinacloudapi.cn>

 

The third step : Turn on Stunnel service , stay VM Start automatically at startup

modify /etc/default/stunnel4 The configuration file , Modify the file ENABLED The value of is 1. Use nano Edit the file , The order is :

sudo nano /etc/default/stunnel4

Move to the arrow below through the keyboard direction key , modify ENABLED by 1 after , Use CRTL + X after , Input Y, To save the current changes . Then go back to Linux Command window .


Step four : stay stunnel Add redis-cli Configuration item for

stay Stunnel Add redis Configuration file for , Use the following command to add a file and configure Redis-cli Link information for

sudo nano /etc/stunnel/redis.conf

After opening the file , Enter the configuration content :

[redis-cli]
client = yes
accept = 127.0.0.1:6380
connect = yourredisname.redis.cache.chinacloudapi.cn:6380

Use CTRL + X, Input Y, Return to save

 

Step five : restart Stunnel service , load Redis To configure , The use command is

sudo systemctl restart stunnel4.service


Step six : Check stunnel Have you monitored 6380 port , Use command

sudo netstat -plunt

 

Step seven : Use Redis-cli adopt 6380(SSL The way ) Connect to Redis, Connection command

redis-cli -p 6380 -a <your redis access key>  

here , You can see that the connection is successful and start managing Redis.

 

[ above , I hope it will be of some help to you .]

 

Reference material :

Use Redis Command line tools to connect : https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-how-to-redis-cli-tool#enable-access-for-redis-cliexe
Connect to Azure Cache for Redis using SSL Port 6380 from Linux VM: https://techcommunity.microsoft.com/t5/azure-paas-blog/connect-to-azure-cache-for-redis-using-ssl-port-6380-from-linux/ba-p/1186109

 

版权声明
本文为[Two lights on the side of the road]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201225122311480Z.html

Scroll to Top