redis不能訪問(wèn)本機(jī)真實(shí)ip地址的解決方案
redis無(wú)法訪問(wèn)本機(jī)真實(shí)ip地址
1.我在進(jìn)行用jedis來(lái)連接redis時(shí)出現(xiàn)了問(wèn)題:
我用Jedis jedis = new Jedis("127.0.0.1",6379);可以成功連接,但是我如果把127.0.0.1換成的本機(jī)地址如192.168.1.103發(fā)現(xiàn)會(huì)報(bào)錯(cuò).
2.解決這個(gè)問(wèn)題
要修改redis.windows.conf的配置文件(說(shuō)明一下我的redis是在windows版的)
這里要改兩個(gè)地方:
- 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
上面的代碼可以看到我的修改了哪些東西,之后再嘗試連接一下。
無(wú)法通過(guò)ip訪問(wèn)redis服務(wù)
嘗試在本機(jī)以及其他主機(jī)通過(guò)ip來(lái)訪問(wèn)redis服務(wù)時(shí),一直出現(xiàn)錯(cuò)誤,無(wú)法通過(guò)IP訪問(wèn)redis服務(wù)。
究其原因:
redis.conf文件中配置了訪問(wèn)限制,通過(guò)bind來(lái)限制了ip訪問(wèn),默認(rèn)為127.0.0.1
注釋掉bind之后,本地可以通過(guò)ip訪問(wèn),但是其他主機(jī)無(wú)法訪問(wèn),在redis3之后,有一個(gè)protected-mode 參數(shù),默認(rèn)開啟 yes,改成no,重啟服務(wù)即可。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Redis和Lua實(shí)現(xiàn)分布式限流器的方法詳解
這篇文章主要給大家介紹了關(guān)于Redis和Lua實(shí)現(xiàn)分布式限流器的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Redis和Lua具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06Redis分布式鎖的正確實(shí)現(xiàn)方法總結(jié)
在本篇文章里小編給大家整理的是關(guān)于Redis分布式鎖的正確實(shí)現(xiàn)方式介紹,有興趣的朋友們可以學(xué)習(xí)下。2020-02-02Redis慢查詢?nèi)罩九c監(jiān)視器問(wèn)題
這篇文章主要介紹了Redis慢查詢?nèi)罩九c監(jiān)視器問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12Redis底層數(shù)據(jù)結(jié)構(gòu)之dict、ziplist、quicklist詳解
本文給大家詳細(xì)介紹了Redis的底層數(shù)據(jù)結(jié)構(gòu):dict、ziplist、quicklist的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2021-09-09Redis如何實(shí)現(xiàn)數(shù)據(jù)庫(kù)讀寫分離詳解
Redis的主從架構(gòu),能幫助我們實(shí)現(xiàn)讀多,寫少的情況,下面這篇文章主要給大家介紹了關(guān)于Redis如何實(shí)現(xiàn)數(shù)據(jù)庫(kù)讀寫分離的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2018-03-03