CentOS7.4下安装Redis

本文详细介绍了在Linux环境下安装和配置Redis的过程,包括从下载到编译,再到配置日志文件、后台运行、设置密码及使用systemctl实现自启动的全过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装准备

Redis下载地址:Redis官网

  • 将redis的gz包传送至主机
  • tar zxvf 解压至/usr/local/redis目录

该步骤可以忽略

## 存放可执行文件
[root@alycentos redis]# mkdir bin
## 存放配置文件 
[root@alycentos redis]# mkdir etc 
[root@alycentos redis]# mv ../redis.conf /usr/local/redis/etc/
[root@alycentos src]# mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-sentine ../bin

文件赋权

## 改变redis文件夹所属(可忽略)
[root@alycentos src]# chown redis:redis /usr/local/redis/*

编译

  • 进入redis目录,执行make命令
  • 进入redis/src目录,执行make命令

至此,redis已安装完毕

配置

Redis配置

日志文件(启动日志等)
# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile "/usr/local/redis/log/redis.log"
后台运行
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
pid文件路劲
# If a pid file is specified, Redis writes it where specified at startup
# and removes it at exit.
#
# When the server runs non daemonized, no pid file is created if none is
# specified in the configuration. When the server is daemonized, the pid file
# is used even if not specified, defaulting to "/var/run/redis.pid".
#
# Creating a pid file is best effort: if Redis is not able to create it
# nothing bad happens, the server will start and run normally.
pidfile /var/run/redis_6379.pid
连接密码
# Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared
requirepass redis

systemctl 开启自启

[root@alycentos /]# cd usr/lib/systemd/system
[root@alycentos system]# vim redis-server.service 

redis-server.service添加如下内容:

[Unit]
Description=Redis Server Manager
After=network.target remote-fs.target nss-lookup.target
 
[Service]
## 配置用户与用户组
group=redis
user=redis
## forking 后台运行
Type=forking
## 指定pid(进程id)文件 
PIDFile=/var/run/redis_6379.pid
## 指定启动与停止运行脚本   
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
ExecStop=/usr/local/redis/bin/redis-cli shutdown
Restart=always
 
[Install]
WantedBy=multi-user.target

运行命令:

## 重新加载systemctl配置
[root@alycentos system]# systemctl daemon-reload
## 开机自启
[root@alycentos system]# systemctl enable redis-server.service
## 将redis-cli建立软连接,已至于可以直接运行redis-cli
[root@alycentos system]# ln /usr/local/redis/bin/redis-cli /usr/bin/redis

问题

1.无法保存库文件

在这里插入图片描述
解决办法(可能):

[root@alycentos bin]# chmod 755 /usr/local/redis/bin/dump.rdb
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值