Contents

Install and configure Redis on Ubuntu 16.04 with systemd

Contents

Manage my redis service with systemctl

Author: @hackedunit
I just fixed a bug.

  1. Install pre-requisities
1
2
$ sudo apt-get install  tcl8.6-dev
```2. Install Redis  

$ cd /tmp
$ wget 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
$ sudo vi /etc/redis/redis.conf


supervised systemd

/var/lib/redis

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  ...  
  dir /var/lib/redis  
  ...  
  
```Save and close the file. 4. Configure systemd to start Redis on boot  
```
$ sudo vi /etc/systemd/system/redis.service  
  [Unit]  
  Description=Redis In-Memory Data Store  
  After=network.target  
  
  [Service]  
  User=redis  
  Group=redis  
  Type=forking  
  ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf  
  ExecStop=/usr/local/bin/redis-cli shutdown  
  Restart=always  
  
  [Install]  
  WantedBy=multi-user.target  

```5. Create 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  
  
```6. Start the Redis service and set Redis to start on boot  
```
  $ sudo systemctl start redis  
  $ sudo systemctl enable redis  
  $ sudo systemctl status redis  
  
```