Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save carltondickson/62977cee8ea32c6ce594eaa60524292b to your computer and use it in GitHub Desktop.
Save carltondickson/62977cee8ea32c6ce594eaa60524292b to your computer and use it in GitHub Desktop.
Install and Configure Redis on Ubuntu 16.04
# From https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-redis-on-ubuntu-16-04
# Use at your own risk
sudo apt-get update
sudo apt-get install build-essential tcl
cd /tmp
curl -O http://download.redis.io/redis-stable.tar.gz
tar xzvf redis-stable.tar.gz
cd redis-stable
make
make test
sudo make install
sudo mkdir /etc/redis
sudo cp /tmp/redis-stable/redis.conf /etc/redis
# /etc/redis/redis.conf changes
sudo nano /etc/redis/redis.conf
# In the file, find the supervised directive. Currently, this is set to no. Since we are running an operating system that uses the systemd init system, we can change this to systemd:
supervised systemd
# Next, find the dir directory. This option specifies the directory that Redis will use to dump persistent data. We need to pick a location that Redis will have write permission and that isn't viewable by normal users.
dir /var/lib/redis
sudo nano /etc/systemd/system/redis.service
# /etc/systemd/system/redis.service
[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
# Redis users, group and directories
sudo adduser --system --group --no-create-home redis
sudo mkdir /var/lib/redis
sudo chown redis:redis /var/lib/redis
sudo chmod 770 /var/lib/redis
# Start and test redis
sudo systemctl start redis
sudo systemctl status redis
redis-cli
ping
# PONG response
set test "It's working!"
get test
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment