redis官方下载网址: https://redis.io/download

安装目录: /usr/local/bin/
配置文件路径: /etc/redis/redis.conf
配置端口: 6379
服务端: /usr/local/bin/redis-server
客户端: /usr/local/bin/redis-cli
持久化文件存放目录路径: /var/lib/redis
pid路径: /var/run/redis.pid
日志路径: /var/log/redis.log

1. centos下安装redis

以centos7.4为例.

1.1. 源码编译安装
$ mkdir ~/soft
$ cd ~/soft
$ wget -c http://download.redis.io/releases/redis-4.0.10.tar.gz
$ tar xzf redis-4.0.10.tar.gz
$ cd redis-4.0.10
$ make
$ sudo make install
1.2. 添加服务并添加到开机自启动
$ cd ~/soft/redis-4.0.10/utils
$ sudo ./install_server.sh

Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] /etc/redis/redis.conf
Please select the redis log file name [/var/log/redis_6379.log] /var/log/redis.log
Please select the data directory for this instance [/var/lib/redis/6379] /var/lib/redis
Please select the redis executable path [] /usr/local/bin/redis-server
Selected config:
Port : 6379
Config file : /etc/redis/redis.conf
Log file : /var/log/redis.log
Data dir : /var/lib/redis
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

$ 
1.3. 创建redis用户及其用户组并给相应目录授权
$ sudo useradd --r --U -M redis
$ sudo chown redis:redis /var/lib/redis
$ sudo chmod 770 /var/lib/redis
1.4. 修改服务名及配置文件

重命名服务名redis_6379redis, 在此之前先停止服务:

$ sudo /etc/init.d/redis_6379 stop
$ sudo mv /etc/init.d/redis_6379 /etc/init.d/redis
$ sudo vim /etc/init.d/redis

将文件内的redis_6379替换为redis, vim按ESC切换到命令模式, 替换后保存退出vim

:%s/redis_6379/redis/g
:wq

编辑配置文件/etc/redis/redis.conf

$ sudo vim /etc/redis/redis.conf

. . . 
daemonize yes

. . . 
supervised systemd

. . . 
pidfile /var/run/redis.pid

. . . 
logfile /var/log/redis.log

. . . 
dir /var/lib/redis

将文件内的redis_6379替换为redis, vim按ESC切换到命令模式, 替换后保存退出vim

:%s/redis_6379/redis/g
:wq
1.5. redis服务管理
$ sudo systemctl daemon-reload
$ sudo systemctl enable redis
$ sudo systemctl status redis
● redis.service - LSB: start and stop redis
   Loaded: loaded (/etc/rc.d/init.d/redis; bad; vendor preset: disabled)
   Active: inactive (dead) since 五 2018-06-22 14:48:36 CST; 7s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 21946 ExecStop=/etc/rc.d/init.d/redis stop (code=exited, status=0/SUCCESS)
  Process: 21909 ExecStart=/etc/rc.d/init.d/redis start (code=exited, status=0/SUCCESS)

6月 22 14:24:50 izm5eat3t2va6ch6mdbpbtz systemd[1]: Starting LSB: start and ...
6月 22 14:24:50 izm5eat3t2va6ch6mdbpbtz redis[21909]: Starting Redis server...
6月 22 14:24:50 izm5eat3t2va6ch6mdbpbtz systemd[1]: Started LSB: start and s...
6月 22 14:48:36 izm5eat3t2va6ch6mdbpbtz systemd[1]: Stopping LSB: start and ...
6月 22 14:48:36 izm5eat3t2va6ch6mdbpbtz redis[21946]: /var/run/redis.pid doe...
6月 22 14:48:36 izm5eat3t2va6ch6mdbpbtz systemd[1]: Stopped LSB: start and s...
Hint: Some lines were ellipsized, use -l to show in full.

$ sudo systemctl start redis
● redis.service - LSB: start and stop redis
   Loaded: loaded (/etc/rc.d/init.d/redis; bad; vendor preset: disabled)
   Active: active (exited) since 五 2018-06-22 14:24:50 CST; 5s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 21909 ExecStart=/etc/rc.d/init.d/redis start (code=exited, status=0/SUCCESS)

6月 22 14:24:50 izm5eat3t2va6ch6mdbpbtz systemd[1]: Starting LSB: start and ...
6月 22 14:24:50 izm5eat3t2va6ch6mdbpbtz redis[21909]: Starting Redis server...
6月 22 14:24:50 izm5eat3t2va6ch6mdbpbtz systemd[1]: Started LSB: start and s...
Hint: Some lines were ellipsized, use -l to show in full.

开启服务: sudo systemctl start redis
停止服务: sudo systemctl stop redis
重启服务: sudo systemctl restart redis
查看进程: sudo lsof -i:6379
杀掉进程: sudo kill -9 pid
进入redis shell: redis-cli

2. ubuntu下安装redis

以ubuntu16.04为例.

源码安装步骤与centos的基本相同。