Redis 4.0 was released as GA in July 2017, newcomers should use Redis 5, but Redis 4 is currently the most production-proven release and will be updated for the next year until Redis 6 will be out.

  那我们就按照官方的推荐,下载5.0的版本吧.

安装Redis

cd /data/softpackage/
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
# 输出
cd src && make install
make[1]: 进入目录“/data/softpackage/redis-5.0.5/src”

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: 离开目录“/data/softpackage/redis-5.0.5/src”
# ok~

 启动Redis

[root@localhost redis-5.0.5]# redis-server redis.conf
26884:C 24 Jun 2019 14:05:29.761 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
26884:C 24 Jun 2019 14:05:29.762 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=26884, just started
26884:C 24 Jun 2019 14:05:29.762 # Configuration loaded
26884:M 24 Jun 2019 14:05:29.763 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 5.0.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 26884
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'
# 说明安装成功~

客户端链接

redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> set hello qvbilam
OK
127.0.0.1:6379> get hello
"qvbilam"

文件说明

 进入src目录下查看.

文件说明
redis-server启动Redis服务器
redis-cli命令行Redis客户端
redis-benchmarkRedis性能测试工具
redis-check-aofAOF修复工具
redis-check-dumpRDB文件检查工具
redis-sentinel高可用,用于Sentinel服务器

常用配置

参数说明
daemonize是否守护进程方式启动(默认no)
port对外端口(默认6379)
logfileRedis系统日志(只是文件名)
dirRedis工作目录(包括日志,持久化文件存在目录)
# 获取所有配置
[root@localhost ~]# redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> config get *
  1) "dbfilename"
  2) "dump.rdb"
  3) "requirepass"
  4) ""
  ...
  213) "bind"
  214) "127.0.0.1"
 # 以key-value的形式展现出来,一共107个配置

启动方式

极简启动

# 通过默认配置启动
redis-server

动态参数启动

# 设置端口号启动
redis-server --port 6666

配置启动

# 将配置写入文件
redis-server configPath
# 查看默认配置,不显示#和空格
cat redis.conf | grep -v '#' | grep -v '^$'
# 将默认配置文件写入到自己的配置中
mkdir config
cat redis.conf | grep -v '#' | grep -v '^$' > config/redis_6379.conf
vim config/redis_6379.conf

-- 修改

# 守护进程启动方式
daemonize yes
# 去掉,本机可通过ip访问,否则只能通过127.0.0.1
bind 127.0.0.1
# 设置外网访问
protected-mode no
# 工作目录
dir "/data/log/redis/data"
# 日志
logfile "6379.log"
# 剩下的都先删除掉

# 递归创建工作目录
mkdir -vp /data/log/redis/data
# 启动服务
redis-server config/redis_6379.conf
# 发现没有返回图标,查看是否启动
lsof -i:6379
# 返回
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
redis-ser 70125 root    6u  IPv6 323004      0t0  TCP *:6379 (LISTEN)
redis-ser 70125 root    7u  IPv4 323005      0t0  TCP *:6379 (LISTEN)
# 注意配置中的工作目录一定要先创建好,否则不会启动成功

-- 查看日志
cd /data/log/redis/data/
cat 6379.log
Last modification:February 18th, 2020 at 10:19 pm