redis中bind配置的詳細(xì)步驟
前沿
在配置文件redis.conf中,默認(rèn)的bind 接口是127.0.0.1,也就是本地回環(huán)地址。這樣的話,訪問redis服務(wù)只能通過本機(jī)的客戶端連接,而無法通過遠(yuǎn)程連接,
這樣可以避免將redis服務(wù)暴露于危險(xiǎn)的網(wǎng)絡(luò)環(huán)境中,防止一些不安全的人隨隨便便通過遠(yuǎn)程
連接到redis服務(wù)。
如果bind選項(xiàng)為空的話,那會接受所有來自于可用網(wǎng)絡(luò)接口的連接。
今天按裝??redis6之后在使用redis的時(shí)候出現(xiàn)連接不成功;安全組也開放了到底是什么問題呢??
帶著疑問我通過redis-cli連接發(fā)現(xiàn)
./redis-cli -h 指定ip -p 指定端口 -a 指定密碼
發(fā)現(xiàn)能夠正常連接,嗯應(yīng)該是port沒有設(shè)置。
后來使用了jedis實(shí)現(xiàn)測試
@Test public void testJedisSingle() throws Exception { //創(chuàng)建一個(gè)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(); }
后來得知。根據(jù)redis.conf配置文件中bind的值的不同,出現(xiàn)不同的提示信息;但是不影響Linux系統(tǒng)中redis的正常使用;
當(dāng)不存在bind時(shí)
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.
當(dāng)bind 本機(jī)ip地址時(shí)
代碼可以測試通過,但是Linux系統(tǒng)中出現(xiàn)問題
[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
當(dāng)bind 為默認(rèn)的127.0.0.1時(shí)
代碼測試不通過
redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect
那么這個(gè)bing參數(shù)該如何配置呢?
1.在bind中配置多個(gè)IP地址,bind 192.168.64.129 127.0.0.1 空格分割
2.將bind的值配置為bind 0.0.0.0 任何ip地址都能連接
注意
我最后就是設(shè)置成0.0.0.0了,因?yàn)椴⒉皇蔷€上環(huán)境,圖方便所以沒有指定指定的端口。大家如果是線上環(huán)境,這里要按照自己的情況進(jìn)行配置否則會有安全問題。(ps之前的個(gè)人機(jī)器經(jīng)常被植入挖礦程序??)
到此這篇關(guān)于redis中bind配置的詳細(xì)步驟的文章就介紹到這了,更多相關(guān)redis bind配置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
百行代碼實(shí)現(xiàn)基于Redis的可靠延遲隊(duì)列
本文主要介紹了百行代碼實(shí)現(xiàn)基于Redis的可靠延遲隊(duì)列,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06redis數(shù)據(jù)類型及應(yīng)用場景知識點(diǎn)總結(jié)
在本篇文章里小編給大家整理的是關(guān)于2020-02-02Redis實(shí)現(xiàn)分布式鎖方法詳細(xì)
在單體應(yīng)用中,如果我們對共享數(shù)據(jù)不進(jìn)行加鎖操作,會出現(xiàn)數(shù)據(jù)一致性問題,我們的解決辦法通常是加鎖。在分布式架構(gòu)中,我們同樣會遇到數(shù)據(jù)共享操作問題。本文將介紹Redis實(shí)現(xiàn)分布式鎖的五種方式。需要的可以參考一下2021-12-12redis3.2配置文件redis.conf詳細(xì)說明
redis3.2配置詳解,Redis啟動的時(shí)候,可以指定配置文件,詳細(xì)說明請看本文說明2018-03-03Redis擊穿穿透雪崩產(chǎn)生原因分析及解決思路面試
這篇文章主要為大家介紹了Redis擊穿穿透雪崩產(chǎn)生原因及解決思路的面試問題答案參考,有需要的朋友可以借鑒參考下,希望能夠有所幫助祝大家多多進(jìn)步2022-03-03Redis報(bào)錯UnrecognizedPropertyException: Unrecognized 
在使用SpringBoot訪問Redis時(shí),報(bào)錯提示識別不了屬性headPart,經(jīng)過排查,發(fā)現(xiàn)并非Serializable或getset方法問題,而是存在一個(gè)方法getHeadPart,但無headPart屬性,解決方案是將getHeadPart改為makeHeadPart2024-10-10