• 【redis的链接】redis的两种连接方法


    执行redis-server /etc/redis.conf开启服务

    方法一:
    [root@zhangmeng ~]# redis-cli
    127.0.0.1:6379> 
    127.0.0.1:6379> quit 

    方法二:

    [root@zhangmeng ~]# telnet 192.168.2.42 6379
    -bash: telnet: command not found
    [root@zhangmeng ~]# 

    提示telnet命令不存在,安装telnet

    [root@zhangmeng ~]# yum -y install telnet*
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.cn99.com
     * extras: mirrors.cn99.com
     * updates: mirrors.cn99.com
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package telnet.x86_64 1:0.17-48.el6 will be installed
    ---> Package telnet-server.x86_64 1:0.17-48.el6 will be installed
    --> Processing Dependency: xinetd for package: 1:telnet-server-0.17-48.el6.x86_64
    --> Running transaction check
    ---> Package xinetd.x86_64 2:2.3.14-40.el6 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ==================================================================================================================
     Package                       Arch                   Version                          Repository            Size
    ==================================================================================================================
    Installing:
     telnet                        x86_64                 1:0.17-48.el6                    base                  58 k
     telnet-server                 x86_64                 1:0.17-48.el6                    base                  37 k
    Installing for dependencies:
     xinetd                        x86_64                 2:2.3.14-40.el6                  base                 122 k
    
    Transaction Summary
    ==================================================================================================================
    Install       3 Package(s)
    
    Total download size: 217 k
    Installed size: 423 k
    Downloading Packages:
    (1/3): telnet-0.17-48.el6.x86_64.rpm                                                       |  58 kB     00:00     
    (2/3): telnet-server-0.17-48.el6.x86_64.rpm                                                |  37 kB     00:00     
    (3/3): xinetd-2.3.14-40.el6.x86_64.rpm                                                     | 122 kB     00:00     
    ------------------------------------------------------------------------------------------------------------------
    Total                                                                             863 kB/s | 217 kB     00:00     
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Installing : 2:xinetd-2.3.14-40.el6.x86_64                                                                  1/3 
      Installing : 1:telnet-server-0.17-48.el6.x86_64                                                             2/3 
      Installing : 1:telnet-0.17-48.el6.x86_64                                                                    3/3 
      Verifying  : 1:telnet-server-0.17-48.el6.x86_64                                                             1/3 
      Verifying  : 1:telnet-0.17-48.el6.x86_64                                                                    2/3 
      Verifying  : 2:xinetd-2.3.14-40.el6.x86_64                                                                  3/3 
    
    Installed:
      telnet.x86_64 1:0.17-48.el6                          telnet-server.x86_64 1:0.17-48.el6                         
    
    Dependency Installed:
      xinetd.x86_64 2:2.3.14-40.el6                                                                                   
    
    Complete!

    再次连接,还是不行

    [root@zhangmeng ~]# telnet 192.168.2.42 6379
    Trying 192.168.2.42...
    telnet: connect to address 192.168.2.42: Connection refused

    查看23号端口是关闭的

    [root@zhangmeng ~]#  netstat -tnl |grep 23

    把telnet打开(disable从yes改为no)

    [root@zhangmeng ~]# cat /etc/xinetd.d/telnet 
    # default: on
    # description: The telnet server serves telnet sessions; it uses 
    #    unencrypted username/password pairs for authentication.
    service telnet
    {
        flags        = REUSE
        socket_type    = stream        
        wait        = no
        user        = root
        server        = /usr/sbin/in.telnetd
        log_on_failure    += USERID
        disable        = no
    }

    重启xinetd服务

    [root@zhangmeng ~]# service xinetd restart
    Stopping xinetd:                                           [  OK  ]
    Starting xinetd:                                           [  OK  ]

    再次查看telnet服务开启的

    [root@zhangmeng ~]#  netstat -tnl |grep 23
    tcp        0      0 :::23                       :::*                        LISTEN      

    再次连接(不加端口),可以访问(如果输入错误无法退出可用ctrl+】,会强制退出到telnet命令行,再输入quit退出即可)

    [root@zhangmeng ~]# telnet 192.168.2.42 
    Trying 192.168.2.42...
    Connected to 192.168.2.42.
    Escape character is '^]'.
    CentOS release 6.4 (Final)
    Kernel 2.6.32-358.el6.x86_64 on an x86_64
    login: root
    Password: 
    Login incorrect 

    用root用户无法直接登录,新建普通用户tom,以tom账号登录,再切换到root用户

    [root@zhangmeng ~]# useradd tom
    -bash: password: command not found
    [root@zhangmeng ~]# passwd tom
    Changing password for user tom.
    New password: 
    BAD PASSWORD: it is too simplistic/systematic
    BAD PASSWORD: is too simple
    Retype new password: 
    passwd: all authentication tokens updated successfully.

    发现设置密码的时候说密码太简单,让重新输,那如果我就要用那个简单的密码不希望收到提示可以用另一种方法

    
    
    [root@zhangmeng ~]# useradd bob
    [root@zhangmeng ~]# echo 123456 |passwd --stdin bob
    Changing password for user bob.
    passwd: all authentication tokens updated successfully.
    [root@zhangmeng ~]# 
    
    

    再用tom用户登录,可以登录成功

    
    
    [root@zhangmeng ~]# telnet 192.168.2.42
    Trying 192.168.2.42...
    Connected to 192.168.2.42.
    Escape character is '^]'.
    CentOS release 6.4 (Final)
    Kernel 2.6.32-358.el6.x86_64 on an x86_64
    login: tom
    Password: 
    [tom@zhangmeng ~]$ 
    
    

    切换到root用户

    
    
    [tom@zhangmeng ~]$ su - root
    Password: 
    [root@zhangmeng ~]# 
    再次连接(加端口),还是不能访问
    [root@zhangmeng ~]# telnet 192.168.2.42 6379
    Trying 192.168.2.42...
    telnet: connect to address 192.168.2.42: Connection refused

    上网查了一下,是redis.conf配置文件里面的ip需要修改(bind 127.0.0.1 ::1 改为 bind 193.168.2.42)

    # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
    # JUST COMMENT THE FOLLOWING LINE.
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    bind 192.168.2.42
    
    # 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服务,再次连接(终于连上啦,不容易啦)

    [root@zhangmeng ~]# telnet 192.168.2.42 6379
    Trying 192.168.2.42...
    Connected to 192.168.2.42.
    Escape character is '^]'.

    完!

  • 相关阅读:
    Unity3D屠龙战机项目总结
    10.2 MySQL数据库安装
    10.1 JDBC基础
    9.5 异常处理规则
    9.4 Java的异常跟踪栈
    9.3 使用throw抛出异常
    9.2 Checked异常和Runtime异常
    9.1 异常处理机制
    8.5 泛型和数组
    8.5 擦除和转换
  • 原文地址:https://www.cnblogs.com/xphdbky/p/7405825.html
Copyright © 2020-2023  润新知