佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > 詳解Redis開(kāi)啟遠(yuǎn)程登錄連接

詳解Redis開(kāi)啟遠(yuǎn)程登錄連接

熱門(mén)標(biāo)簽:鐵路電話系統(tǒng) 呼叫中心市場(chǎng)需求 百度競(jìng)價(jià)排名 Linux服務(wù)器 服務(wù)外包 網(wǎng)站排名優(yōu)化 AI電銷 地方門(mén)戶網(wǎng)站

今天使用jedis客戶端api連接遠(yuǎn)程連接redis的時(shí)候,一直報(bào)錯(cuò),如下:

redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect
  at redis.clients.jedis.Connection.connect(Connection.java:164)
  at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:80)
  at redis.clients.jedis.Connection.sendCommand(Connection.java:100)
  at redis.clients.jedis.Connection.sendCommand(Connection.java:91)
  at redis.clients.jedis.BinaryClient.auth(BinaryClient.java:551)
  at redis.clients.jedis.BinaryJedis.auth(BinaryJedis.java:2047)
  at sy.test.TestJedis.setUp(TestJedis.java:18)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
  at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
  at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
  at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
  at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.net.ConnectException: Connection refused: connect
  at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
  at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
  at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
  at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
  at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
  at java.net.Socket.connect(Socket.java:579)
  at redis.clients.jedis.Connection.connect(Connection.java:158)
  ... 30 more 

原來(lái)是redis默認(rèn)只能localhost登錄,所以需要開(kāi)啟遠(yuǎn)程登錄。解決方法如下:

在redis的配置文件redis.conf中,找到bind localhost注釋掉。

注釋掉本機(jī),局域網(wǎng)內(nèi)的所有計(jì)算機(jī)都能訪問(wèn)。

band localhost   只能本機(jī)訪問(wèn),局域網(wǎng)內(nèi)計(jì)算機(jī)不能訪問(wèn)。

bind  局域網(wǎng)IP    只能局域網(wǎng)內(nèi)IP的機(jī)器訪問(wèn), 本地localhost都無(wú)法訪問(wèn)。

驗(yàn)證方法:

  [root@mch ~]# ps -ef | grep redis
  root   2175   1 0 08:15 ?    00:00:05 /usr/local/bin/redis-server *:6379 

/usr/local/bin/redis-server *:6379 中通過(guò)"*"就可以看出此時(shí)是允許所有的ip連接登錄到這臺(tái)redis服務(wù)上。

注意事項(xiàng):

今天再設(shè)置遠(yuǎn)程訪問(wèn)的時(shí)候,在啟動(dòng)Redis的時(shí)候報(bào)錯(cuò):Creating Server TCP listening socket *:6379: unable to bind socket(Redis一定不能設(shè)置成后臺(tái)運(yùn)行,否則終端不會(huì)有任何錯(cuò)誤顯示)。

上網(wǎng)搜索說(shuō)各種原因的都有,有的說(shuō)是Redis版本的bug(我用的版本是3.2.0),我是參考以下幾篇文章解決了這個(gè)問(wèn)題:

https://github.com/antirez/redis/issues/3241

http://stackoverflow.com/questions/8537254/redis-connect-to-remote-server

我沒(méi)有注釋掉bind 127.0.0.1,而是將bind 127.0.0.1 改成了bind 0.0.0.0。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • Redis分布式鎖實(shí)現(xiàn)方式及超時(shí)問(wèn)題解決
  • Redis開(kāi)啟鍵空間通知實(shí)現(xiàn)超時(shí)通知的步驟詳解
  • Redis總結(jié)筆記(二):C#連接Redis簡(jiǎn)單例子
  • Python與Redis的連接教程
  • java 連接Redis的小例子
  • Redis連接超時(shí)異常的處理方法

標(biāo)簽:仙桃 湘潭 湖南 銅川 蘭州 衡水 崇左 黃山

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《詳解Redis開(kāi)啟遠(yuǎn)程登錄連接》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    华安县| 和平县| 南宫市| 镇沅| 含山县| 海丰县| 大渡口区| 洛隆县| 同德县| 通州区| 综艺| 友谊县| 沾化县| 陈巴尔虎旗| 巴林右旗| 黄陵县| 伊吾县| 克东县| 兴海县| 兴业县| 平顶山市| 尼勒克县| 衡山县| 襄樊市| 古浪县| 和林格尔县| 来安县| 永吉县| 沾益县| 阿拉善右旗| 福贡县| 栾川县| 青铜峡市| 泰兴市| 安西县| 光山县| 临夏市| 温泉县| 随州市| 祁连县| 巫溪县|