1. 程式人生 > >Java連線虛擬機器的redis報錯問題解決辦法

Java連線虛擬機器的redis報錯問題解決辦法

直奔主題,Java連線虛擬機器報錯,程式碼如下:

public class TestPing {

public static void main(String[] args) {
Jedis jedis = new Jedis("192.168.201.128", 6379);
System.out.println(jedis.ping());
}
}

執行報錯,控制檯資訊如下:

Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out

借鑑一些網友的解決方案:

關閉虛擬機器的防火牆

      1)暫時關閉防火牆:/etc/init.d/iptables stop

     2) 重啟虛擬機器生效:chkconfig iptables off   或者 /sbin/chkconfig --level 2345 iptables off

     樓主使用的是第二種方法,如下圖所示:

     

重啟虛擬機器之後,在檢視防火牆狀態,如下圖所示


繼續執行上述程式碼,報錯如下:

Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect

解決方案,修改redis.conf配置檔案,將埠號127.0.0.1註釋掉,這樣任何IP都能訪問,如下圖所示:


儲存退出後,執行程式碼,發現報錯依舊,因為尚未啟動redis服務,啟動redis服務,如下圖所示:


執行程式碼,此時報錯如下:

  1. <spanstyle="color:#ff0000;">Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: </span>
  1. <spanstyle="color:#ff0000;">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: 
    </span>
  1. <spanstyle="color:#ff0000;">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. </span>
  1. <spanstyle="color:#ff0000;">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. </span>
  1. <spanstyle="color:#ff0000;">3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. </span>
  1. <spanstyle="color:#ff0000;">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.</span>

上述exception大致意思是:拒絕redis在保護模式下執行的,沒有繫結IP地址,沒有授權密碼,如果你想從外部電腦連線redis的話,你必須要採納以下其中的某一個解決方法

樓主採用的第二種方法,修改redis.conf配置檔案,將protected-mode yes 改為no,如下圖所示


重啟虛擬機器,啟動redis服務,如下圖所示


執行程式碼,控制檯輸出PONG,如下圖所示:

到此,問題解決。

題外話:我有個疑問就是防火牆和redis.conf配置檔案裡已經把IP註釋了,為何會報紅色的錯誤,經過網上查閱資料,發現其他網友也有類似問題,不過大部分人用的紅色報錯的第四種解決辦法,在這裡給出連結

相關推薦

連線虛擬機器ftp

(1)連線報錯:530 Permission denied ,解決參考:http://blog.chinaunix.net/uid-25266990-id-2557040.html    (2)連線報錯:530 Login incorrect , 解決參考:http:/

Oracle資料庫安裝+漢化版PLsql+Oracle外掛,plsql連線Oracle步驟和解決辦法

    從https://download.csdn.net/download/fxiaoyaole/10449523 此連結下載裡面有所資源,資源包括(Oracle兩個資料庫壓縮包win64_11gR2_database_1of2, win64_11gR2_database

gem install redis解決辦法

redis-cluster安裝需要通過gem install redis來安裝相關依賴。否則報錯。通過gem install redis會報如下錯誤1:ERROR:  Loading command: install (LoadError)      cannot load such file -- zlib

Java連線虛擬機器redis問題解決辦法

直奔主題,Java連線虛擬機器報錯,程式碼如下: public class TestPing {public static void main(String[] args) {Jedis jedis = new Jedis("192.168.201.128", 637

gem install redis解決

ubi doc def fault wrapper AR -name post x86 在執行gem install redis時 提示: gem install redis ERROR: Error installing redis:

JMETER java.net.SocketException: Connection reset 解決方案

exception cti 延遲 nec exceptio -- delay log 方案 相關值解析MaxUserPort:最大動態端口數(Default = 5000, Max = 65534)TcpTimedWaitDelay:TCP等待延遲時間(30)TcpNumC

redis解決

1、Connecting to node 127.0.0.17000 [ERR] Sorry, can't connect to node 192.168.1.917000 redis叢集:Connecting to node 127.0.0.1:7000: [ERR] Sorry, can't conne

mybatis解決辦法 :Result Maps collection does not contain value for java.lang.String

錯誤 java.lang.IllegalArgumentException: Result Maps collection does not contain value for java.lang.String at org.apache.ibatis.session.Configura

windows版redis的下載地址以及解決辦法

下載地址:https://github.com/MSOpenTech/redis 用win+R輸入cmd開啟,在到相應的資料夾下面,輸入啟動了命令即可 win下面批量啟動redis程式碼: package com.learn.redis; import java.io.File;

CentOS6.x中vmware workstation 虛擬機器啟動:Could not open /dev/vmmon

最初安裝報錯,但是介面可以開啟,可以正常安裝,但是安裝過後,啟動報錯 Gtk-Message: Failed to load module "canberra-gtk-module": libcanberra-gtk-module.so:cannot open sh

騰訊雲CentOS7安裝mysql各種解決辦法!!以及Navicat連線(服務啟動不了解決辦法

先釋放一下!氣死我了!! 背景: 在雲主機上安裝mysql來來回回重灌了十幾遍,氣得我昨晚還把雲主機的系統重灌了一遍!!!但是並沒有解決根本問題。最終還是今天上午解決了! 我安裝的mysql是5.6 首先說一下我的錯誤步驟!記住一下是錯誤步驟!

VMware虛擬機器啟動,無法執行64位操作

VMware Workstation虛擬機器安裝使用64位作業系統時涉及到一個CPU虛擬化的問題,如果BIOS沒有開啟CPU的虛擬化選項,建立和開啟64位虛擬機器就會報錯 1、安裝了VMware W

java.lang.NoClassDefFoundError: org/apache/commons/collections/FastHashMap解決辦法

在編寫Servlet中實現表單值自動填充的程式中,出現了-500 java.lang.NoClassDefFoundError: org/apache/commons/collections/FastHashMap報錯,究其原因就是在commons-collection-4

java junit測試,註解引入service解決辦法

作為程式設計師,搞後端開發,當然離不開單元測試了。舉個例子,測試下mapper介面,service介面等等。當用到spring容器的時候,在測試類直接寫 如下程式碼: @Autowired private AccountService accountServiceIm

Redis:err max number of clients reached 解決辦法

Redis用一段時間之後會報錯,經過反覆測試和百度、Google之後才發現是redis連線池在關閉專案的時候,需要收回連線池,不然redis在開發的過程中,所有開發人員本地專案連線redis伺服器,經常重啟專案會累積很多不能釋放的連線, 程式碼如下: <bean id="jedisConfig

windows寫的指令碼,ubuntu虛擬機器始終 [Error 2]no such file or directory

切換到Mapping標籤,在Deployment path on server 'test'這一欄的最右側,點選...按鈕,選擇檔案上傳的目標目錄。之後點選Use this server as default,就可以讓這個工程一直預設上傳到這個伺服器的這個目錄,不用多次選擇

虛擬機器登入-bash: /etc/profile: Permission denied

管理員使用者賬號root能正常登陸,但普通使用者登陸時提示報錯: -bash: /etc/profile: Permission denied 出現這個報錯提示的原因:這是/etc目錄許可權問題。在超級管理員root下檢視/etc的許可權,可以看到其他普通使用者是沒有

VirtualBox虛擬機器啟動:fatal:No bootable medium found! System halted

fatal:No bootable medium found! System halted意思是    致命的:沒有啟動中發現!宕機第一 可能是系統未完成安裝就強制關機第二 root使用者操作刪除系統檔案第三 使用習慣不當,應該讓系統正常關機而不是直接點×強制關機原因:就是找

python 鏈接codis 解決辦法 command 'EXEC' is not allowed

command 'exec' is not allowed python redis codis [[email protected]/* */ ceph]# python ../pkg/redisbase.py Traceback (most recent cal

Authentication token manipulation error解決辦法

erro ive 參考 ext .net center tex tps tro Authentication token manipulation error報錯解決辦法 #參考http://blog.163.com/junwu_lb/blog/static/1916798