Bitnami Redis Virtual Machine

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! This guide includes some basic information you will need to get started with your application.

How to import a Bitnami Virtual Machine?

Check the following instructions to import a Bitnami Virtual Machine:

Importing a Bitnami Virtual Machine in VirtualBox
  • Select the "File -> Import Appliance" menu option and select the .ova file downloaded from the Bitnami website. Then click "Continue".
  • Once it is imported, click the "Start" button in the VirtualBox toolbar.

For a detailed walkthrough, check our Virtualbox tutorial.

Importing a Bitnami Virtual Machine in a VMware product
  • Select the "File -> Import" menu option and select the .ova file downloaded from the Bitnami website. Then click "Continue".
  • Once the import is complete, click "Finish" to start the virtual machine.

For a detailed walkthrough, check our VMware tutorial, which uses VMware Fusion as an example. To learn how to use our virtual machines with other VMware products, refer to the VMware Workstation documentation or the VMware vSphere documentation.

What credentials do I need?

You need two sets of credentials:

  • The application credentials, consisting of a username and password. These credentials allow you to log in to your new Bitnami application.

  • The server credentials, consisting of an SSH username and password. These credentials allow you to log in to your Virtual Machines server using an SSH client and execute commands on the server using the command line.

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

Username: user

What is the administrator password?

Password: The administrator password to log in to your application is randomly generated during the first boot. Check the FAQ to learn how to retrieve it.

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

SSH username: bitnami

What is my server IP address?

The IP address is displayed on screen at the end of the boot process, but you can check it at any time by running the following command:

  $ sudo ifconfig

Check server IP address

How do I get my SSH key or password?

You can obtain the SSH password from the virtual machine console when it starts up. Click here for more information.

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.

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

virtualMachine

Bitnami Documentation