当前位置: 首页 > news >正文

centos下编译安装redis最新稳定版

一、目标

编译安装最新版的redis

二、安装步骤

1、redis官方下载页面

Downloads - Redis

2、下载最新版的redis源码包

注:此时的最新稳定版是 redis 7.2.5

wget https://download.redis.io/redis-stable.tar.gz

3、安装编译环境

yum install -y gcc gcc-c++

4、解压并编译安装

tar -zxf redis-stable.tar.gz
cd redis-stable
make PREFIX=/usr/local/redis install
mkdir /usr/local/redis/etc
cp redis.conf /usr/local/redis/etc/redis.conf

注:PREFIX=/usr/local/redis 指定redis安装目录

5、设置环境变量

vi /etc/profile# 追加如下内容
export PATH=$PATH:/usr/local/redis/bin# 保存退出# 使生效
source /etc/profile

6、修改系统参数

vi /etc/security/limits.conf# 追加如下两行*	soft	nofile	102400*	hard	nofile	102400
echo -e "net.core.somaxconn = 511\nvm.overcommit_memory = 1" >> /etc/sysctl.conf
sysctl -p

注:不做这一步的话,会报错如下:

7127:C 05 Jul 2024 14:04:36.683 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

7127:M 05 Jul 2024 14:04:36.683 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

 7、手动启动和停止redis

redis-server /usr/local/redis/etc/redis.conf

注:这样会在前台启动。

如果想后台启动,需要修改配置文件。然后重启redis即可直接跑到后台运行了

vi /usr/local/redis/etc/redis.conf

将【daemonize no】改为【daemonize yes】

redis-cli shutdown
或
pkill redis-server

8、将redis启动交给systemd托管

vi /etc/systemd/system/redis.service# 写上如下内容
[Unit]
Description=redis
Documentation=https://redis.io
After=network.target[Service]
User=redis
Group=redis
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
ExecStop=/usr/local/redis/bin/redis-cli shutdown
Restart=on-failure[Install]
WantedBy=multi-user.target

9、创建redis系统账号

注:由于systemd启动脚本里指定了启动redis的用户为redis,所以必须创建相应的账号,并赋予权限。

groupadd redis && useradd -r -g redis -s /sbin/nologin redis
chown -R redis.redis /usr/local/redis

10、将redis加入开机自启

注:如果交给systemd托管了,那么就可以用下面这个方法,让其开机自启

systemctl enable redis

11、(附)部分配置介绍

【daemonize no】改为【daemonize yes】
# 启动redis后不进入后台,想让其进入后台就改为yes。但如果托管给systemd的话这里不用改【# requirepass foobared】 更改为【requirepass serena0129】
#开启redis认证,设备密码为serena0129【logfile ""】改为【logfile "/var/log/redis.log"】
#将redis路径设定为/var/log/redis.log

http://www.lryc.cn/news/392489.html

相关文章:

  • 如何让自动化测试更加灵活简洁?
  • linux 下载依赖慢和访问github代码慢
  • 奥比中光astra_pro相机使用记录
  • 【MindSpore学习打卡】应用实践-计算机视觉-深入解析 Vision Transformer(ViT):从原理到实践
  • Debezium系列之:支持在一个数据库connector采集中过滤某些表的删除事件
  • SQL Server端口配置指南:最佳实践与技巧
  • FastGPT 报错:undefined 该令牌无权使用模型:gpt-3.5-turbo (request id: xxx)
  • springboot系列八: springboot静态资源访问,Rest风格请求处理, 接收参数相关注解
  • # 职场生活之道:善于团结
  • go sync包(五) WaitGroup
  • 基于深度学习的相机内参标定
  • 适合金融行业的国产传输软件应该是怎样的?
  • 昇思25天学习打卡营第9天|MindSpore使用静态图加速(基于context的开启方式)
  • class类和style内联样式的绑定
  • 3033.力扣每日一题7/5 Java
  • GPT-5:下一代AI如何彻底改变我们的未来
  • 重载一元运算符
  • 10元 DIY 一个柔性灯丝氛围灯
  • 表单自定义组件 - 可选择卡片SelectCard
  • Ubuntu / Debian安装FTP服务
  • 若依 Vue 前端分离 3.8.8 版中生成的前端代码中关于下拉框只有下拉箭头的问题
  • C++把一个类封装成动态链接库
  • 每天一个项目管理概念之项目章程
  • c++11新特性-4-返回类型后置
  • Linux-C语言实现一个进度条小项目
  • vue使用glide.js实现轮播图(可直接复制使用)
  • TK养号工具开发会用上的源代码科普!
  • 信创-办公软件应用工程师认证
  • 数组操作forEach和map
  • 流式处理应用场景与流式计算处理框架选择建议