赞
踩
使用 Jedis 操作 Redis 数据库报错 :
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: Failed to create socket. at redis.clients.jedis.DefaultJedisSocketFactory.createSocket(DefaultJedisSocketFactory.java:110) at redis.clients.jedis.Connection.connect(Connection.java:226) at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:140) at redis.clients.jedis.Connection.sendCommand(Connection.java:163) at redis.clients.jedis.Connection.sendCommand(Connection.java:154) at redis.clients.jedis.BinaryClient.auth(BinaryClient.java:815) at redis.clients.jedis.BinaryJedis.auth(BinaryJedis.java:2709) at org.example.jedis.JedisDemo.main(JedisDemo.java:11) Caused by: java.net.SocketTimeoutException: connect timed out at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at redis.clients.jedis.DefaultJedisSocketFactory.createSocket(DefaultJedisSocketFactory.java:80) ... 7 more
Redis 数据库的 配置文件 是 安装目录下的 redis.windows-service.conf 配置文件 ;
注释所有的绑定配置 :
# 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. # 默认情况下,如果未指定“bind”配置指令,则Redis会侦听来自服务器上所有可用网络接口的连接。 # 可以使用“bind”配置指令来仅侦听一个或多个选定的接口,后跟一个或多个IP地址。 # 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). # 警告 : 如果运行 Redis 的计算机直接暴露在互联网上, # 则绑定到所有接口是危险的,并会将实例暴露给互联网上的所有人。 # 因此,默认情况下,我们取消注释以下绑定指令,这将强制 Redis 仅侦听 IPv4 环回接口地址 #(这意味着 Redis 只能接受来自在同一台计算机上运行的客户端的连接)。 # # 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 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 是一种安全保护层,旨在避免在互联网上公开的 Redis 实例被访问和利用。 # # 当启用保护模式并且如果: # # 1)服务器未使用“bind”指令明确绑定到一组地址。 # 2)未配置密码。 # # 服务器仅接受来自IPv4和IPv6环回地址127.0.0.1和::1以及Unix域套接字的客户端连接。 # # 默认情况下启用了保护模式。仅在您确定希望来自其他主机的客户端连接到 Redis,即使未配置身份验证, # 也没有使用“bind”指令明确列出一组特定接口时才应禁用它。 protected-mode yes
此处保护模式要关闭 , 修改为
protected-mode no
要关闭防火墙 , 才能被外部设备访问 本地的 Redis 服务器 ;
在 Windows 中查询防火墙是否关闭的命令 :
Get-NetFirewallProfile | select Name, Enabled
命令 ;
PS C:\Users\octop\Desktop> Get-NetFirewallProfile | select Name, Enabled
Name Enabled
---- -------
Domain True
Private True
Public True
netsh advfirewall show allprofiles state
命令 ;
D:\>netsh advfirewall show allprofiles state
域配置文件 设置:
----------------------------------------------------------------------
状态 启用
专用配置文件 设置:
----------------------------------------------------------------------
状态 启用
公用配置文件 设置:
----------------------------------------------------------------------
状态 启用
确定。
执行
systemctl status firewalld
命令 , 查询防火墙状态 ;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。