Skip to content

Instantly share code, notes, and snippets.

@josephdicdican
Last active February 10, 2017 09:20
Show Gist options
  • Save josephdicdican/6b9d872d413d6f73be39b39b0d5bde18 to your computer and use it in GitHub Desktop.
Save josephdicdican/6b9d872d413d6f73be39b39b0d5bde18 to your computer and use it in GitHub Desktop.

Redis Setup

Build dependencies

sudo apt-get update
sudo apt-get install build-essential tcl

Download and install redis

wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make && make test

Essentials

  • redis-server - Redis server
  • redis-cli - command line interface utility to talk with Redis

Make install

sudo make install

Configure Redis

sudo mkdir /etc/redis
sudo cp ./redis-stable/redis.conf /etc/redis
sudo vim /etc/redis/redis.conf

# Look for supervised and dir directive
supervised systemd
dir /var/lib/redis

Create a Redis systemd Unit File

sudo vim /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

Create the Redis User, 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

To execute or call redis-server / redis-cli without specifying full path.

Starting Redis

sudo systemctl start redis
sudo systemctl status redis

# Output
● redis.service - Redis In-Memory Data Store
   Loaded: loaded (/etc/systemd/system/redis.service; disabled; vendor preset: enabled)
   Active: active (running) since Fri 2017-02-10 07:53:23 UTC; 4s ago
 Main PID: 12125 (redis-server)
    Tasks: 3
   Memory: 6.2M
      CPU: 6ms
   CGroup: /system.slice/redis.service
           └─12125 /usr/local/bin/redis-server 127.0.0.1:6379

Feb 10 07:53:23 ip-172-31-11-169 redis-server[12125]:  |    `-._`-._        _.-'_.-'    |
Feb 10 07:53:23 ip-172-31-11-169 redis-server[12125]:   `-._    `-._`-.__.-'_.-'    _.-'
Feb 10 07:53:23 ip-172-31-11-169 redis-server[12125]:       `-._    `-.__.-'    _.-'
Feb 10 07:53:23 ip-172-31-11-169 redis-server[12125]:           `-._        _.-'
Feb 10 07:53:23 ip-172-31-11-169 redis-server[12125]:               `-.__.-'
Feb 10 07:53:23 ip-172-31-11-169 redis-server[12125]: 12125:M 10 Feb 07:53:23.150 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn
Feb 10 07:53:23 ip-172-31-11-169 redis-server[12125]: 12125:M 10 Feb 07:53:23.150 # Server started, Redis version 3.2.7
Feb 10 07:53:23 ip-172-31-11-169 redis-server[12125]: 12125:M 10 Feb 07:53:23.150 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To
Feb 10 07:53:23 ip-172-31-11-169 redis-server[12125]: 12125:M 10 Feb 07:53:23.150 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create
Feb 10 07:53:23 ip-172-31-11-169 redis-server[12125]: 12125:M 10 Feb 07:53:23.150 * The server is now ready to accept connections on port 6379

Check Redis if working

$ redis-cli ping
PONG

Should be working fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment