Python遠端連線Redis

來源:互聯網
上載者:User

標籤:cat   nat   拒絕   接受   地址   group   note   restart   運行   

import redis
r=redis.Redis(host=‘192.168.56.102‘,port=6379,db=0,password=‘jinxfredis‘ )
r.set(‘name‘,‘jin‘)
print(r.get(‘name‘))

Python遠端連線Redis時報如下錯誤:

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.

拒絕的Redis在保護模式下運行,因為保護模式是啟用的,沒有指定綁定地址,沒有向用戶端請求身分識別驗證密碼。在這種模式下,串連只能從環回介面接受。如果你想從外部電腦串連到複述,你可能採取的解決方案:

1)只是禁用保護模式發送命令的配置設定保護模式沒有從loopback介面串連到複述同一主機伺服器正在運行,然而確保複述,不是公開從互連網訪問如果你這樣做。使用配置重寫使此更改永久存在。

2)也可以通過編輯Redis設定檔,將protected模式選項設定為no,然後重新啟動伺服器,從而禁用protected模式。

3)如果您只是為了測試而手動啟動伺服器,那麼使用“—保護模式no”選項重新啟動伺服器。

4)設定綁定地址或身分識別驗證密碼。注意:為了讓伺服器開始接受來自外部的串連,您只需要做上述的一件事。

按照上面2-4設定後,

   bind 0.0.0.0

   protected-mode no

   requirepass password

從新啟動Redis,還是報相同的錯誤。。。

原來Redis不指定設定檔,就按照預設的設定啟動,所以重新啟動Redis時,設定指定的設定檔,遠程就可以正常訪問了

[[email protected] ~]# redis-server redis-3.2/redis.conf 

Python遠端連線Redis

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.