查看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了