【redis】redis的bind配置
在配置檔案redis.conf中,預設的bind 介面是127.0.0.1,也就是本地迴環地址。這樣的話,訪問redis服務只能通過本機的客戶端連線,而無法通過遠端連線,
這樣可以避免將redis服務暴露於危險的網路環境中,防止一些不安全的人隨隨便便通過遠端
連線到redis服務。
如果bind選項為空的話,那會接受所有來自於可用網路介面的連線。
在使用redis的時候出現連線不成功;
在專案中匯入jar包jedis-2.7.2.jar,編寫測試類
@Test
public void testJedisSingle() throws Exception {
//建立一個jedis物件
Jedis jedis = new Jedis("192.168.64.129",6379);
jedis.set("test", "hello jedis");
String string = jedis.get("test");
System.out.println(string);
jedis.close();
}
根據redis.conf配置檔案中bind的值的不同,出現不同的提示資訊;但是不影響Linux系統中redis的正常使用;
當不存在bind時
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.
當bind 本機ip地址時
程式碼可以測試通過,但是Linux系統中出現問題
[root@root redis]# ./bin/redis-cli -c
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Could not connect to Redis at 127.0.0.1:6379: Connection refused
當bind 為預設的127.0.0.1時
程式碼測試不通過
redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect
Linux中操作正常
目前採用的方式,程式碼和Linux中的redis客戶端都可以使用
1.在bind中配置多個IP地址,bind 192.168.64.129 127.0.0.1
2.將bind的值配置為bind 0.0.0.0
相關文章
- 配置RedisRedis
- redis之 Redis持久化配置Redis持久化
- redis常用配置Redis
- Lumen配置RedisRedis
- Redis(1)- Redis資料庫的安裝和配置Redis資料庫
- Spring MVC整合redis的配置SpringMVCRedis
- Redis的安裝與配置Redis
- Centos-redis配置redis.conf內容CentOSRedis
- Redis筆記01-Redis配置檔案Redis筆記
- Redis主從配置Redis
- 【Redis 系列】redis 學習七,那些你不知道的 redis 配置檔案詳解Redis
- Linux CentOS 7 下 Redis 的配置LinuxCentOSRedis
- 4-4 Redis 的常用配置Redis
- NoSQL之Redis的配置優化SQLRedis優化
- CentOS redis安裝配置CentOSRedis
- Tp5 配置 RedisRedis
- 【Redis】安裝與配置Redis
- [Redis] 安裝與配置Redis
- docker 配置 Redis 主從DockerRedis
- redis sentinel配置啟動Redis
- Redis持久化及其配置Redis持久化
- redis配置和工具類Redis
- Redis優化配置解析Redis優化
- redis.conf 常用配置Redis
- NoSQL之Redis配置解析SQLRedis
- 實時監控redis -- redislive與redis踩坑配置Redis
- Redis實戰-詳細配置-優雅的使用Redis註解/RedisTemplateRedis
- Redis效能篇(三)Redis關鍵系統配置:如何應對Redis變慢Redis
- Redis的安裝配置與命令操作Redis
- Redis的配置及與memcached區別Redis
- Linux上的redis的安裝和配置LinuxRedis
- springboot2.0 配置redis哨兵Spring BootRedis
- redis配置檔案詳解Redis
- 39_配置redis叢集Redis
- redis 配置檔案詳解Redis
- Docker配置redis主從哨兵DockerRedis
- Redis哨兵模式配置測試Redis模式
- windows上安裝配置redisWindowsRedis
- Centos安裝與配置RedisCentOSRedis