Installing and configuring Redis on Ubuntu
- By : YaoYuan
- Category : linux Tutorial
- Tags : configuring, installing, redis, ubuntu
- Comment : 0
Redis is an in-memory data structure store, most commonly used as a database, cache and message broker. It is built to support data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, and more.
This tutorial will show you how to properly setup Redis on a Linux-based machine running Ubuntu as an operating system. Follow the steps below and you’ve have no trouble navigating through this straightforward installation and configuration process.
- The first thing you must do is connect to your Linux server via SSH and resynchronize the package index files from their sources.
- Once that’s done, go ahead and install the newest versions of all packages currently installed on your server by entering these commands:
sudo apt-get update sudo apt-get upgrade
- To install Redis on your system, simply run the command below:
sudo apt-get install redis-server
- Optionally, in case you plan to use Redis as an object cache for WordPress or any other PHP-based application, you also need to install the following package:
sudo apt-get install php-redis
- To start configuring Redis on Ubuntu, you must first edit the /etc/redis/redis.conf file. To do so, you can use nano or any other text editor of your choice to access the file:
sudo nano /etc/redis/redis.conf
- Next, you should configure the max memory for Redis, as well as inform Redis what to will select for removal when the max memory is reached. To do this, add the following lines at the end of the file:
maxmemory 128mb maxmemory-policy allkeys-lru
- In the example above, Redis will remove any key according to the LRU algorithm when the specified memory of 128mb is reached. After saving and closing the file, restart the service:
sudo systemctl restart redis-server.service
- Finally, enable Redis on system boot:
sudo systemctl enable redis-server.service
Now you have successfully set up Redis on your Linux-based VPS running Ubuntu. Congratulations!