下载 Redis

wget http://download.redis.io/releases/redis-5.0.6.tar.gz
https://redis.io/download

解压

tar -xzf redis-5.0.6.tar.gz

编译安装

编译,并将 redis 安装到指定目录

cd redis-5.0.6
make PREFIX=/usr/local/redis install

添加环境变量

REDIS_HOME=/usr/local/redis
export PATH=$PATH:$REDIS_HOME/bin
vim ~/.zshrc 

REDIS_HOME=/usr/local/redis
export PATH=$PATH:$REDIS_HOME/bin

# source 生效
source ~/.zshrc    

修改 redis.conf 配置文件

vim redis-5.0.6/redis.conf

# 设置为后台启动
# daemonize no
daemonize yes

# 允许远程连接 Redis,默认只能连接本地
# bind 127.0.0.1

# 默认 protected-mode yes
protected-mode no

# 自定义 port 6379
port 6379

# 自定义密码,默认无
requirepass ec-aabbcc

创建服务文件 redis.service

sudo vim /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis/bin/redis-server /etc/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID 
# ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

启动

systemctl daemon-reload

systemctl start redis.service
systemctl status redis.service