今天使用jedis客户端api连接远程连接redis的时候,一直报错,如下: 

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

  原来是redis默认只能localhost登录,所以需要开启远程登录。解决方法如下:

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

    注释掉本机,局域网内的所有计算机都能访问。

    band localhost   只能本机访问,局域网内计算机不能访问。

    bind  局域网IP    只能局域网内IP的机器访问, 本地localhost都无法访问。

  验证方法:

  [root@mch ~]# ps -ef | grep redis
  root : ? :: /usr/local/bin/redis-server *:

  /usr/local/bin/redis-server *:6379 中通过"*"就可以看出此时是允许所有的ip连接登录到这台redis服务上。

  注意事项:

  今天再设置远程访问的时候,在启动Redis的时候报错:Creating Server TCP listening socket *:6379: unable to bind socket(Redis一定不能设置成后台运行,否则终端不会有任何错误显示)。

  上网搜索说各种原因的都有,有的说是Redis版本的bug(我用的版本是3.2.0),我是参考以下几篇文章解决了这个问题:

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

  http://blog.csdn.net/qq_25797077/article/details/51986455

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

  我没有注释掉bind 127.0.0.1,而是将bind 127.0.0.1 改成了bind 0.0.0.0。

  参考文章:

      1.http://www.oschina.net/question/579073_113004?fromerr=YBv8RRYl

Redis开启远程登录连接。的更多相关文章

  1. Redis开启远程登录连接

    Redis 安装详见 http://www.cnblogs.com/zendwang/p/6560628.html 当前安装测试版本:Redis 3.2.8 默认安装完毕Redis只能本机访问 [ro ...

  2. 如何开启远程桌面连接功能?windows的远程桌面连接功能使用步骤

    由于远程桌面的诞生,为电脑工作者提供了极大的便利.首先,推荐1款比较适合服务器管理的远程桌面: 可以管理1000+服务器/vps的远程桌面:IIS7远程桌面管理 开启远程桌面功能步骤: 1.右键点击电 ...

  3. mysql8数据库修改root密码,以及创建用户遇到的坑,开启远程登录,用navicat进行mysql的远程连接,mysql8.0默认编码方式,部分参数配置查询命令

    yum 安装MySQL8 echo "删除系统默认或之前可能安装的其他版本的 mysql" for i in $(rpm -qa|grep mysql);do rpm -e $i ...

  4. 开启远程桌面连接windows的方法以及遇到的问题

    确认电脑的远程服务是否已经开启 开始--运行--输入“services.msc ”,打开服务,找到三个remote desktop开头的服务 Remote Desktop Configuration. ...

  5. ssh远程登录连接慢的解决方法

    近期在搭建自动化集群服务,写脚本ssh批量分发公钥至其它服务器时比较缓慢,便在度娘上寻找解决方法如下: 方法一: 以ssh -v 调试模式远程登录: [root@bqh-nfs- ceshi]# ss ...

  6. mysql用户修改登录密码及开启远程登录

    一.修改用户登录密码: mysql> show databases;ERROR 1820 (HY000): You must SET PASSWORD before executing this ...

  7. Ubuntu 开启远程登录 SSH 的安装和配置

    SSH 为 SecureShell 的缩写,由 IETF 的网络工作小组(NetworkWorkingGroup)所制定:SSH 是一种安全协议,主要用于给远程登录会话数据进行加密,保证数据传输的安全 ...

  8. centos7下mysql 开启远程登录

    安装mysql 安装mysql就不做过多的介绍了,相信小伙伴们都可以很轻松的安装 进入mysql命令行 mysql -u用户名 -p密码 新建远程登录的用户 grant all on *.* to a ...

  9. CentOS6安装MySQL开启远程登录

    Centos6安装MySQL 检测下系统有没有自带的mysql:yum list installed | grep mysql 如果已经有的话执行命令 yum -y remove mysql-libs ...

随机推荐

  1. pyqt样式表语法笔记(中)--原创

    pyqt样式表语法笔记(中) pyqt QSS python 样式表 一.弹窗 在日常的各种桌面软件的使用中,我们都会碰到弹窗.例如注册,登录的时候,会有相应的信息弹窗,这里就以信息收集弹窗为例进行弹 ...

  2. 通用数据库帮助类DBHelper(含log日志信息实时记录)

    项目需要,需要一个通用的数据库操作类,增删改查.事务.存储过程.日志记录都要有,于是在已有的帮助类上做了一些改进,并将log4j的.NET版--log4net嵌入其中记录sql的执行环境和状态. 用起 ...

  3. SystemClock官方简介

    public final class SystemClock extends Object java.lang.Object    ↳ android.os.SystemClock Class Ove ...

  4. js的apply()与call()的区别

    1.各自对应的不同的语法: /*apply()方法*/ function.apply(thisObj[, argArray]) /*call()方法*/ function.call(thisObj[, ...

  5. setTimeout 和 setInteval 的区别。

    学习前端的可能都知道js有2个定时器setTimeOut和setinteval.用的时候可能不是很在意,但是2者还是有区别的 setTimeout方法是定时程序,也就是在什么时间以后干什么.干完就完了 ...

  6. js继承之原型链方式实现

    温故而知新: 在之前的文章已经重点了解了原型对象,今天就理一理这个原型对象在原型链式的继承中的使用 function a(x,y){this.x=x;this.y=y;} //定义一个函数,当构造函数 ...

  7. Mac下安装BeautifulSoup

    1.输入命令su,输入root密码,进入root用户 2.执行命令安装pip: sudo easy_install pip 详细pip介绍:http://blog.csdn.net/olanlanxi ...

  8. ubuntu12.04.5安装openssh-server所引发的血案

    刚安装好的ubuntu12.04.5在安装openssh-server之后,安装其他软件都安装不了,如下: root@ubuntu:/home/lancer/software/ssh# apt-get ...

  9. Css清除浮动最优方式之一

    ---恢复内容开始--- .container:before, .container:after { display: table; content: " "; } .contai ...

  10. 秒懂JS对象、构造器函数和原型对象之间的关系

    学习JS的过程中,想要掌握面向对象的程序设计风格,对象模型(原型和继承)是其中的重点和难点,拜读了各类经典书籍和各位前辈的技术文章,感觉都太过高深,花费了不少时间才搞明白(个人智商是硬伤/(ㄒoㄒ)/ ...