zoukankan      html  css  js  c++  java
  • redis 远程 访问 安全配置

    朋友总结很好,就转载了-> 站长博客

    假设两台redis服务器,ip分别为:192.168.1.101和192.168.1.103,如果在101上通过redis-cli访问103上的redis呢?
    在远程连接103直线,先讲下redis-cli的几个关键参数:
     
    用法:redis-cli [OPTIONS] [cmd [arg [arg ...]]]
     
    -h <主机ip>,默认是127.0.0.1
    -p <端口>,默认是6379
    -a <密码>,如果redis加锁,需要传递密码
    --help,显示帮助信息
     
    通过对rendis-cli用法介绍,在101上连接103应该很简单:
     
    [root@xsf001 ~]# redis-cli -h 192.168.1.103 -p 6379  
    redis 192.168.1.103:6379>   
     在101上对103设置个个string值 user.1.name=zhangsan
     
    redis 192.168.1.103:6379> set user.1.name zhangsan  
    OK  
            看到ok,表明设置成功了。然后直接在103上登陆,看能不能获取到这个值。
     
    [root@xsf003 utils]# redis-cli   
    redis 127.0.0.1:6379> get user.1.name  
    "zhangsan"  
            木错吧,确实是zhangsan,这说明101上连的是103上的redis服务器。当然能够成功连接103是有基本条件的,101上可以喝103上的6379端口通信。
    人人都可以连接redis服务器是很危险的,我们需要给103上的redis设置个密码,怎么设置呢,需要编辑redis的配置文件/etc/redis/6379.conf
     
    [root@xsf003 utils]# vim /etc/redis/6379.conf   
     
          找到# requirepass foobared 去掉前面的注释#,并把foobared 替换为你自己的密码:hi, coder 
     
    requirepass "hi, coder"  
     保存配置文件之后,重启redis服务
     
    [root@xsf003 utils]# /etc/init.d/redis_6379 stop  
    Stopping ...  
    Waiting for Redis to shutdown ...  
    Redis stopped  
    [root@xsf003 utils]# /etc/init.d/redis_6379 start  
    Starting Redis server...  
     101上重新连接103并获取user.1.name的值
     
    [root@xsf001 ~]# redis-cli -h 192.168.1.103 -p 6379  
    redis 192.168.1.103:6379> get user.1.name  
    (error) ERR operation not permitted  
    redis 192.168.1.103:6379>   
            为什么是error呢,当然是因为连接103时没传递密码了,退出重新连
     
    redis 192.168.1.103:6379> quit  
    [root@xsf001 ~]# redis-cli -h 192.168.1.103 -p 6379 -a "hi, coder"  
    redis 192.168.1.103:6379> get user.1.name  
    "zhangsan"  
     
             看到zhangsan,说明你已经连接成功了。
  • 相关阅读:
    论文翻译:2020_DARCN_A Recursive Network with Dynamic Attention for Monaural Speech Enhancement
    论文翻译:2020_demucs_Real Time Speech Enhancement in the Waveform Domain
    论文翻译:2021_A Perceptually Motivated Approach for Lowcomplexity, Realtime Enhancement of Fullband Speech
    tomcat架构分析及配置详解
    深入了解SpringMVC源码解析
    Spring MVC高级应用
    Nginx应用场景配置
    SpringSecurity基础场景应用大全
    SpringBoot基础应用
    Spring MVC应用
  • 原文地址:https://www.cnblogs.com/qunshu/p/3187677.html
Copyright © 2011-2022 走看看