Redis 6.2.6 最新版安装教程

1. CentOS 8.2 安装 redis 6.2.6

  • Redis 官网: redis ,复制如下链接地址
    image-20220415222503931

  • 使用 wget 下载

    wget https://download.redis.io/releases/redis-6.2.6.tar.gz
    
  • 查看Linux系统有没有 gcc 环境

    gcc --version
    

    image-20220415223132125

  • 没有就安装,下载安装最新版的 gcc 编译器,安装C语言的编译环境

    yum install gcc-c++
    gcc -v   // 查看gcc版本
    
  • 安装完 gcc 后, 解压

    tar -zxvf redis-6.2.6.tar.gz
    
  • 解压完后进入目录

    cd redis-6.2.1 
    
  • 在解压目录下再次执行 make 命令编译

    make install   // 检查
    
  • Redis 安装目录: /usr/local/bin

  • 查看默认安装目录:

    redis-benchmark : 性能测试工具,可以在自己电脑运行,看看电脑性能如何

    redis-check-aof: 修复有问题的 AOF 文件, rdb 和 aof

    redis-chec-dump: 修复有问题的 dump.rdb 文件

    redis-sentinel: Redis集群使用

    redis-server : Redis 服务器启动命令

    redis-cli: 客户端,操作入口

2. Redis 启动

Redis 提供了多种启动方法。

  1. 前台启动(默认的启动方法,不推荐)
    image-20220415224223803
    当窗口关闭后,redis就停止运行了。

  2. 直接运行的时候设置参数
    redis-server - - port 6388, 这种方式不利于生产环境保存常用的设置

  3. 后台启动,使用配置文件

    备份 redis.conf , 拷贝一份 redis.conf 到其他目录。 如让在 /etc 目录下,cp redis.conf /etc/redis.conf

    修改配置文件, 将 daemonize no 改成 yes, 让服务在后台启动

    redis 后台启动: redis-server /etc/redis.conf

    查看redis进程

    image-20220415225155551

  4. 将启动固定为启动命令。此方法最为常用,便于运维。

    # cat /usr/lib/systemd/system/redis.service
    [Unit]
    Description=Redis
    After=syslog.target network.target remote-fs.target nss-lookup.target
     
    [Service]
    Type=forking
    PIDFile=/run/redis_6379.pid
    ExecStart=/usr/local/redis-6.2.4/src/redis-server /usr/local/redis-6.2.4/redis.conf
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true
     
    [Install]
    WantedBy=multi-user.target
    

    可以使用命令启动:

    systemctl start redis
    

3. Redis 关闭

  1. 单实例关闭

    redis-cli shutdown
    

    也可以进入终端后再关闭

    redis-cli
    127.0.0.1:6379> shutdown
    not connected> exit
    
    
    redis-cli
    Could not connect to Redis at 127.0.0.1:6379: Connection refused
    
  2. 采用 kill 端口的方式关闭 redis 进程
    image-20220415225916549

  3. 多实例关闭,指定端口关闭(生产环境不实用)

    redis-cli -p 6379 shutdown
    
  4. redis-cli shutdown nosave|save 表示是否在关闭redis 之前生成持久化文件

  5. systemctl stop redis 服务

4. Redis 客户端登录

  1. 交互式
    image-20220415230318761
  2. 命令式
    image-20220415230408833

猜你喜欢

转载自blog.csdn.net/zhw21w/article/details/124205961