%3CLINGO-SUB%20id%3D%22lingo-sub-1186109%22%20slang%3D%22en-US%22%3EConnect%20to%20Azure%20Cache%20for%20Redis%20using%20SSL%20Port%206380%20from%20Linux%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1186109%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3EScenario%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EYou%20are%20using%20a%20Linux%20VM%20and%20you%20want%20to%20connect%20to%20Azure%20Cache%20for%20Redis%20using%20SSL%20Port%206380.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EAction%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EYou%20can%20connect%20to%20Azure%20Cache%20for%20Redis%20using%20SSL%20Port%20with%20the%20help%20of%20Stunnel%20and%20Redis-cli.%3C%2FP%3E%0A%3CP%3EThe%20steps%20are%20as%20follows%3A%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%201%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EInstall%20the%20Redis-cli%20tool%20in%20your%20Linux%20machine.%20The%20command%20is%20as%20below%3A%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Esudo%20apt-get%20update%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Esudo%20apt-get%20install%20redis-tools%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ENote%3A%20redis-tools%20package%20has%20redis-cli%20tool%20as%20well%20among%20other%20tools.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%202%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ESince%20the%20redis-cli%20doesn%E2%80%99t%20support%20SSL%20port%20(6380)%2C%20we%20can%20make%20use%20of%20stunnel%20to%20connect%20to%20Azure%20Cache%20for%20Redis%20using%20SSL%20port.%20We%20have%20version%204%20of%20the%20utility%2C%20called%20stunnel4%20which%20can%20be%20installed%20using%20the%20below%20command%3A%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Esudo%20apt-get%20install%20stunnel4%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENote%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIf%20you%20want%20to%20run%20the%20Redis%20using%20non%20SSL%20port%206379%2C%20in%20that%20case%20you%20do%20not%20need%20stunnel%20and%20you%20can%20directly%20access%20using%20the%20below%20command%20provided%20non-ssl%20port%20is%20open%20in%20Azure%20Cache%20for%20Redis%3A%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Eredis-cli%20-p%206379%20-a%20%3CYOUR%20access%3D%22%22%20key%3D%22%22%20for%3D%22%22%20azure%3D%22%22%20cache%3D%22%22%20for%3D%22%22%20redis%3D%22%22%3E%20-h%20%26lt%3B%20yourcachename.redis.cache.windows.net%26gt%3B%3C%2FYOUR%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%203%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ETo%20configure%20the%20service%20to%20start%20at%20booting%2C%20you%20must%20modify%20the%20%2Fetc%2Fdefault%2Fstunnel4%20file%20using%20the%20below%20command%3A%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Esudo%20nano%20%2Fetc%2Fdefault%2Fstunnel4%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThis%20opens%20a%20file%20where%20you%20have%20a%20variable%20%E2%80%98ENABLED%E2%80%99%20which%20must%20be%20set%20to%201%20to%20enable%20the%20service%20to%20start%20as%20shown%20below%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Sindhu_Hegde_0-1582263729720.png%22%20style%3D%22width%3A%20426px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F172410iFC420BE339756C81%2Fimage-dimensions%2F426x228%3Fv%3D1.0%22%20width%3D%22426%22%20height%3D%22228%22%20title%3D%22Sindhu_Hegde_0-1582263729720.png%22%20alt%3D%22Sindhu_Hegde_0-1582263729720.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EYou%20can%20save%20the%20changes%20with%20CTL%2BX%20and%20then%20pressing%20ENTER.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%204%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EWe%20need%20to%20configure%20the%20Azure%20Cache%20for%20Redis%20for%20redis-cli%20which%20must%20be%20mentioned%20in%20Redis%20configuration%20file%20of%20stunnel.%3C%2FP%3E%0A%3CP%3EExecute%20the%20below%20command%3A%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Esudo%20nano%20%2Fetc%2Fstunnel%2Fredis.conf%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThis%20creates%20a%20new%20file%20where%20add%20the%20following%20entry%20and%20insert%20the%20actual%20name%20of%20your%20Azure%20Cache%20for%20Redis%20in%20place%20of%20yourcachename.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%5Bredis-cli%5D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Eclient%20%3D%20yes%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Eaccept%20%3D%20127.0.0.1%3A6380%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Econnect%20%3D%20yourcachename.redis.cache.windows.net%3A6380%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Sindhu_Hegde_1-1582263729735.png%22%20style%3D%22width%3A%20539px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F172408i57D18FF6217E36DF%2Fimage-dimensions%2F539x129%3Fv%3D1.0%22%20width%3D%22539%22%20height%3D%22129%22%20title%3D%22Sindhu_Hegde_1-1582263729735.png%22%20alt%3D%22Sindhu_Hegde_1-1582263729735.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ESave%20the%20file.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%205%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ENow%2C%20we%20have%20configured%20the%20stunnel%20and%20hence%20need%20to%20restart%20the%20service%20which%20can%20be%20done%20with%20the%20help%20of%20below%20command%3A%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Esudo%20systemctl%20restart%20stunnel4.service%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%206%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIf%20you%20check%20the%20services%20listening%20for%20connections%20on%20your%20Redis%2C%20you%20should%20see%20stunnel%20listening%20on%20port%206380%20as%20below%3A%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Esudo%20netstat%20-plunt%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Sindhu_Hegde_2-1582263729762.png%22%20style%3D%22width%3A%20642px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F172409i3B32357A46C9427A%2Fimage-dimensions%2F642x107%3Fv%3D1.0%22%20width%3D%22642%22%20height%3D%22107%22%20title%3D%22Sindhu_Hegde_2-1582263729762.png%22%20alt%3D%22Sindhu_Hegde_2-1582263729762.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%207%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ENow%20you%20can%20connect%20to%20Azure%20Cache%20for%20Redis%20using%20SSL%20port%20with%20the%20help%20of%20Redis-cli.%20Below%20is%20the%20command%3A%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Eredis-cli%20-p%206380%20-a%20%3CYOUR%20access%3D%22%22%20key%3D%22%22%20for%3D%22%22%20azure%3D%22%22%20cache%3D%22%22%20for%3D%22%22%20redis%3D%22%22%3E%3C%2FYOUR%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EYou%20can%20see%20that%20Redis%20gets%20connected%20successfully%20and%20you%20will%20be%20able%20to%20perform%20operations%20on%20Azure%20Cache%20for%20Redis%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Sindhu_Hegde_3-1582263729773.png%22%20style%3D%22width%3A%20603px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F172411iFB3F1CCC943EA62A%2Fimage-dimensions%2F603x110%3Fv%3D1.0%22%20width%3D%22603%22%20height%3D%22110%22%20title%3D%22Sindhu_Hegde_3-1582263729773.png%22%20alt%3D%22Sindhu_Hegde_3-1582263729773.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHope%20this%20helps!%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1186109%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Redis%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EConnect%20to%20Azure%20Cache%20for%20Redis%20using%20SSL%20Port%206380%20from%20Linux%20VM%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Scenario:

You are using a Linux VM and you want to connect to Azure Cache for Redis using SSL Port 6380.

 

Action:

You can connect to Azure Cache for Redis using SSL Port with the help of Stunnel and Redis-cli.

The steps are as follows:

Step 1:

Install the Redis-cli tool in your Linux machine. The command is as below:

sudo apt-get update

sudo apt-get install redis-tools

Note: redis-tools package has redis-cli tool as well among other tools.

 

Step 2:

Since the redis-cli doesn’t support SSL port (6380), we can make use of stunnel to connect to Azure Cache for Redis using SSL port. We have version 4 of the utility, called stunnel4 which can be installed using the below command:

sudo apt-get install stunnel4

 

Note:

If you want to run the Redis using non SSL port 6379, in that case you do not need stunnel and you can directly access using the below command provided non-ssl port is open in Azure Cache for Redis:

redis-cli -p 6379 -a <Your Access Key for Azure Cache for Redis> -h < yourcachename.redis.cache.windows.net>

 

Step 3:

To configure the service to start at booting, you must modify the /etc/default/stunnel4 file using the below command:

sudo nano /etc/default/stunnel4

This opens a file where you have a variable ‘ENABLED’ which must be set to 1 to enable the service to start as shown below:

Sindhu_Hegde_0-1582263729720.png

You can save the changes with CTL+X and then pressing ENTER.

 

Step 4:

We need to configure the Azure Cache for Redis for redis-cli which must be mentioned in Redis configuration file of stunnel.

Execute the below command:

sudo nano /etc/stunnel/redis.conf

This creates a new file where add the following entry and insert the actual name of your Azure Cache for Redis in place of yourcachename.

[redis-cli]

client = yes

accept = 127.0.0.1:6380

connect = yourcachename.redis.cache.windows.net:6380

Sindhu_Hegde_1-1582263729735.png

Save the file.

 

Step 5:

Now, we have configured the stunnel and hence need to restart the service which can be done with the help of below command:

sudo systemctl restart stunnel4.service

 

Step 6:

If you check the services listening for connections on your Redis, you should see stunnel listening on port 6380 as below:

sudo netstat -plunt

Sindhu_Hegde_2-1582263729762.png

 

Step 7:

Now you can connect to Azure Cache for Redis using SSL port with the help of Redis-cli. Below is the command:

redis-cli -p 6380 -a <Your Access Key for Azure Cache for Redis>

You can see that Redis gets connected successfully and you will be able to perform operations on Azure Cache for Redis:

Sindhu_Hegde_3-1582263729773.png

 

Hope this helps!