Deploy your Bitnami Redis Stack on 1&1 Cloud Platform now! Launch Now

Bitnami Redis for 1&1 Cloud Platform

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 1&1! 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, 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 1&1 Cloud Platform 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?

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

SSH username: root

How do I get my SSH key or password?

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 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

How to upload files to the server with SFTP?

NOTE: Bitnami applications can be found in /opt/bitnami/apps.
  • If you are using the Bitnami Launchpad for 1&1 Cloud Platform, obtain your SSH credentials by following these steps:

    • Browse to the Bitnami Launchpad for 1&1 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.

      SSH credentials

  • If you are using the 1&1 Control Panel, obtain your SSH credentials by following these steps:

    • Log in to the 1&1 Control Panel.
    • Navigate to the "Infrastructure -> Servers" section.
    • Look through the list of servers until you find the server you wish to modify. Click the server name.
    • In the "Features -> Server access" section, note the SSH username and click the "Show Password" link to obtain the corresponding SSH password.

      SSH credentials

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 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. Specify root as the user name and enter the server password.

    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 /root 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 "SFTP" as the file protocol.
  • Enter your server host name and specify root as the user name.

    WinSCP configuration

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

    WinSCP configuration

You should now be logged into the /root 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, the username root and the SSH password.

    Cyberduck configuration

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

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

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.

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 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 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 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.

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 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
oneone