zoukankan      html  css  js  c++  java
  • 阿里云ECS CentOS 8 安装配置Redis

    本文主要记录在船新的CentOS 8中安装配置.NET Core运行环境以及配合使用的Redis,Redis的安装配置相对比较简单,综合了网上的教程进行实践,并最终完成配置正常使用。废话不多说,开始!

    一、安装Redis

    1、安装
    yum install redis
    
    2、查询本次安装的版本(主要用于查看Redis所有文件位置)
    rpm -qa|grep redis
    

    结果:redis-5.0.3-1.module_el8.0.0+6+ab019c03.x86_64

    3、查询安装位置
    rpm -ql redis-5.0.3-1.module_el8.0.0+6+ab019c03.x86_64
    

    文件目录

    4、开启Redis Server
    cd /usr/bin
    
    redis-server
    

    开启服务

    至此,Redis Server已经可以启动了!

    5、客户端连接 Redis Server

    开启一个新的Linux连接窗口。此处为连接本地的Redis,故无需带上ip以及端口参数

    cd /usr/bin
    
    redis-cli
    

    开启客户端

    本地客户端连接也是正常的!

    二、远程连接Redis

    1、配置

    完成以上步骤,仅仅是在本地连接上能够使用,一旦使用外部调用,则无法使用。此处外部设备操作系统为win10,其他的根据自身情况度娘设置。其次,在外部连接之前,先配置阿里云ESC 安全组配置,添加Redis端口安全组,默认端口为6379

    问题①:在不进行配置的情况下,直接连接远程端Redis Server会报如下错误:

    (error) 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.
    

    此处大致意思为:配置中 protected-mode属性为yes,即当前处于保护模式下,无法连接。我们需要设置其为no

    问题②:无法操作远程Redis,进行Redis操作报错:

    Error: 在驱动器 %1 上插入软盘。
    

    此处问题进行密码设置即可。

    以上问题的解决方法

    本地客户端连接情况下,进行如下操作:

    a、打开Redis配置文件Redis.conf
    cd /etc
    
    vim redis.conf
    

    按下键盘i进入编辑模式

    找到如下参数,并修改:

    针对问题①的修改:

    bind 127.0.0.1  	 //行数:69   =》修改为#bind 127.0.0.1 
    
    protected-mode yes      //行数:89  =》修改为protected-mode no
    
    daemonize yes 	        //行数:137  =》修改为daemonize no //设置为no则不作为后台运行,否则后台运行
    

    问题①设置示例

    针对问题②的修改:

    # requirepass foobared   //行数:508  =》在508行下添加与行,内容为requirepass code6076..
    

    问题②设置示例

    b、保存配置文件并退出

    按下键盘esc退出编辑模式,然后按shift + : 键,再录入wq,回车即可。

    c、重新启动Redis Server
    redis-server /etc/redis.conf
    

    此处进行Redis服务器启动并指定配置文件,以应用我们改的配置。

    注:如果上面设置daemonize参数

    为no时,回车后,效果如下:(为空白,实则已经非后台执行,当前控制台已被占用)

    daemonize no

    为yes时:回车后,效果如下:(后台执行,可继续操作)

    daemonize yes

    2、连接

    以Windows 10 为例,连接方式如下:

    D:WorkSpaceRedis
    edis-cli -h x.x.x.x -p 6379 -a code6076..
    

    连接测试

    3、设置开机自启

    启动服务

    systemctl start redis
    

    如果开启服务出现任何输出,则需要根据提示,根据日志进行配置,我就遇到了redis日志权限不足。有类似情况使用如下命令: chown redis:redis /var/log/redis/redis.log
    报错如下图:
    开启服务报错

    设置自启

    systemctl enable redis
    

    然后重启服务器

    reboot
    

    重启完成后,查看状态:

    systemctl stutas redis
    

    大功告成!

  • 相关阅读:
    递归算法解析成树形结构
    Tomcat性能参数设置
    hibernate.cfg.xml 配置(摘录)
    OpenCms 集成外部Solr Server
    安装配置OPENCMS的Replication cluster(从)详细过程
    ruby 格式化当前日期时间
    Ruby 语法快速入门
    ruby condition
    配置 RAILS FOR JRUBY1.7.4
    我的权限系统设计实现MVC4 + WebAPI + EasyUI + Knockout(五)框架及Web项目的组件化
  • 原文地址:https://www.cnblogs.com/memoyu/p/13234560.html
Copyright © 2011-2022 走看看