Windows远程连接Redis(Linux)

文章目录

  • Windows远程连接Redis(Linux)
    • 1、写在前面
    • 2、配置redis.conf
    • 3、启动Redis
      • 3.1 开启redis服务
      • 3.2 启动客户端
      • 3.3 Redis命令
      • 3.4 查看Redis密码
    • 4、关闭Redis
    • 5、Java操作Redis


1、写在前面

  • Windows版本:Windows10
  • Linux版本:Ubuntu Kylin 16.04
  • Redis版本:Redis-3.2.7
  • IDE:IntelliJ IDEA Ultimate2020.2.3
  • Redis:单机部署

2、配置redis.conf

修改redis.conf配置文件

  • 注释掉bind 127.0.0.1这一行,如下图所示:

  • 设置客户端连接的密码requirepass,如下图所示:

  • 官方说明

This should stay commented out for backward compatibility and because most people do not need auth (e.g. they run their own servers).

为了向后兼容性,这(#requirepass foobared)应该被注释掉,因为大多数人不需要身份验证(例如,他们运行自己的服务器)。

此处是个人机器的使用,直接设置即可

  • 关闭保护模式,如下图所示:

  • 官方说明

By default protected mode is enabled. You should disable it only if you are sure you want clients from other hosts to connect to Redis even if no authentication is configured, nor a specific set of interfaces are explicitly listed using the “bind” directive.

Protected mode是一层安全保护,旨在避免访问和利用互联网上打开的 Redis 实例。

当保护模式打开时,如果:
1) 服务器未使用 “bind” 指令显式绑定到一组地址。
2) 未配置密码。

  • 服务器仅接受来自从IPv4 和 IPv6 环回地址 127.0.0.1 和 ::1,以及来自 Unix 域套接字。

默认情况下,保护模式处于启用状态。仅当您确定希望其他主机的客户端连接到 Redis 时,才应禁用它,即使未配置身份验证,也没有使用bind指令显式列出一组特定的接口。

3、启动Redis

3.1 开启redis服务

需要指定redis.conf的文件位置

zhangsan@node01:/usr/local/redis-3.2.7$ src/redis-server ./redis.conf

后台启动设置daemonize no 改成 yes

3.2 启动客户端

启动客户端,在命令行指定Redis主机地址、认证密码,端口号默认是6379,可以不用指定

--raw参数是防止中文乱码,对Redis操作的结果使用raw格式(当 STDOUT 不是 tty 时为默认值)。

zhangsan@node01:/usr/local/redis-3.2.7$ src/redis-cli -h 192.168.132.10 -a password --raw

3.3 Redis命令

zhangsan@node01:/usr/local/redis-3.2.7$ src/redis-cli --help
redis-cli 3.2.7Usage: redis-cli [OPTIONS] [cmd [arg [arg ...]]]-h <hostname>      Server hostname (default: 127.0.0.1).-p <port>          Server port (default: 6379).-s <socket>        Server socket (overrides hostname and port).-a <password>      Password to use when connecting to the server.-r <repeat>        Execute specified command N times.-i <interval>      When -r is used, waits <interval> seconds per command.It is possible to specify sub-second times like -i 0.1.-n <db>            Database number.-x                 Read last argument from STDIN.-d <delimiter>     Multi-bulk delimiter in for raw formatting (default: \n).-c                 Enable cluster mode (follow -ASK and -MOVED redirections).--raw              Use raw formatting for replies (default when STDOUT isnot a tty).--no-raw           Force formatted output even when STDOUT is not a tty.--csv              Output in CSV format.--stat             Print rolling stats about server: mem, clients, ...--latency          Enter a special mode continuously sampling latency.--latency-history  Like --latency but tracking latency changes over time.Default time interval is 15 sec. Change it using -i.--latency-dist     Shows latency as a spectrum, requires xterm 256 colors.Default time interval is 1 sec. Change it using -i.--lru-test <keys>  Simulate a cache workload with an 80-20 distribution.--slave            Simulate a slave showing commands received from the master.--rdb <filename>   Transfer an RDB dump from remote server to local file.--pipe             Transfer raw Redis protocol from stdin to server.--pipe-timeout <n> In --pipe mode, abort with error if after sending all data.no reply is received within <n> seconds.Default timeout: 30. Use 0 to wait forever.--bigkeys          Sample Redis keys looking for big keys.--scan             List all keys using the SCAN command.--pattern <pat>    Useful with --scan to specify a SCAN pattern.--intrinsic-latency <sec> Run a test to measure intrinsic system latency.The test will run for the specified amount of seconds.--eval <file>      Send an EVAL command using the Lua script at <file>.--ldb              Used with --eval enable the Redis Lua debugger.--ldb-sync-mode    Like --ldb but uses the synchronous Lua debugger, inthis mode the server is blocked and script changes areare not rolled back from the server memory.--help             Output this help and exit.--version          Output version and exit.

3.4 查看Redis密码

  • 查看认证密码
config get requirepass
  • 修改认证密码
config set requirepass 123456 #设置redis密码

4、关闭Redis

192.168.132.10:6379> SHUTDOWN
not connected>

5、Java操作Redis

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;import java.util.*;public class RedisDemo {private static String HOST = "192.168.132.10";private static int PORT = 6379;private static String PWD = "password";private static Jedis jedis = null;private static JedisPool jedisPool = null;public static void main(String[] args) {// 1. 创建Jedis对象(两个都可以)
//        jedis = new Jedis(HOST, PORT);init();// 2. 测试String res = jedis.ping();
//        System.out.println(res);}/*** TODO 获取Jedis实例*/public synchronized static Jedis getJedis() {try {if (jedisPool != null) {Jedis resource = jedisPool.getResource();return resource;} else {return null;}} catch (Exception e) {e.printStackTrace();return null;}}/*** TODO 释放资源*/public static void returnResource(final Jedis jedis) {if (jedis != null) {
//            jedisPool.returnResource(jedis);jedis.close();jedisPool.close();}}/*** TODO 初始化Redis连接池*/public static void init() {if (jedis == null) {jedis = new Jedis(HOST, PORT);jedis.auth(PWD);}if (jedis != null) {System.out.println("Redis连接成功");} else {System.out.println("Redis连接失败");}}

结束!

Windows远程连接Redis(Linux)相关推荐

  1. Windows远程连接Redis服务器

    Windows远程连接Redis服务器 本地安装Redis 找到Redis并启动Redis,放着不用动,千万别关 打开命令行(cmd),移动到Redis的Redis-cli位置(就是你启动server ...

  2. tightvnc实现windows远程连接控制linux主机

    一.安装tightvnc: tightvnc的安装在安装包中有详细的说明(README文件) 首先你要确保linux已经安装jpeg和zlib库, 2.编译 执行如下两个命令: [root@local ...

  3. windows远程连接redis

    1.WIN+R,CMD 2. 进入redis安装目录 3. 运行:redis-cli.exe -h ip -p port auth pass / edis-cli.exe -h ip -p port ...

  4. Windows使用ssh协议远程连接ubuntu linux子系统

    Windows使用ssh协议远程连接ubuntu linux子系统 一.Windows远程连接ubuntu linux子系统 二.开启ubuntu ssh服务 三.获取ubuntu子系统的ip地址 四 ...

  5. Linux安装Redis、远程连接Redis

    Linux安装Redis.远程连接Redis Redis官方tar包下载地址 Linxu安装Redis 1.新建redis安装目录 2.上传文件到服务器的安装目录 3.解压tar包 4.安装gcc环境 ...

  6. windows下使用vnc viewer远程连接redhat Linux桌面

    在windows下使用vnc viewer远程连接 redhat Linux桌面,主要配置步骤: 一. 首先是 redhat Linux桌面配置vnc server 1. 查看vnc工具包是否安装 y ...

  7. linux远程连接redis的步骤

    远程连接redis两个步骤: 1.redis-cli -h 连接地址 -p 端口 例如:redis-cli -h r-12345678.redis.rds.aliyuncs.com -p 6379 2 ...

  8. 远程连接Kali Linux使用PuTTY实现SSH远程连接

    远程连接Kali Linux使用PuTTY实现SSH远程连接 本书主要以在Android设备上安装的Kali Linux操作系统为主,介绍基于Bash Shell渗透测试.由于在默认情况下,在Andr ...

  9. windows远程登录 ubuntu Linux 系统及互连共享桌面

    预备工作 #开启防火墙端口 sudo ufw allow 3389 #安装ssh sudo apt-get install openssh-server 一.windows直连Ubuntu16.04共 ...

最新文章

  1. Win10系列:JavaScript访问文件和文件夹
  2. 计算机软件uml,计算机软件——UML旅游管理系统
  3. react开发心路历程
  4. Python编程基础:第二十九节 异常Exception
  5. 亚马逊部分 AWS DNS 系统遭 DDoS 攻击,已达数小时之久
  6. python中所有保留字首字母都是小写_int是不是python的保留字
  7. linux系统中防止系统时间,设置系统时间与在Linux中
  8. 动态数组vector
  9. 主定理(master theorem)学习小记
  10. 【转】一、用于VS2019的QT配置
  11. 【CodeForces - 1096D】Easy Problem(dp,思维)
  12. 这几张图告诉你程序员的变化,最后一张图扎心了
  13. 【实践】网易云音乐推荐中用户行为序列深度建模.pdf(附下载链接)
  14. javaweb简单的登录增删改查系统_国产化之路统信UOS /Nginx /Asp.Net Core+ EF Core 3.1/达梦DM8实现简单增删改查操作...
  15. 4.dialog 工具
  16. 花花省V5淘宝客APP源码无加密社交电商自营商城系统带抖音接口
  17. 《小样本学习研究综述》赵凯琳等 Survey on Few-shot Learning,文献阅读笔记
  18. linux syn_recv过多ip,SYN_RECV处理方案
  19. 《非常网管:网络管理从入门到精通(修订版)》一1.1 计算机网络基础
  20. HUAWEI 机试题:工厂流水线调度

热门文章

  1. Jenkins远程执行Windows命令
  2. 如何将CAD文件批量转成PDF格式?转换软件快捷处理
  3. c++11中emplace_back vs push_back
  4. Cannot resolve overloaded method ‘createDataFrame‘
  5. java计算机毕业设计菲特尼斯健身管理系统设计与实现MyBatis+系统+LW文档+源码+调试部署
  6. Go C 编程 第9课 放飞汽球(魔法学院的奇幻之旅 Go C编程绘图)
  7. 天融信 LINUX客户端 CENTOS版安装
  8. 国内外常用NTP公共时间同步服务器
  9. SideFX Houdini FX 18.0.416 Win安装出现许可显示灰度
  10. 关于SAP 打印时 特殊字符的输出