当前位置:   article > 正文

Linux系统下Redis的安装与配置_linux redis配置文件位置

linux redis配置文件位置

Redis安装包下载

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

redis官网
下载完成后使用scp命令拷贝安装包到Linux系统下:scp /Users/codegeekgao/Desktop/gxp/redis-3.2.11.tar.gz donniegao@10.211.55.9:/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
  • 1
  • 2
  • 3
  • 4
  • 5

配置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.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

出现这个问题可以选择上面的关闭保护模式,也可以配置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安装已经成功。
  • 将redis设置开机自动重启
    vim /lib/systemd/system/redis.service
    添加内容如下:

[Unit]
Description=redis
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.targe
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

保存后,启动和开启服务
systemctl daemon-reload 重新加载systemctl
systemctl enable redis.service 设置开机启动
systemctl start redis.service 启动redis服务

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/497964
推荐阅读
相关标签
  

闽ICP备14008679号