Deploy your Bitnami Redis Stack on Microsoft Azure now! Launch Now

Bitnami Redis for Microsoft Azure

Description

Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

First steps with the Bitnami Redis Stack

Welcome to your new Bitnami application running on Microsoft Azure! Here are a few questions (and answers!) you might need when first starting with your application.

What credentials do I need?

You need two sets of credentials:

  • The application credentials that allow you to log in to your new Bitnami application. These credentials consist of a username and password.
  • The server credentials that allow you to log in to your Microsoft Azure server using an SSH client and execute commands on the server using the command line. These credentials consist of an SSH username and key.

What is the administrator username set for me to log in to the application for the first time?

Username: user

What SSH username should I use for secure shell access to my application?

SSH username: bitnami

How to start or stop the services?

Each Bitnami stack includes a control script that lets you easily stop, start and restart services. The script is located at /opt/bitnami/ctlscript.sh. Call it without any service name arguments to start all services:

$ sudo /opt/bitnami/ctlscript.sh start

Or use it to restart a single service, such as Apache only, by passing the service name as argument:

$ sudo /opt/bitnami/ctlscript.sh restart apache

Use this script to stop all services:

$ sudo /opt/bitnami/ctlscript.sh stop

Restart the services by running the script without any arguments:

$ sudo /opt/bitnami/ctlscript.sh restart

Obtain a list of available services and operations by running the script without any arguments:

$ sudo /opt/bitnami/ctlscript.sh

What is the default configuration?

By default, the Redis server is configured to run on the default port 6379. You can connect to the server locally or remotely using the redis-cli command line tool Replace the YOURPASSWORD placeholder with the value of your password.

$ redis-cli -h SERVER-IP -a YOURPASSWORD

The Redis server is configured following the security guidelines from the official Redis documentation. Although you use a password to connect to the server, it is strongly recommended to change your firewall policies to only accept connections from the IP address that you are using to connect to the Redis server.

Redis version

In order to check which Redis version your machine is running, execute the following command from the console:

$ redis-server -v

Redis configuration file

The Redis configuration file is located at /opt/bitnami/redis/etc/redis.conf.

Redis port

The default port on which Redis listens is 6379.

Redis log file

The Redis log file is created at /opt/bitnami/redis/var/log/redis-server.log.

What are the default ports?

A port is an endpoint of communication in an operating system that identifies a specific process or a type of service. Bitnami stacks include several services or servers that require a port.

Remember that if you need to open some ports you can follow the instructions given in the FAQ to learn how to open the server ports for remote access.

Port 22 is the default port for SSH connections.

The Redis access port is 6379. This port is closed by default, you must open it to enable remote access.

How to upload files to the server with SFTP?

NOTE: Bitnami applications can be found in /opt/bitnami/apps.

First, obtain your SSH credentials by following these steps:

  • Browse to the Bitnami Launchpad for Microsoft Azure and sign in if required using your Bitnami account.
  • Select the "Virtual Machines" menu item.
  • Select your cloud server from the resulting list.
  • Note the server IP address and SSH credentials on the resulting page. Your server may have been deployed using either an SSH password or an SSH key.

    SSH credentials with password

    SSH credentials with key

Although you can use any SFTP/SCP client to transfer files to your server, this guide documents FileZilla (Windows, Linux and Mac OS X), WinSCP (Windows) and Cyberduck (Mac OS X).

Using an SSH Key

Once you have your server's SSH key, choose your preferred application and follow the steps below to connect to the server using SFTP.

FileZilla
IMPORTANT: To use FileZilla, your server private key should be in PPK format.

Follow these steps:

  • Download and install FileZilla.
  • Launch FileZilla and use the "Edit -> Settings" command to bring up FileZilla's configuration settings.
  • Within the "Connection -> SFTP" section, use the "Add keyfile" command to select the private key file for the server. FileZilla will use this private key to log in to the server.

    FileZilla configuration

  • Use the "File -> Site Manager -> New Site" command to bring up the FileZilla Site Manager, where you can set up a connection to your server.
  • Enter your server host name and specify bitnami as the user name.
  • Select "SFTP" as the protocol and "Ask for password" as the logon type.

    FileZilla configuration

  • Use the "Connect" button to connect to the server and begin an SFTP session. You might need to accept the server key, by clicking "Yes" or "OK" to proceed.

You should now be logged into the /home/bitnami directory on the server. You can now transfer files by dragging and dropping them from the local server window to the remote server window.

If you have problems accessing your server, get extra information by use the "Edit -> Settings -> Debug" menu to activate FileZilla's debug log.

FileZilla debug log

WinSCP
IMPORTANT: To use WinSCP, your server private key should be in PPK format.

Follow these steps:

  • Download and install WinSCP.
  • Launch WinSCP and in the "Session" panel, select "SCP" as the file protocol.
  • Enter your server host name and specify bitnami as the user name.

    WinSCP configuration

  • Click the "Advanced…" button and within the "SSH -> Authentication -> Authentication parameters" section, select the private key file for the server. WinSCP will use this private key to log in to the server.

    WinSCP configuration

  • From the "Session" panel, use the "Login" button to connect to the server and begin an SCP session.

You should now be logged into the /home/bitnami directory on the server. You can now transfer files by dragging and dropping them from the local server window to the remote server window.

If you need to upload files to a location where the bitnami user doesn't have write permissions, you have two options:

  • Once you have configured WinSCP as described above, click the "Advanced…" button and within the "Environment -> Shell" panel, select sudo su - as your shell. This will allow you to upload files using the administrator account.

    WinSCP configuration

  • Upload the files to the /home/bitnami directory as usual. Then, connect via SSH and move the files to the desired location with the sudo command, as shown below:

     $ sudo mv /home/bitnami/uploaded-file /path/to/desired/location/
    
Cyberduck
IMPORTANT: To use Cyberduck, your server private key should be in PEM format.

Follow these steps:

  • Select the "Open Connection" command and specify "SFTP" as the connection protocol.

    Cyberduck configuration

  • In the connection details panel, under the "More Options" section, enable the "Use Public Key Authentication" option and specify the path to the private key file for the server.

    Cyberduck configuration

  • Use the "Connect" button to connect to the server and begin an SFTP session.

You should now be logged into the /home/bitnami directory on the server. You can now transfer files by dragging and dropping them from the local server window to the remote server window.

Using a Password

Once you have your server's SSH credentials, choose your preferred application and follow the steps below to connect to the server using SFTP.

FileZilla

Follow these steps:

  • Download and install FileZilla.
  • Launch FileZilla and use the "File -> Site Manager -> New Site" command to bring up the FileZilla Site Manager, where you can set up a connection to your server.
  • Enter your server host name.
  • Select "SFTP" as the protocol and "Ask for password" as the logon type. Use bitnami as the server username and the password generated during the server deployment process.

    FileZilla configuration

  • Use the "Connect" button to connect to the server and begin an SFTP session. You might need to accept the server key, by clicking "Yes" or "OK" to proceed.

You should now be logged into the /home/bitnami directory on the server. You can now transfer files by dragging and dropping them from the local server window to the remote server window.

If you have problems accessing your server, get extra information by use the "Edit -> Settings -> Debug" menu to activate FileZilla's debug log.

FileZilla debug log

WinSCP

Follow these steps:

  • Download and install WinSCP.
  • Launch WinSCP and in the "Session" panel, select "SCP" as the file protocol.
  • Enter your server host name and set bitnami as the server username. Enter the corresponding password as well.

    WinSCP configuration

  • From the "Session" panel, use the "Login" button to connect to the server and begin an SCP session.

You should now be logged into the /home/bitnami directory on the server. You can now transfer files by dragging and dropping them from the local server window to the remote server window.

Cyberduck

Follow these steps:

  • Select the "Open Connection" command and specify "SFTP" as the connection protocol.

    Cyberduck configuration

  • In the connection details panel, enter the server IP address, bitnami as the username, and the password generated during the deployment process.

    Cyberduck configuration

  • Use the "Connect" button to connect to the server and begin an SFTP session.

You should now be logged into the /home/bitnami directory on the server. You can now transfer files by dragging and dropping them from the local server window to the remote server window.

How to create a Virtual Network peering?

To connect two instances internally you can enable a Virtual Network (VNet) peering from the Azure Portal. Depending if the instances were launched in the same or in different resource groups, there are two methods for performing a internal connection: sharing a virtual network or enabling a virtual network peering.

Security information

In order to improve the security of this component, we have renamed the commands CONFIG, FLUSHDB and FLUSHALL to empty strings. This is done to avoid potentially harmful actions with those commands. To modify this behavior, edit the Redis configuration file redis.conf.

You can find more information and recommendations about Redis security on the official website.

How to connect to the Redis server?

Connect to Redis from the same computer where it is installed with the redis-cli client tool. Replace the YOURPASSWORD placeholder with the value of your password:

$ redis-cli -a YOURPASSWORD
127.0.0.1:6379>

Once connected, use the Redis get and set commands to save and retrieve keys and their values. Here's an example:

127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"

How to connect to Redis from a different machine?

IMPORTANT: Making this application's network ports public is a significant security risk. You are strongly advised to only allow access to those ports from trusted networks. If, for development purposes, you need to access from outside of a trusted network, please do not allow access to those ports via a public IP address. Instead, use a secure channel such as a VPN or an SSH tunnel. Follow these instructions to remotely connect safely and reliably.

To connect to Redis from a different machine, you must open port 6379 for remote access. Refer to the FAQ for more information on this.

You can now connect to Redis using a command like the one below. Replace the YOURPASSWORD placeholder with the value of your password:

$ redis-cli -h SERVER-IP -a YOURPASSWORD

How to change the Redis password?

You can modify the Redis password by editing the requirepass directive in the /opt/bitnami/redis/etc/redis.conf file. Replace the NEWPASSWORD placeholder with the value of your new password:

requirepass NEWPASSWORD

Then restart the Redis server:

$ sudo /opt/bitnami/ctlscript.sh restart redis
  • (Optional) If you don't want to restart the Redis service, appart from changing the configuration file, you can execute the following command to change the password at runtime. Replace the CURRENTPASSWORD and NEWPASSWORD placeholders with the values of the current password and your new password:

    $ redis-cli -a CURRENTPASSWORD CONFIG set requirepass NEWPASSWORD

How to change Redis persistence mode?

You can change the modes to adapt Redis persistence to your needs. There are multiple possibilities to do so. Find below how to enable AOF as an example:

  • Edit the configuration file /opt/bitnami/redis/etc/redis.conf. Change the appendonly configuration directive from no to yes:

      appendonly yes
    
  • Edit the Redis configuration file /opt/bitnami/redis/etc/redis.conf. Change the appendonly configuration directive from no to yes as shown below:

      appendonly yes
    

    This change will apply when you restart the server.

  • (Optional) To apply the change inmediately, execute the following command. Replace the YOURPASSWORD placeholder with the value of your password:

      $ redis-cli -a YOURPASSWORD CONFIG set appendonly yes
    

For more information on this, please check the Redis official documentation about Redis Persistence.

How to create a Redis cluster?

From Redis 3.x, it is possible to create a cluster of Redis nodes in master-slave mode. The minimum configuration required is a 6-node cluster with 3 masters and 3 slaves. This section will introduce you to creating a simple redis cluster. For further information, please refer to http://redis.io/topics/cluster-tutorial and http://redis.io/topics/cluster-spec.

Pre-requisites

Ruby must be installed with the Redis gem. Install these components with the commands below:

  • Debian:

    $ sudo apt-get install ruby
    $ sudo gem install redis
    
  • CentOS:

    $ sudo yum install ruby
    $ sudo yum install redis
    

Manual approach

Use the following template and place it in your desired location.

  • Create the following folder structure:

      $ mkdir -p my-cluster
      $ cd my-cluster
      $ mkdir PORT-1 PORT-2 PORT-3 PORT-4 PORT-5 PORT-6
    
  • In every PORT-* folder, create a configuration file. Name it whatever you wish (eg. PORT-x.conf) and fill it with this content:

      port PORT-x
      cluster-enabled yes
      cluster-config-file nodes-PORT-x.conf
      cluster-node-timeout 5000
      appendonly yes
    
  • Start a Redis server (node) in each port. This will open the normal port for client connection and the cluster-bus port (10000 + PORT-x), used between nodes to communicate.

      $ cd PORT-x
      $ ../redis-server ./PORT-x.conf
    
  • Execute the cluster manager (redis-trib.rb) located in the /opt/bitnami/redis/bin directory:

      $ ./redis-trib.rb create --replicas 1 127.0.0.1:PORT1 127.0.0.1:PORT-2 127.0.0.1:PORT-3 127.0.0.1:PORT-4 127.0.0.1:PORT-5 127.0.0.1:PORT-6
    
  • Connect to each node in the cluster as usual.

Automatic approach

Redis comes with a tool named create-cluster, located at /opt/bitnami/scripts/create-cluster. This allows you to avoid the manual configuration described above.

By default, this utility will create 6 nodes with 1 replica and will start creating nodes on port 30000. In order to not modify the utility, is recommended to create a config.sh script in the same folder as create-cluster with the following content:

PORT=STARTING-PORT-NUMBER
TIMEOUT=2000
NODES=6
REPLICAS=1

Start the node and create the cluster:

$ ./create-cluster start
$ ./create-cluster create

Stop the cluster:

$ ./create-cluster stop

Clean up the folder:

$ ./create-cluster clean

How can I run a command in the Bitnami Redis Stack?

Log in to the server console as the bitnami user and run the command as usual. The required environment is automatically loaded for the bitnami user.

How to test Redis with a client?

You can test your Redis installation with a client like Predis, which is written in PHP. Find a complete list of Redis clients here.

NOTE: To use the example script below, you must have PHP installed on the server. You can check this by executing php -v. If you don't have it available, you can easily install PHP on Debian with the command sudo apt-get install php5 or on CentOS with the command sudo yum install php.

Begin by extracting the contents of the downloaded archive and creating a simple script named example.php.

$ cd predis-1.0
$ nano example.php

The script begins by including the class autoloader file and instantiating an object of the class:

require 'autoload.php';
$client = new Predis\Client(array(
  'host' => '127.0.0.1',
  'port' => 6379,
  'password' => 'PASSWORD'
));

Notice that it configures the client object by defining the Redis server host, port and password. Replace these values with actual values for your server.

You can now use the object's set() and get() methods to add or remove values from the cache. In this example, the set() method stores the value 'cowabunga' using the key 'foo'. The key can then be used with the get() method to retrieve the original value whenever needed.

$client->set('foo', 'cowabunga');
$response = $client->get('foo');

Here's the complete code for the example.php script:

<?php
require 'autoload.php';
$client = new Predis\Client(array(
  'host' => '127.0.0.1',
  'port' => 6379,
  'password' => 'PASSWORD'
));
$client->set('foo', 'cowabunga');
$response = $client->get('foo');
echo $response;
?>

Save the file and run it.

$ php example.php

The script will connect to your Redis server, save the value to the key 'foo', then retrieve and display it.

How to load a module to Redis?

You can extend your Redis solution using the Redis modules. Thus, you can implement new features and add new functionalities to your application.

Follow the instructions below to load a module to Redis:

IMPORTANT: Before follow the steps below, you must compile the source code of the module. Check the Redis Modules official documentation for more information on this.
  • Once you have the compiled module library (module.so), the recommended way to load the module is during the startup of Redis by adding the following configuration directive to the configuration file /opt/bitnami/redis/etc/redis.conf:

      loadmodule /path/to/the/module.so
    

    The configuration will take effect in the next time you restart Redis.

  • (Optional) To load the module at runtime (with no downtime), execute the following command. Replace the YOURPASSWORD placeholder with the value of your password:

      $ redis-cli -a YOURPASSWORD MODULE LOAD /path/to/the/module.so
    

For more ways to load modules, please check the oficial documentation Redis Modules: Loading modules.

How to create a full backup of Redis?

Backup

The Bitnami Redis Stack is self-contained and the simplest option for performing a backup is to copy or compress the Bitnami stack installation directory. To do so in a safe manner, you will need to stop all servers, so this method may not be appropriate if you have people accessing the application continuously.

Follow these steps:

  • Change to the directory in which you wish to save your backup:

      $ cd /your/directory
    
  • Stop all servers:

      $ sudo /opt/bitnami/ctlscript.sh stop
    
  • Create a compressed file with the stack contents:

      $ sudo tar -pczvf application-backup.tar.gz /opt/bitnami
    
  • Restart all servers:

      $ sudo /opt/bitnami/ctlscript.sh start
    

You should now download or transfer the application-backup.tar.gz file to a safe location.

Restore

Follow these steps:

  • Change to the directory containing your backup:

      $ cd /your/directory
    
  • Stop all servers:

      $ sudo /opt/bitnami/ctlscript.sh stop
    
  • Move the current stack to a different location:

      $ sudo mv /opt/bitnami /tmp/bitnami-backup
    
  • Uncompress the backup file to the original directoryv

      $ sudo tar -pxzvf application-backup.tar.gz -C /
    
  • Start all servers:

      $ sudo /opt/bitnami/ctlscript.sh start
    

If you want to create only a database backup, refer to these instructions for MySQL and PostgreSQL.

How to change the Redis password?

You can modify the Redis password by editing the requirepass directive in the /opt/bitnami/redis/etc/redis.conf file. Replace the NEWPASSWORD placeholder with the value of your new password:

requirepass NEWPASSWORD

Then restart the Redis server:

$ sudo /opt/bitnami/ctlscript.sh restart redis
  • (Optional) If you don't want to restart the Redis service, appart from changing the configuration file, you can execute the following command to change the password at runtime. Replace the CURRENTPASSWORD and NEWPASSWORD placeholders with the values of the current password and your new password:

    $ redis-cli -a CURRENTPASSWORD CONFIG set requirepass NEWPASSWORD

azure

Bitnami Documentation