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

一、目标

编译安装最新版的redis

二、安装步骤

1、redis官方下载页面

Downloads - Redis

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

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

bash 复制代码
wget https://download.redis.io/redis-stable.tar.gz

3、安装编译环境

bash 复制代码
yum install -y gcc gcc-c++

4、解压并编译安装

bash 复制代码
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、设置环境变量

bash 复制代码
vi /etc/profile

# 追加如下内容
export PATH=$PATH:/usr/local/redis/bin

# 保存退出

# 使生效
source /etc/profile

6、修改系统参数

bash 复制代码
vi /etc/security/limits.conf

# 追加如下两行
	*	soft	nofile	102400
	*	hard	nofile	102400
bash 复制代码
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

bash 复制代码
redis-server /usr/local/redis/etc/redis.conf

注:这样会在前台启动。

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

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

将【daemonize no】改为【daemonize yes】

bash 复制代码
redis-cli shutdown
或
pkill redis-server

8、将redis启动交给systemd托管

bash 复制代码
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,所以必须创建相应的账号,并赋予权限。

bash 复制代码
groupadd redis && useradd -r -g redis -s /sbin/nologin redis
chown -R redis.redis /usr/local/redis

10、将redis加入开机自启

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

bash 复制代码
systemctl enable redis

11、(附)部分配置介绍

bash 复制代码
【daemonize no】改为【daemonize yes】
# 启动redis后不进入后台,想让其进入后台就改为yes。但如果托管给systemd的话这里不用改


【# requirepass foobared】 更改为【requirepass serena0129】
#开启redis认证,设备密码为serena0129


【logfile ""】改为【logfile "/var/log/redis.log"】
#将redis路径设定为/var/log/redis.log
相关推荐
李白你好3 小时前
Windows 离线 Linux 提权辅助查询工具
linux
Lust Dusk4 小时前
记一次Linux应急响应题目解析
linux·运维·服务器·网络·安全·网络安全
ShineWinsu4 小时前
对于Linux:五种IO模型以及非阻塞IO的详细解析
linux·c++·面试·io·阻塞·非阻塞·fcntl
千千寰宇4 小时前
[Linux/Ollama] Termux : 一款运行在 Android 平台上的开源终端模拟器与 Linux 环境应用、支持在手机上基于Ollama部署LLM
linux
ningmengjing_5 小时前
Redis 从入门到实战:Python操作全攻略
数据库·redis·python
lingran__6 小时前
Linux 基础常用指令万字详解(上)|文件目录命令,结合底层原理剖析
linux·运维·服务器·后端·centos·linux基础指令
Dlrb12117 小时前
Linux驱动---sys文件系统自动添加设备节点、添加调试节点以及MISC设备驱动的解释
linux·imx6ull·misc·设备节点·sys文件系统
刘某的Cloud7 小时前
Galera Cluster mariadb 生产环境常见问题排查与运维指南
linux·运维·数据库·mariadb·集群高可用
70asunflower8 小时前
Linux 性能排查分析完全教程
linux·运维
dok129 小时前
Johannes 《Linux内核模块与设备驱动开发:编写Linux驱动程序》 (11)kmalloc 动态内存分配和struct file中的私有数据
linux·驱动开发·算法