zoukankan      html  css  js  c++  java
  • 连redis 连不上怎么办!

    网上很多,你应该已经查了一溜够了!我这里只强调config 配置文件!

    而配置里,两个配置起决定性作用,bind属性和protected-mode属性(protected-mode有没有是要看版本,老版本没有的)。我为什么把注释都放进来呢,因为人家已经写得很清楚了,好好看!

    ################################## NETWORK #####################################
    
    # By default, if no "bind" configuration directive is specified, Redis listens
    # for connections from all the network interfaces available on the server.
    # It is possible to listen to just one or multiple selected interfaces using
    # the "bind" configuration directive, followed by one or more IP addresses.
    #
    # 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 lookback 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
    # Protected mode is a layer of security protection, in order to avoid that
    # Redis instances left open on the internet are accessed and exploited.
    #
    # When protected mode is on and if:
    #
    # 1) The server is not binding explicitly to a set of addresses using the
    #    "bind" directive.
    # 2) No password is configured.
    #
    # The server only accepts connections from clients connecting from the
    # IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
    # sockets.
    #
    # 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 yes

    如果链接不上,我看很多都让把 protected-mode 修改为 no  并且 将 bind属性注释掉 (老版本只注释掉bind),但是,这样,不就谁都可以链接redis数据库了?那就不安全了啊

    所以,protected-mode属性根本不用改,bind属性不要注释,只需要在bind 后添加你想要链接此数据库的地址就好了 如:

    bind 192.168.1.100 10.0.0.1 就代表192.168.1.100和10.0.0.1是可以链接到数据库的,人家写的很清楚了!而且这也是安全并被推荐使用的!

    下面说一下windows 下启动redis服务的问题!

    如下图,是windows安装完的文件

    通常,我们会双击redis-server.exe启动服务,但是默认服务使用的并不是这里的conf配置文件,如图:

    这个/path/to/redis.conf才是redis-server.exe启动时指定的redis.conf配置,理论上我们修改这个redis.conf里的属性,重新启动服务也行,然而,我并没找到这个redis.conf

    所以我修改了redis.windows-service.conf 配置(当然你可以修改redis.windows.conf我认为也没问题),并指定修改好的配置文件 如:

    这时候再启动redis-cli.exe 运行命令:config get * 查看一下你的conf配置就ok了

    至于linux下,如果链接不上redis也是这个思路:修改下配置文件,然后指定配置文件重新启动服务就好了!

    关闭服务
      redis-cli -h 127.0.0.1 -p 6379 shutdown
      1.访问redis根目录    cd  /usr/local/redis-2.8.19
      2.登录redis:redis-cli -h 127.0.0.1 -p 6379
      3.查看所有key值:keys *
      4.删除指定索引的值:del key
      5.清空整个 Redis 服务器的数据:flushall
      6.清空当前库中的所有 key:flushdb
    linux下redis操作指令
    查询redis
       ps aux|grep redis
    关闭redis服务
       redis-cli shutdown
    指定conf启动redis-server
       redis-server etc/redis/redis.conf
  • 相关阅读:
    HDU4477 Cut the rope II 递推
    HDU4571 Travel in time 动态规划
    在VS2010中使用$err,hr快速查看当前GetLastError()的值
    对C语言的volatile关键字的理解
    三星S6D1121主控彩屏(240*320*18bit,262K)图形设备接口(GDI)实现
    C语言创建二叉树数据结构, 以及各种遍历
    Ubuntu下使用Dr.com宽带客户端上网的步骤
    8051单片机学习笔记/概要/总结/备忘
    联想笔记本电脑Ubuntu系统下触摸板的锁定
    [MSP430] 集成开发环境 IAR Embedded Workbench for MSP430 5.50
  • 原文地址:https://www.cnblogs.com/ruber/p/13434616.html
Copyright © 2011-2022 走看看