本地Redis服务配置

要求:在虚拟机中启动redis服务,并要在windows物理机上取得链接

  • 虚拟机安装略,(结果如下)

windows工作机上装了Oracle VM VirtualBox,并在其中装好了linux系统,

linux系统版本如下:

# uname -a
Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
# ip addr 【查看虚拟机ip,其中(10.10.12.18)为本虚拟机ip】
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:a8:1c:bd brd ff:ff:ff:ff:ff:ff
inet 10.10.12.18/24 brd 10.10.12.255 scope global dynamic enp0s3
valid_lft 77192sec preferred_lft 77192sec
inet6 fe80::a00:27ff:fea8:1cbd/64 scope link
valid_lft forever preferred_lft forever

windows中ping测试成功

C:\Users\hdb>ping 10.10.12.18

正在 Ping 10.10.12.18 具有 32 字节的数据:
来自 10.10.12.18 的回复: 字节=32 时间<1ms TTL=64
来自 10.10.12.18 的回复: 字节=32 时间<1ms TTL=64
来自 10.10.12.18 的回复: 字节=32 时间<1ms TTL=64
来自 10.10.12.18 的回复: 字节=32 时间=1ms TTL=64 10.10.12.18 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 1ms,平均 = 0ms

接下来问题来了,redis启动后,可以在linux中进行增删改查,但是外部windows无法取得链接

测试代码如下

public static void main(String[] args) {
@SuppressWarnings("resource")
Jedis jedis = new Jedis("10.10.12.18", 6379);
System.out.println(jedis.ping());
} 日志如下
/*
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.conf文件中 ,注释掉:bind 127.0.0.1
  • 在redis.conf文件中 ,把 protected-mode = yes 更改为 protected-mode = no

重启redis后,java测试代码运行成功($ src/redis-server redis.conf , 该命令可以确保更新的配置参数可以立即生效);

补充:redis默认端口6379 , 要保证linux对外开放了该端口,外部才能访问。我的虚拟机刚好默认关闭了防火墙,所以上面操作没有涉及开关防火墙或者开放指定端口的记录。

本地Redis服务配置的更多相关文章

  1. 在linux安装redis单机和集群后,如何在windows上使用redis客户端或者java代码访问错误的原因很简单,就是没有连接上redis服务,由于redis采用的安全策略,默认会只准许本地访问。需要通过简单配置,完成允许外网访问。

    这几天在学习在linux上搭建服务器的工作,可谓历经艰辛.可喜最后收获也不少. 这次是在linux上搭建redis服务器后从windows上缺无法访问,连接不上. 仔细回忆以前搭建nginx和ftp的 ...

  2. Window环境下配置Redis服务的方法及查看缓存数据的工具介绍

    工具下载位置:http://pan.baidu.com/s/1hqVh1f2,包括服务端配置以及查看缓存的工具. 服务端是以服务的形式运行,将Redis服务端解压到某个目录,然后执行cmd执行命令: ...

  3. Ubuntu 17.10 用 apt 搭建 lamp 环境、安装 phpmyadmin、redis 服务+扩展、mysql 扩展、开启错误提示、配置虚拟主机

    2018-02-24 13:50:30 更新: 个人喜欢相对原生又不太麻烦,所以用 apt 构建环境.不过,最近使用到现在记得出现过了 3 次 apache 或 mysql 服务器无法启动或无法连接的 ...

  4. 阿里云服务上面部署redis + 本地Redis客户端连接方法

    本文结合自己在阿里云服务器上面搭建redis服务器,在本地redis的客户端Redis Desktop Manager连接成功的操作,将操作中的一些方法做了一些归纳和总结,希望可以帮到有需要的同学. ...

  5. 阿里云服务器ecs配置之安装redis服务

    一.介绍 Redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统.和Memcache类似,但很大程度补偿了Memcache的不足,它支持存储的value类型相对更多,包括st ...

  6. windows 本地链接 VMware虚拟机 redis服务

    使用本地Windows链接 VMware虚拟机 redis服务 我用的虚拟机系统是:windows Server 2012 先把Redis服务器拷贝到服务器并解压,目录如下 这里仅仅作为演示,所以就不 ...

  7. 【转载】Windows安装Redis并添加本地自启动服务

    概况 在windows本地搭建redis缓存,添加到本地计算机的服务中,保证每次开机自动启动服务. 第一步:下载redis(我的是计算机win10,64位) https://github.com/Mi ...

  8. redis服务及其配置与应用(window 环境下)

    一.redis简介:Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API(源自百度百科),个人更喜欢下面的解释:我们 ...

  9. Windows安装Redis并添加本地自启动服务

    概况 在windows本地搭建redis缓存,添加到本地计算机的服务中,保证每次开机自动启动服务. 第一步:下载redis(我的是计算机win10,64位) https://github.com/Mi ...

随机推荐

  1. MySql的数据导入到Sql Server数据库中

    步骤一:安装MySql驱动 驱动下载链接:https://dev.mysql.com/downloads/connector/odbc/ 下载完成后安装, 一路Next即可 步骤二:创建DSN DSN ...

  2. 使用EA画流程图

    https://www.sparxsystems.com.au/enterprise_architect_user_guide/13.0/model_domains/flow_chart.html

  3. vscode git 提交数据到分支

        1.vscode菜单--终端--新建终端   git config --global user.name "your name"   git config --global ...

  4. 尝试使用 Visual Studio Online (Cloud IDE)

    这里的 Visual Studio Online 不是 Azure DevOps ,他们虽然是相同的名称,却是不同的域名 https://online.visualstudio.com/ ,今天我们就 ...

  5. 六 一些常用类:Random、BigInteger、BigDecimal、DecimalFormat

    常用类:

  6. 容器STL

    一.迭代器iterator 迭代器是容器的一种遍历方式,每种容器都定义了自己的迭代器类型 声明一个迭代器: 容器名称<数据类型>::iterator 迭代器名称 vector<int ...

  7. NO28 第四关考试题

    第4章 第4周课前测试考试题 4.1 定时任务规则的含义01 第1题 如果在某用户的crontab文件中有以下记录,该行中的命令多久执行一次(RHCE考试题)?(  ) 30 4 * * 3 mycm ...

  8. greenplum 存储过程 返回结果集多列和单列

    参考: http://francs3.blog.163.com/blog/static/4057672720125231223786/

  9. P1076 Wifi密码

    P1076 Wifi密码 转跳点:

  10. XtraReport1添加参数

    解决了在report有个BeforePrint事件这里面直接 C# code   ? 1 string year = this.Parameters["year"].Value.T ...