redis不能訪問本機(jī)真實(shí)ip地址的解決方案
redis無法訪問本機(jī)真實(shí)ip地址
1.我在進(jìn)行用jedis來連接redis時出現(xiàn)了問題:
我用Jedis jedis = new Jedis("127.0.0.1",6379);可以成功連接,但是我如果把127.0.0.1換成的本機(jī)地址如192.168.1.103發(fā)現(xiàn)會報(bào)錯.
2.解決這個問題
要修改redis.windows.conf的配置文件(說明一下我的redis是在windows版的)
這里要改兩個地方:
- 1.修改bind的ip
- 2.修改protected-mode yes為protected-mode no
我的修改如下
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bind 127.0.0.1 192.168.1.103 # 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 no
上面的代碼可以看到我的修改了哪些東西,之后再嘗試連接一下。
無法通過ip訪問redis服務(wù)
嘗試在本機(jī)以及其他主機(jī)通過ip來訪問redis服務(wù)時,一直出現(xiàn)錯誤,無法通過IP訪問redis服務(wù)。
究其原因:
redis.conf文件中配置了訪問限制,通過bind來限制了ip訪問,默認(rèn)為127.0.0.1
注釋掉bind之后,本地可以通過ip訪問,但是其他主機(jī)無法訪問,在redis3之后,有一個protected-mode 參數(shù),默認(rèn)開啟 yes,改成no,重啟服務(wù)即可。
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Windows系統(tǒng)設(shè)置Redis服務(wù)使其開機(jī)自啟動
Redis是一種鍵值對數(shù)據(jù)庫,也稱為內(nèi)存數(shù)據(jù)庫,因?yàn)樗梢詫?shù)據(jù)存儲在內(nèi)存中,而不是在磁盤上,下面這篇文章主要給大家介紹了關(guān)于Windows系統(tǒng)設(shè)置Redis服務(wù)使其開機(jī)自啟動的相關(guān)資料,需要的朋友可以參考下2024-01-01
關(guān)于redis Key淘汰策略的實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄P(guān)于redis Key淘汰策略的實(shí)現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-03-03
聊聊使用RedisTemplat實(shí)現(xiàn)簡單的分布式鎖的問題
這篇文章主要介紹了使用RedisTemplat實(shí)現(xiàn)簡單的分布式鎖問題,文中給大家介紹在SpringBootTest中編寫測試模塊的詳細(xì)代碼,需要的朋友可以參考下2021-11-11
從零搭建SpringBoot2.X整合Redis框架的詳細(xì)教程
這篇文章主要介紹了從零搭建SpringBoot2.X整合Redis框架的詳細(xì)教程,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-12-12

