最近碰到一个Redis一直无法访问本地host设置的一个 redis.com的问题,但是换成127.0.0.1就能连接成功,经过了解,是Redis配置文件中默认设置了bind 127.0.0.1
的原因。
解决办法:
修改本地Redis配置文件 redis.conf
################################## 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
bind 0.0.0.0
改完配置文件后发现重启Redis服务无效,(Ps:自己将Redis做成了本地服务)
下面是安装和卸载Redis服务的命令,在redis-server.exe所在的目录下cmd执行下面命令即可:
安装redis为服务:
redis-server.exe --service-install redis.windows.conf --loglevel verbose
卸载redis服务:
redis-server --service-uninstall
修改完成后,手动启动下本地服务的Redis服务,再次连接,问题解决。
网友评论