Redis is an open source in-memory key-value store known for its performance and flexibility. Redis has built-in replication and can be set up in a master-slave configuration. For more information read here.
I want to add an object cache for my
I am assuming you are running an AWS LightSail with Ubuntu 16.04 as the base operating system and you have full root access to the server. Also, it is better to make a Snapshot of your server before you go any further. This is in case things go horribly wrong and you wish to rollback.
The suggested way of installing Redis is to compile it from source as the software has no dependency other than a GCC compiler and
Build and Test dependencies
Login to your server and prepare the server to satisfy build dependencies. We need to confirm we have software to compile and run tests for Redis. The tcl package is a requirement for us to be able to run make test
sudo apt install update
sudo apt install build-essential tcl
Make a temporary work directory and cd to it. This directory will serve as our base for compiling the software. After installation is done, you can go ahead and remove the temporary work directory. Use
mkdir ~/work && cd ~/work
tar xvzf redis-stable.tar.gz
After the binaries are successfully compiled it is a good idea to run make test from the command line.
After all tests are passed you can go ahead and install the binaries by typing
sudo make install
Next step is to copy the server configuration file. We will use the standard location /etc/redis/redis.conf
sudo mkdir /etc/redis
cp ~/work/redis-stable/redis.con /etc/redis
Use your favorite editor to edit this configuration file to make some minor edits
sudo vi /etc/redis/redis.conf
Find the working directory section and set the dir to /var/lib/redis. We will create this directory after we create the redis user.
# Note that you must specify a directory here, not a file name.
Also, change supervision method to
# Note: these supervision methods only signal "process is ready."
# They do not enable continuous liveness pings back to your supervisor.
Next, we will create a user, group and directory for
sudo adduser --system --group --no-create-home redis
sudo mkdir -p /var/lib/redis
sudo chown redis:redis /var/lib/redis
sudo chmod 770 /var/lib/redis
To start the service on boot we will set a
Save the script and do a service reload. Enable and start the Redis Server. If you make changes to the service file you should do a daemon reload.
systemctl enable redis.service
systemctl start redis.service
To test the R
/etc/systemd/system# redis-cli ping
Another way to see messages related to the service is via journalctl as shown below.
journalctl | grep redis-server
redis-server: 1214:M 21 Dec 2018 18:19:14.882 # Server initialized
You should see a server initialized message.
At this point our Redis server is ready to be used. If possible, you can also boot the server to verify if the service starts up automatically.