zoukankan      html  css  js  c++  java
  • redis的bind绑定详解

    查看redis版本: redis-server -v

    $ redis-server -v
    Redis server v=4.0.9 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=9435c3c2879311f3
    

    或者运行redis-cli之后输入info命令可以查看redis的配置信息

    $ redis-cli
    127.0.0.1:6379> info
    # Server
    redis_version:4.0.9
    redis_git_sha1:00000000
    redis_git_dirty:0
    redis_build_id:9435c3c2879311f3
    

    redis-server4.0的版本默认启动了保护模式, 在redis的配置文件/etc/redis/redis.conf中可以看到

    bind 127.0.0.1 ::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
    

    同时默认设置了绑定bind 127.0.0.1 ::1, 这时只能本机通过回环地址127.0.0.1访问redis服务

    让其他电脑也能访问到这台机器的redis

    之前的误区是:

    如果想要其他的A电脑访问本机redis服务, 那么在配置文件中加入 bind A电脑的IP 就可以了

    我之前想在172.17.100.39上访问172.17.100.37上运行的redis服务, 按之前错误的做法是bind 172.17.100.39, 但是发现redis始终启动不起来

    (base) xxxx:/etc/redis$ sudo systemctl restart redis.service
    Job for redis-server.service failed because a timeout was exceeded.
    See "systemctl status redis-server.service" and "journalctl -xe" for details.
    

    其实这是错误的理解, bind的意思是将redis服务绑定在哪个网卡(IP)上, 通过ifconfig可以查看本机所有的网卡对应的IP地址, 因此bind后面的ip地址只能在ifconfigIP地址中.

    因此正确的做法是将redis服务器添加bind 172.17.100.37, 将其绑定在37上后, 39服务器直接访问37IP地址就可以访问到37的redis了

  • 相关阅读:
    JD笔试试题(凭记忆写的+人生感悟 try finally )
    ZOJ 3626 Treasure Hunt I(树形dp)
    Oracle数据库有用函数
    leetcode
    BIEE11G系统数据源账号过期问题(默认安装步骤)
    class文件结构浅析(2)
    使用Lua 局部变量来优化性能,同一时候比較局部变量和全局变量
    Linux基本配置和管理 3 ---- Linux命令行文本处理工具
    android面试题及答案
    CentOS 6.4的安装--史上最全-CRPER木木
  • 原文地址:https://www.cnblogs.com/gcxblogs/p/14669484.html
Copyright © 2011-2022 走看看