1. 程式人生 > >通過Jedis客戶端連線不到redis(二)

通過Jedis客戶端連線不到redis(二)

之前我的一篇文章,也是解決Jedis連線不到redis的,但是情況不一樣,之前的問題主要是防火牆的問題,但是現在看來並不是防火牆的問題,因為redis自身也有配置來限制外網的訪問,所以當時也不知道為什麼就可以了,今天主要以redis配置的角度來看一下,如何解決外網訪問redis的問題。

首先還是描述一下問題:

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

上面是測試程式碼,下面是報錯資訊:
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect
	at redis.clients.jedis.Connection.connect(Connection.java:207)
	at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
	at redis.clients.jedis.Connection.sendCommand(Connection.java:126)
	at redis.clients.jedis.Connection.sendCommand(Connection.java:121)
	at redis.clients.jedis.BinaryClient.ping(BinaryClient.java:106)
	at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:195)
	at com.atguigu.redis.test.TestPing.main(TestPing.java:10)
Caused by: java.net.ConnectException: Connection refused: connect
	at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
	at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
	at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
	at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
	at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
	at java.net.PlainSocketImpl.connect(Unknown Source)
	at java.net.SocksSocketImpl.connect(Unknown Source)
	at java.net.Socket.connect(Unknown Source)
	at redis.clients.jedis.Connection.connect(Connection.java:184)
	... 6 more

首先,通過檢視linux的防火牆,看看是否是防火牆搞的鬼:
[[email protected] ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

結果是這樣的,inactive是不活動的意思,和active相反,這個比較好理解。

然後使用windows的telnet來試一下,上一篇關於遠端連線redis的文章中沒有關於telnet的資訊,這次不上,

C:\Users\Administrator>telnet 192.168.1.118 6379

結果當然也是連不上了,然後就只能請教萬能的百度大哥了:
原來是redis預設只能localhost登入,所以需要開啟遠端登入。解決方法如下:

  在redis的配置檔案redis.conf中,找到bind localhost註釋掉。

    註釋掉本機,區域網內的所有計算機都能訪問。

    band localhost   只能本機訪問,區域網內計算機不能訪問。

    bind  區域網IP    只能區域網內IP的機器訪問, 本地localhost都無法訪問。

上面是從別的地方找到的內容,雖然不是很具體,但是指明瞭方向,那就是redis.conf,所以
################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1
bind 192.168.1.118

# 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:
#

上面是redis.conf中的內容
bind 192.168.1.118
是我後來新增的,也就是加了這句話之後,才可以正常的訪問了。
public static void main(String[] args) {
		Jedis jedis = new Jedis("192.168.1.118", 6379);
		System.out.println(jedis);
		String ping = jedis.ping();
		System.out.println(ping);
	}

[email protected]
PONG


相關推薦

通過Jedis客戶連線redis

之前我的一篇文章,也是解決Jedis連線不到redis的,但是情況不一樣,之前的問題主要是防火牆的問題,但是現在看來並不是防火牆的問題,因為redis自身也有配置來限制外網的訪問,所以當時也不知道為什麼就可以了,今天主要以redis配置的角度來看一下,如何解決外網訪問red

配置客戶連線遠端資料庫oracle

在使用者輸入sqlplus system/[email protected]後,sqlplus程式會自動到sqlnet.ora檔案中找NAMES.DEFAULT_DOMAIN引數,假如該引數存在,則將該引數中的值取出,加到網路服務名的後面,即此例中你的輸入由sqlplus system/[email

c/s客戶---功能測試點

1、視訊(併發最愛有bug) 視窗關係(有依附關係的,是否關大的小的也關) 併發:過程中各種操作(錄製過程中點選按鈕、錄製過程中關閉大視窗、收聽時點選其他人、歷史記錄中播放過程中點選其他聯絡人、歷史記錄中播放過程中在點選播放、歷史記錄中播放過程中關閉歷史記錄、錄製中換賬號)

以太坊go-ethereum客戶查詢交易列表

玩過比特幣的朋友都知道,比特幣是可以通過api(listtransactions)查詢指定地址的歷史交易的。但在eth中沒有提供類似的查詢api。今天這篇部落格就簡單介紹一下如果解決這個問題。 問題 以太坊go-ethereum客戶端是沒有根據地址查詢交

使用jedis客戶連線redis,單機版和叢集版

單機版 1.入門例項 @Test public void testJedis(){ //建立一個jedis物件,需要指定服務的ip和埠號 Jedis jedis=new Jedis("192.168.25.11",

jedis客戶連線redis錯誤總結

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

如何解決客戶連線上Linux上的redis的問題

第一步:檢視你的redis 伺服器是否開啟 ps -ef |grep -i redis第二部:檢查你的redis.conf 檔案是否有問題        如繫結的ip是否註釋        6379埠是否開啟        保護模式是否解除        等等.......這

客戶連線上kafka的問題以及kafka總是自動關閉問題

客戶端連線不上kafka的問題 java使用客戶端測試連線kafka:https://blog.csdn.net/Lnho2015/article/details/51353936 以下問題是基於kafka所在伺服器跟開發環境不在一臺機器上 1.把listeners和adver

Sql2008 配置遠端連線客戶連線上的解決方法

將"客戶端協議"的"TCP/IP"也修改為“Enabled” 配置完成,重新啟動SQL Server 2008。此時應該可以使用了,但是還是要確認一下防火牆。開啟防火牆設定。將SQLServr.exe(C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEX

關於VMware ESX Server客戶連線上等問題的解決

crond (pid 9701) is running... Chain INPUT (policy ACCEPT 9169 packets, 4606K bytes)  pkts bytes target     prot opt in     out     source               

通過java客戶連線hbase 注意事項

1、通過java客戶端連線hbase,其中hbase通過zookeeper去管理,需要注意的是客戶端埠。      通過在瀏覽器端輸入地址檢視:http://192.168.3.206:60010/m

Zookeeper之Zookeeper底層客戶架構實現原理轉載

一次 描述 綁定 機制 一個 ini fin 源碼 receive Zookeeper的Client直接與用戶打交道,是我們使用Zookeeper的interface。了解ZK Client的結構和工作原理有利於我們合理的使用ZK,並能在使用中更早的發現問題。本文將在研究源

EXCHANGE客戶訪問服務器CAS中的身份驗證方式

傳輸 郵箱服務器角色 找到 輸入 驗證 管理器 orm 虛擬 code 在部署完畢exchange後系統會自動建立IIS服務來響應相應的請求。客戶端訪問服務器(以下簡稱CAS)實質上是一臺IIS服務器,在服務器中部署一套名為“Default web site”的站點來完成O

SpringCloud——客戶負載平衡器Ribbon

一、Ribbon簡介         Ribbon是一個客戶端負載均衡器,它可以很好地控制HTTP和TCP客戶端的行為。        Ribbon中的中心概念是指定客戶端的概念。每個負載平衡器是組合的組合的一部分,它們一起工作以根據需要聯絡遠端伺服器,並且集合具有您將其

express+mysql+vue專案入門-express服務連線mysql資料庫

 express+mysql+vue專案入門-express服務端連線mysql資料庫,此方法mysql為例:新增一個mysql連線模組並匯出,在服務端入口匯入使用即可 var mysql = req

Zookeeper的java客戶API使用方法

前面幾篇博文,我們簡單的介紹了一下zookeeper,如何安裝zookeeper叢集,以及如何使用命令列等。這篇博文我們重點來看下Zookeeper的java客戶端API使用方式。 建立會話 客戶端可以通過建立一個Zookeeper(org.apache

oracle 10g 學習之客戶安裝和配置2

概述 Oracle 資料庫是一種網路上的資料庫, 它在網路上支援多使用者, 支援伺服器/客戶機等部署(或配置) 伺服器與客戶機是軟體概念, 它們與計算機硬體不存在一一對應的關係. 即: 同一臺計算機既可以充當伺服器又可以充當客戶機, 或者, 一臺計算機只充當伺服器或只充當充當客戶機. Oracle 資料庫

猿題庫iOS客戶的技術細節:基於CoreText的排版引擎

來自:http://blog.devtang.com/blog/2013/10/21/the-tech-detail-of-ape-client-3/ 前言 本人今年主要在負責猿題庫iOS客戶端的開發,本文旨在通過分享猿題庫iOS客戶端開發過程中的技術細節

Android客戶效能測試—記憶體

前言: 1.該內容為APP應用客戶端的效能測試,未涉及後臺,所以並非針對API或資料介面 2.測試的目標項:資源消耗、記憶體洩露、電量功耗、響應時間 3.客戶端的效能指標:記憶體、CPU、流量 4.本系列主要是講述 如何獲取安卓APP應用的效能指標,並簡單分析,定

《SSH客戶實現和LinuxCentos共享檔案以及批量管理》

①lrzsz 在linux裡可代替ftp上傳和下載。 a.安裝lrzsz: b.在SecureCRT中設定上傳下載路徑: ②rz命令:  rz命令本地上傳檔案到伺服器: -y:覆蓋已有檔案