• Redis安装CentOS


    Redis安装

    Yum 官方源里没有 redis,所以采用手动源码安装
    1、 上传 redis 安装包到 Linux 任意目录下,解压 
    tar xvf redis-5.0.7.tar.gz
    2、 安装 gcc(redis 安装依赖 C 语言环境,需要先安装 gcc)
    yum install -y gcc
    3、 进入解压后的 redis 目录下,执行编译操作
    make MALLOC=libc
    4、 执行安装命令
    make install
    5、 安装成功
     

    Redis配置

    1、 在 redis 目录下,新建 conf 文件夹,将 redis.conf 配置文件拷贝到 conf 文件夹下,并重
    命名为 6379.conf
    mkdir conf
    cp redis.conf ./conf/6379.conf
    2、 修改 redis.conf 配置文件
    ################################# GENERAL #####################################
    
    # By default Redis does not run as a daemon. Use 'yes' if you need it.
    # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
    daemonize yes          # 从 no 修改 为 yes ,是否开启线程守护,即是否支持后台运行
    
    ...
    
    # The filename where to dump the DB
    dbfilename dump_6379.rdb      # 修改redis数据存放本地的文件名
    
    ...
    
    # Examples:
    #
    # bind 192.168.1.100 10.0.0.1
    # bind 127.0.0.1 ::1
    #
    # ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
    # internet, binding to all the interfaces is dangerous and will expose the
    # instance to everybody on the internet. So by default we uncomment the
    # following bind directive, that will force Redis to listen only into
    # the IPv4 loopback interface address (this means Redis will be able to
    # accept connections only from clients running into the same computer it
    # is running).
    #
    # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
    # JUST COMMENT THE FOLLOWING LINE.
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # bind 127.0.0.1         # 注释这行,不是前面的 bind 127.0.0.1 ,开启支持远程连接,同时需要将 protected-mode 改为 node
    
    ...
    
    # By default protected mode is enabled. You should disable it only if
    # you are sure you want clients from other hosts to connect to Redis
    # even if no authentication is configured, nor a specific set of interfaces
    # are explicitly listed using the "bind" directive.
    protected-mode no        # 是否开启保护模式,从 yes 修改为 no,配合注释 bind 127.0.0.1 可以实现远程链接
    
    ...
    
    # If the master is password protected (using the "requirepass" configuration
    # directive below) it is possible to tell the replica to authenticate before
    # starting the replication synchronization process, otherwise the master will
    # refuse the replica request.
    #
    # masterauth <master-password>
    masterauth admin       # 服务器本机登录redis 是否需要密码
    
    requirepass admin      # 远程连接 redis 是否需要密码
     
    以上总结为下面6点:
     
      1、daemonize 改为 yes
      2、dbfilename 改为 dump_6379.rdb
      3、将 bind 127.0.0.1 注释掉
      4、protected-mode 改为 no

      5、masterauth admin      # 服务器本机登录redis 是否需要密码

      6、requirepass admin     # 远程连接 redis 是否需要密码(需要添加)

    Redis 启动

    1、 先启动 server,在 conf 目录下,执行
    redis-server ./6379.conf
    2、 使用客户端登录 redis,默认连接的是 6379 端口的 redis 实例
    redis-cli

    redis-cli -p 6379 (带有密码时,先登录进入redis命令行页面)
    auth "password" (我的密码开头带(,需要用引号括起来)
    3、 关闭 redis-server
    redis-cli shutdown

    多实例部署

    1、 在 conf 目录下,拷贝一份配置文件,如
    cp 6379.conf 6380.conf
    2、 修改 6380.conf 文件
    port 修改为 6380
    dbfilename 修改为 dump_6380.rdb
     
    3、 启动 redis-server
    redis-server ./6380.conf
    4、 使用客户端登录 redis
    redis-cli -p 6380

    Redis 主从关系配置

    在从 redis 中,新增配置,指向主 redis 的 ip 和端口
    slaveof ip 6379

    Redis 其他配置

    maxclient:最大连接数,默认是 10000
    maxmemory:最大内存
    requirepass:设置密码
     

    Redis应用场景

    1、缓存
    2、消息队列,比如支付
    3、活动排行榜或计数
    4、发布,订阅消息(消息通知)
    5、商品列表,评论列表等
    6、有效期控制

    Redis持久化

    Redis的两种持久化机制

    • rdb:在指定的时间间隔内将内存中的数据集快照写入磁盘
      优点:性能最大化 、如果数据集很大,RDB的启动效率会更高
      缺点:数据安全性差
    • aof:以日志的形式记录服务器所处理的每一个写、删除操作,查询操作不会记录
      优点:数据安全性高
      缺点:对于相同数量的数据集而言,AOF文件通常要大于RDB文件。恢复数据慢
  • 相关阅读:
    【Python爬虫】第五课(b站弹幕)
    【Python爬虫】第四课(查询照片拍摄地址)
    一些tips
    【Python爬虫】第三课(提取数据)
    【Python爬虫】第二课(请求头设置)
    【Python爬虫】第一课
    【数据分析】如何进行数据分析
    【数据分析】派单排序策略优化验证(附sql查询代码)
    python基础01
    消息
  • 原文地址:https://www.cnblogs.com/DeryKong/p/16272011.html
Copyright © 2020-2023  润新知