Redis 安装

Redis 支持 window, linux ,

window 上安装 redis

下载地址:https://github.com/dmajkic/redis/downloads。

下载到的 Redis 支持 32bit 和 64bit ,根据自己系统实际情况选择不同的版本来安装。 但是我还是建议大家重装系统,安装64位的!

运行Redis

1. 比如我安装在 D:/app/redis/
2. 打开一个 cmd 窗口,并cd 到 D:/app/redis/
3. 启动redis (注意配置文件路径,请根据自己的安装版本选择配置文件)
    redis-server.exe redis.conf
    redis-server.exe redis.windows.conf

Linux 手动 安装 Redis

编译环境(本环境安装是在Centos下面进行的):

yum -y install gcc gcc-c++ libstdc++-devel

安装包下载地址:http://redis.io/download

$ wget http://download.redis.io/releases/redis-2.8.17.tar.gz
$ tar xzf redis-2.8.17.tar.gz
$ cd redis-2.8.17
$ make
  • 上面我们是通过 wget 来下载安装包,下载完成文件名为 redis-2.8.17.tar.gz
  • tar 表示解压文件,上面解压文件名为 redis-2.8.17
  • cd redis-2.8.17 表示进入 redis-2.8.17

进入到src 下面,有两个很重要的命令

  • redis-server 启动redis服务器

命令详细如下

Usage: ./redis-server [/path/to/redis.conf] [options]
       ./redis-server - (read config from stdin)
       ./redis-server -v or --version
       ./redis-server -h or --help
       ./redis-server --test-memory <megabytes>

Examples:
       ./redis-server (run the server with default conf)
       ./redis-server /etc/redis/6379.conf
       ./redis-server --port 7777
       ./redis-server --port 7777 --slaveof 127.0.0.1 8888
       ./redis-server /etc/myredis.conf --loglevel verbose

Sentinel mode:
       ./redis-server /etc/sentinel.conf --sentinel
  • redis-cli 客户端相关

命令详细如下

Usage: redis-cli [OPTIONS] [cmd [arg [arg ...]]]
  -h <hostname>      Server hostname (default: 127.0.0.1).
  -p <port>          Server port (default: 6379).
  -s <socket>        Server socket (overrides hostname and port).
  -a <password>      Password to use when connecting to the server.
  -r <repeat>        Execute specified command N times.
  -i <interval>      When -r is used, waits <interval> seconds per command.
                     It is possible to specify sub-second times like -i 0.1.
  -n <db>            Database number.
  -x                 Read last argument from STDIN.
  -d <delimiter>     Multi-bulk delimiter in for raw formatting (default: \n).
  -c                 Enable cluster mode (follow -ASK and -MOVED redirections).
  --raw              Use raw formatting for replies (default when STDOUT is
                     not a tty).
  --no-raw           Force formatted output even when STDOUT is not a tty.
  --csv              Output in CSV format.
  --latency          Enter a special mode continuously sampling latency.
  --latency-history  Like --latency but tracking latency changes over time.
                     Default time interval is 15 sec. Change it using -i.
  --slave            Simulate a slave showing commands received from the master.
  --rdb <filename>   Transfer an RDB dump from remote server to local file.
  --pipe             Transfer raw Redis protocol from stdin to server.
  --pipe-timeout <n> In --pipe mode, abort with error if after sending all data.
                     no reply is received within <n> seconds.
                     Default timeout: 30. Use 0 to wait forever.
  --bigkeys          Sample Redis keys looking for big keys.
  --scan             List all keys using the SCAN command.
  --pattern <pat>    Useful with --scan to specify a SCAN pattern.
  --intrinsic-latency <sec> Run a test to measure intrinsic system latency.
                     The test will run for the specified amount of seconds.
  --eval <file>      Send an EVAL command using the Lua script at <file>.
  --help             Output this help and exit.
  --version          Output version and exit.

Examples:
  cat /etc/passwd | redis-cli -x set mypasswd
  redis-cli get mypasswd
  redis-cli -r 100 lpush mylist x
  redis-cli -r 100 -i 1 info | grep used_memory_human:
  redis-cli --eval myscript.lua key1 key2 , arg1 arg2 arg3
  redis-cli --scan --pattern '*:12345*'

运行redis

$ src/redis-server

启动 redis 服务进程后,就可以使用测试客户端程序 redis-cli 和 redis 服务交互了

$ src/redis-cli
redis> set pangugle hello
OK
redis> get pangugle
"hello"

Ubuntu 下安装

在 Ubuntu 系统安装 Redi 可以使用以下命令:

$sudo apt-get update
$sudo apt-get install redis-server

启动 Redis

$redis-server

查看 redis 是否启动?

$redis-cli

以上命令将打开以下终端:

redis 127.0.0.1:6379>
127.0.0.1 是本机 IP ,6379 是 redis 服务端口。现在我们输入 PING 命令。

redis 127.0.0.1:6379> ping
PONG

CentOS6 安装 redis

centos6 yum安装redis

  • yum添加epel源

    yum install epel-release

  • 安装yum

    yum install redis

  • Redis 服务端配置

    vim  /etc/redis.conf

    修改以守护进程方式启动:

    找到redis.conf 并修改 daemonize no 为 daemonize yes

  • 开启客户端要确保服务端启动

    redis-server /etc/redis.conf

  • redis-server -v 查看版本

    redis-server /etc/redis.conf redis-cli ping
    PONG

    测试启动 redis-cli ping 返回PONG,启动成功。

    redis-cli 链接

  • 设置redis开机自启动

    chkconfig --add redis

    chkconfig redis on 开启开机启动

    chkconfig redis off 关闭开机启动

    打开redis命令:service redis start

    关闭redis命令:service redis stop

    重启redis命令:service redis restart

Centos7 yum 安装 redis

  • 安装redis

    yum -y install redis

  • 启动redis

    systemctl start redis

  • 查看redis

    systemctl status redis

  • 停止redis

    systemctl stop redis

  • 重启redis

    systemctl restart redis

docker 安装 redis

请看 https://www.pangugle.com/tech/article/docker/run_redis.html

注意:

redis 的默认端口是 6379, 如果需要远程提供访问,请记得开启端口,也就是防火墙

如果使用的是 iptables 的话

iptables -I INPUT -p tcp -m tcp --dport 6379 -j ACCEPT