查看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-server
4.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
地址只能在ifconfig
的IP
地址中.
因此正确的做法是将redis
服务器添加bind 172.17.100.37
, 将其绑定在37
上后, 39
服务器直接访问37
的IP
地址就可以访问到37
的redis了