The latest version of Ubuntu at the time of this writing is 15.10. Ubuntu 15.10 already shipped with Redis 3 but if you need LTS (Long Term Support) version of Ubuntu (Latest LTS version is Ubuntu 14.04) you can only install Redis 2.8 from the repository.
We need make to compile Redis from source. You can check whether you already have make installed or not using which command.
$ which make
If the command above does not give output like the above it means that you haven't got make installed . You can install make from the repository.
$ sudo apt-get -y install cmake
All the prerequisites are now ready, the first thing to do is download Redis source. At the time of this writing the latest stable version of Redis is 3.0.5. You might want to check Redis Download Page for the latest stable version of Redis.
After running the command above please check with the page on the redis-hashes repo above and make sure the output of the command above is correct.
We can see the the sha1 hash of the package that was downloaded and the one hosted on github is the same.
After checking the SHA1 hash of the package, now extract the redis source archive and rename the extracted directory to redis
$ tar xzf redis-3.0.5.tar.gz
$ mv redis-3.0.5 redis
Go to the new directory that contains the redis source code and run make to compile the Redis source code. This process might take some time depending on your machine specification.
$ cd redis
The above output has been truncated. If your compilation of Redis was successful you should get output similar to the above.
After successful compilation, let's install the redis binary files. The binary will be installed to the ```/usr/local/bin``` folder. We need to use ```sudo``` to copy these binary files to the directory.
$ sudo make install
cd src && make install
make: Entering directory `/home/sumodirjo/redis/src'
## Trying Redis
Now, the redis-server binary is ready, we can test using it by running ```/usr/local/bin/redis-server```. You will see output similar to text below :
21242:C 03 Nov 20:44:36.309 # Warning: no config file specified, using the default config. In order to specify a config file use /usr/local/bin/redis-server /path/to/redis.conf
21242:M 03 Nov 20:44:36.310 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
21242:M 03 Nov 20:44:36.310 # Redis can't set maximum open files to 10032 because of OS error: Operation not permitted.
21242:M 03 Nov 20:44:36.311 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
21242:M 03 Nov 20:44:36.316 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
21242:M 03 Nov 20:44:36.317 # Server started, Redis version 3.0.5
21242:M 03 Nov 20:44:36.317 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
21242:M 03 Nov 20:44:36.317 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
21242:M 03 Nov 20:44:36.317 * DB loaded from disk: 0.000 seconds
21242:M 03 Nov 20:44:36.317 * The server is now ready to accept connections on port 6379
The process is still running on foreground, to exit you can press ```CTRL+C```.
## Configuring Redis
Even though we're already able to run Redis server but it is not properly setup yet. In this section we'll configure Redis so that it become a properly setup service on Ubuntu 14.04.
### Creating the Redis User
We need to create a user to run redis server. You can run command below to create new user named ```redis```.
### Create a Redis Default Configuration
The Redis init script will read the default configuration when starting redis-server. Create a new file ```/etc/default/redis-server``` with the content below. All content in this file is commented so nothing is being applied from this file.
redis-server configure options
ULIMIT: Call ulimit -n with this argument prior to invoking Redis itself.
This may be required for high-concurrency environments. Redis itself cannot
alter its limits as it is not being run as root. (default: do not call
### Customizing the Redis Configuration
We need to change some configurations inside the redis.conf file before copying the file to redis.
We'll make Redis server work as a daemon. Find the line below:
Change it to
Change the pidfile location. Find the line below
Change it to
This configuration change will make Redis server listen to all network interfaces. If you don't need the Redis service to be accessible from another server you can leave this configuration default. Hoever, if you need to make Redis accessible from another, find line below
Change it to
Now, configuring the logfile location. By default redis does not do logging. Find the line below :
Change it to
The last one is redis data directory. Find the line below
Change it to
### Copying Configuration
Copy the Redis main configuration file. Make sure you already changed the values on the ```redis.conf``` file specified above.
$ sudo cp redis.conf /etc/redis
Copy the Redis Sentinel configuration
$ sudo cp sentinel.conf /etc/redis
Log rotation is a must have activity for a server application. By rotating the log, we make sure that the main log file size is not growing huge but we will still have a history of log files because the log is rotated.
For example if the redis-server log named redis-server.log when rotated it will be copied to redis-server.log.1 and then compressed as redis-server.log.1.gz. The logfile redis-server.log will be emptied.
On the next log rotation the redis-server.log.1.gz will be moved to redis-server.log.2.gz and again redis-server.log copied and compressed as redis-server.log.1.gz and so on.
Create new file ```/etc/logrotate.d/redis-server``` and add logrotate configuration below on the file.
The logrotate configuration above will rotate the log on a weekly basis and keep the previous log for 12 times, in this case 12 weeks.
You can change the ```weekly``` line above with daily, monthly, or yearly. If your redis has heavy load and writes a lot of log you might want to consider rotating the log daily. How long you want to keep the logs can be configured with ```rotate``` directive above.
### Creating Init Script for Redis
Redis server needs an init script so that we can easily manage the Redis service (start, stop, restart the service).
Create new file ```/etc/init.d/redis-server``` with the content below.
BEGIN INIT INFO
Required-Start: $syslog $remote_fs
Required-Stop: $syslog $remote_fs
Default-Start: 2 3 4 5
Default-Stop: 0 1 6
Short-Description: redis-server - Persistent key-value db
Description: redis-server - Persistent key-value db
Redis also comes with a benchmarking tool. To benchmark your redis server you can run command below
## Running Tests
Redis comes with a testing script, but the script needs tcl 8.5 as prerequisite. To install tcl 8.5 you can run command below
$ sudo apt-get -y install tcl8.5
### Redis Tests
Now you 're ready to run a test, make sure that redis-server is already running. If you want to run a redis test you can run the script with the command below (don't forget the ```./``` to run the script).
Sentinel is a feature of Redis where multiple instance of Redis can work together as cluster. We're not going to discuss about Sentinel in this tutorial but we'll only run the test. To run sentinel the test, you can run command below
GOOD! No errors.
In this tutorial we learned how-to install latest stable version of Redis from source by compiling the source code and configuring redis to run as a service.
It's always easier and recommended to use Redis from your the Linux distribution repository but if you need features that are not available on the Redis version provided by the Linux distribution, you might have to compile and install the latest stable version of Redis yourself.
Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will...
Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you...