Created
February 14, 2018 16:49
Star
You must be signed in to star a gist
Configure Redis on Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
############################################################################### | |
######################### Install and Configure Redis ######################### | |
############################################################################### | |
############################################################################### | |
################### Install the Build and Test Dependencies ################### | |
############################################################################### | |
# In order to get the latest version of Redis, we will be compiling and | |
# installing the software from source. Before we download the code, we need to | |
# satisfy the build dependencies so that we can compile the software. | |
sudo apt-get update -y | |
sudo apt-get install build-essential tcl -y | |
############################################################################### | |
#################### Download, Compile, and Install Redis ##################### | |
############################################################################### | |
# Download and Extract the Source Code | |
cd /tmp | |
# Download the latest stable version of Redis | |
curl -O http://download.redis.io/redis-stable.tar.gz | |
# Unpack the tarball | |
tar xzvf redis-stable.tar.gz | |
# Move into the Redis source directory structure | |
cd redis-stable | |
############################################################################### | |
########################### Build and Install Redis ########################### | |
############################################################################### | |
# Compile the Redis binaries | |
make | |
# install the binaries onto the system | |
sudo make install | |
############################################################################### | |
############################## Configure Redis ################################ | |
############################################################################### | |
# create a configuration directory | |
sudo mkdir /etc/redis | |
# copy over the sample Redis configuration file included in the Redis source | |
sudo cp /tmp/redis-stable/redis.conf /etc/redis | |
# change the supervised directive to 'supervised systemd' | |
sed -i -e 's/supervised no/supervised systemd/g' /etc/redis/redis.conf | |
# change the dir directive to 'dir /var/lib/redis' | |
sed -i -e 's/dir .\//dir \/var\/lib\/redis/g' /etc/redis/redis.conf | |
############################################################################### | |
###################### Create a Redis systemd Unit File ####################### | |
############################################################################### | |
# create a systemd unit file so that the init system can manage the | |
# Redis process | |
echo " | |
[Unit] | |
Description=Redis In-Memory Data Store | |
After=network.target | |
[Service] | |
User=redis | |
Group=redis | |
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf | |
ExecStop=/usr/local/bin/redis-cli shutdown | |
Restart=always | |
[Install] | |
WantedBy=multi-user.target" > /etc/systemd/system/redis.service | |
############################################################################### | |
################# Create the Redis User, Group and Directories ################ | |
############################################################################### | |
# create the redis user and group | |
sudo adduser --system --group --no-create-home redis | |
# create the redis directory | |
sudo mkdir /var/lib/redis | |
# give the redis user and group ownership over this directory | |
sudo chown redis:redis /var/lib/redis | |
#Adjust the permissions so that regular users cannot access this location | |
sudo chmod 770 /var/lib/redis | |
############################################################################### | |
############################ Start and Test Redis ############################# | |
############################################################################### | |
sudo systemctl start redis | |
echo 'done - you might want to test by $sudo systemctl status redis' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment