Linux系统下Redis的安装与配置

版权声明:本文为博主原创文章版权归作者和CSDN共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 https://blog.csdn.net/javaee_gao/article/details/89086443

Redis安装包下载

首先到Redis官网下载 redis下载链接 找到下图所示位置:选择相对应的版本的redis进行下载,本文以mac开发环境进行演示:

redis官网
下载完成后使用scp命令拷贝安装包到Linux系统下:scp /Users/codegeekgao/Desktop/gxp/redis-3.2.11.tar.gz [email protected]:/soft/packages

redis安装环境

由于Redis的安装需要依赖C++,请确保安装的系统有C++的环境。若没有使用yum install gcc-c++ 进行安装C++

  • 解压源码
    tar -zxvf redis-3.0.0.tar.gz
  • 进入解压后的目录进行编译并安装
    cd /usr/local/redis-3.0.0
    make PREFIX=/usr/local/redis install
    若出现以下提示表示编译安装已通过
    安装成功提示图
    redis.conf是redis的配置文件,redis.conf在redis源码目录。拷贝配置文件到安装目录下进入源码目录,里面有一份配置文件 redis.conf,然后将其拷贝到安装路径下,并创建日志目录和数据目录。
cp /usr/local/redis/redis.conf  /usr/local/redis/conf
cd /usr/local/redis
mkdir conf
mkdir log
mkdir redisData

配置redis

  • 后台启动
    vim redis.conf
    将 daemonize yes 以后端模式启动
  • 配置持久化文件存放位置
    dir /usr/local/service/redis/redisData
  • 配置日志生成文件路径
    logfile /usr/local/service/redis/log/redis.log
  • 配置redis可以远程连接
    将redis.conf中bind 127.0.0.1 注释掉,见下图:
    注释绑定本地ip
    并且关闭掉保护模式配置:protected-mode no
    修改访问模式
    否则在客户端将会报一下错误:
JedisDataException: 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登陆的密码
redis.conf中配置项注释的#requirepass打开并设置以下连接的密码比如:requirepass myRedis
以上配置好以后,初始化配置基本完成了,下面就是启动redis了。

  • 启动redis
    ./bin/redis-server ./redis.conf
    -连接redis
    /usr/local/redis/bin/redis-cli -a myRedis
    如果没有-a myRedis是无法连接上redis的
    当连接完成后,使用ping命令,若返回Pong,则redis安装已经成功。

猜你喜欢

转载自blog.csdn.net/javaee_gao/article/details/89086443