Skip to content

Instantly share code, notes, and snippets.

@cwonrails
Forked from clzola/install-redis.sh
Created August 17, 2017 21:33
Show Gist options
  • Save cwonrails/975ca6445d1bd4000ed13c9f6479d8d9 to your computer and use it in GitHub Desktop.
Save cwonrails/975ca6445d1bd4000ed13c9f6479d8d9 to your computer and use it in GitHub Desktop.
Bash script for installing Redis on Ubuntu 16.04
#!/bin/bash
# Install the Build and Test Dependencies
apt-get update
apt-get install -y curl build-essential tcl
# Download and Extract the Source Code
cd /tmp
curl -O http://download.redis.io/redis-stable.tar.gz
tar xzvf redis-stable.tar.gz
cd redis-stable
# Build and Install Redis
make
make test
make install
# Configure Redis
mkdir /etc/redis
cp /tmp/redis-stable/redis.conf /etc/redis
sed -i "s/^supervised no/supervised systemd/" /etc/redis/redis.conf
sed -i "s/^dir \.\//dir \/var\/lib\/redis/" /etc/redis/redis.conf
# Create a Redis systemd Unit File
wget -O /etc/systemd/system/redis.service https://gist.githubusercontent.com/clzola/2b98f0b128d94811e43f86412dc375a1/raw/d2b1475ba3c44d6b3341a724166004e366a7304b/redis.service
# Create the Redis User, Group and Directories
adduser --system --group --no-create-home redis
mkdir /var/lib/redis
chown redis:redis /var/lib/redis
chmod 770 /var/lib/redis
# Start Redis
systemctl start redis
# Enable Redis to Start at Boot
systemctl enable redis
# Clean
rm -rf /tmp/redis-stable
rm /tmp/redis-stable.tar.gz
[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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment