1. 下载最新 stable 源码 https://redis.io/

2. 为支持 systemd,安装必要的库,

$ sudo apt-get install libsystemd-dev   # for debian serial
$ sudo yum install systemd-devel        # for redhat serial

3. 解压,参考 README.md 编译安装

$ tar --gzip -xvf redis-6.2.1.tar.gz
$ cd redis-6.2.1/
$ make USE_SYSTEMD=yes
$ make test                         #(long time)
$ sudo make install

4. 源码目录下已有配置文件 redis.conf,这里简单修改如下几项,(修改后将其放在某个固定路径,例如 /redis/conf下)

 

复制代码
...
daemonize yes
...
supervised auto
...
pidfile /var/run/redis.pid
...
save "" # 注意,snapshot 这里需要根据实际需求仔细调整,我只用作临时数据存储,这里不需要持久化
...

复制代码

 

$ sudo mkdir -p /redis/conf/
$ sudo cp redis.conf /redis/conf

5. 因为支持 systemd,所以不能直接使用源代码包提供的 utils/install_server.sh 来将 redis 设置为开机启动,

$ cd utils
$ sudo ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server This systems seems to use systemd. Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!

但是在 utils/ 下提供了 systemd service 的模板文件 systemd-redis_server.service,按需修改如下,

复制代码
# Redis systemd service file

[Unit]
Description=Redis data structure server
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /redis/conf/redis.conf
ExecStartPost=/bin/sh -c "echo $MAINPID > /var/run/redis.pid"
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/local/bin/redis-cli -p 6379 shutdown
TimeoutSec=0               #关掉Time开头的其余两个参数
LimitNOFILE=5000
PrivateTmp=yes
复制代码

然后将其拷贝到 /lib/systemd/system 下,并重命名为 redis.service

$ sudo cp systemd-redis_server.service /lib/systemd/system/redis.service

启动,

$ sudo systemctl enable redis.service
$ sudo systemctl start redis.service
$ systemctl status redis.service

安装 Python 绑定,

$ sudo pip3 install -i https://pypi.douban.com/simple redis

响应解析 parse 加速库,

$ sudo pip3 install -i https://pypi.douban.com/simple hiredis

 安装命令提示工具,类似于 mysql 的 mycli 工具,官网见 https://iredis.io/

$ sudo pip3 install -i https://pypi.douban.com/simple iredis

 

更多信息可参考网友博客: https://www.cnblogs.com/milton/p/11154954.html