Ubuntu 18.04 安装 Redis

下载安装 redis

$ cd /usr/local/src
$ wget http://download.redis.io/releases/redis-5.0.5.tar.gz
$ tar xzf redis-5.0.5.tar.gz
$ cd redis-5.0.5
$ make 
$ make install

修改配置文件

$ mkdir /etc/redis
$ cp /usr/local/src/redis-5.0.5/redis.conf /etc/redis
$ vi /etc/redis/redis.conf

根据以下内容更改文件 /etc/redis/redis.conf

...
supervised systemd
...
dir /var/lib/redis
...

创建一个 Redis systemd Unit File

$ vi /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 用户,组和目录

$ adduser --system --group --no-create-home redis
$ mkdir /var/lib/redis
$ chown redis:redis /var/lib/redis
$ chmod 770 /var/lib/redis

启动和测试 Redis

$ systemctl daemon-reload
$ systemctl start redis
$ systemctl status redis

$ redis-cli
> ping
pong

博客:godper.com
参考:letscloud.io,redis.io

你可能感兴趣的:(redis,ubuntu)