天天看點

【redis】redis的bind配置

  在配置檔案redis.conf中,預設的bind 接口是127.0.0.1,也就是本地回環位址。這樣的話,通路redis服務隻能通過本機的用戶端連接配接,而無法通過遠端連接配接,

  這樣可以避免将redis服務暴露于危險的網絡環境中,防止一些不安全的人随随便便通過遠端

連接配接到redis服務。

  如果bind選項為空的話,那會接受所有來自于可用網絡接口的連接配接。

在使用redis的時候出現連接配接不成功;

在項目中導入jar包jedis-2.7.2.jar,編寫測試類

根據redis.conf配置檔案中bind的值的不同,出現不同的提示資訊;但是不影響Linux系統中redis的正常使用;

  redis.clients.jedis.exceptions.JedisDataException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified,

no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode

sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change

permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with

the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

  代碼可以測試通過,但是Linux系統中出現問題

  [root@root redis]# ./bin/redis-cli -c

  Could not connect to Redis at 127.0.0.1:6379: Connection refused

  代碼測試不通過

  redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect

  Linux中操作正常

  1.在bind中配置多個IP位址,bind 192.168.64.129 127.0.0.1

  2.将bind的值配置為bind 0.0.0.0