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

相关推荐

  1. Centos安装Redis6.X

    2024-07-11 14:36:05       45 阅读
  2. docker 部署最新稳定zookeeper

    2024-07-11 14:36:05       42 阅读
  3. CentOS 7 / Linux 安装Redis(超简单

    2024-07-11 14:36:05       32 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 14:36:05       53 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 14:36:05       56 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 14:36:05       46 阅读
  4. Python语言-面向对象

    2024-07-11 14:36:05       57 阅读

热门阅读

  1. 嵌入式Bootloader面试题面面观(2万字长文)

    2024-07-11 14:36:05       22 阅读
  2. 1.python基础

    2024-07-11 14:36:05       20 阅读
  3. 24/07/11数据结构(6.1215)双链表实现-栈实现

    2024-07-11 14:36:05       21 阅读
  4. Spring框架:核心概念与Spring Boot微服务开发指南

    2024-07-11 14:36:05       17 阅读
  5. 解决Spring Boot中的数据安全与加密

    2024-07-11 14:36:05       21 阅读
  6. Flask和Django两个Web框架的特点和适用场景

    2024-07-11 14:36:05       22 阅读
  7. 直升机停机坪的H代表什么

    2024-07-11 14:36:05       16 阅读
  8. AcWing 187. 导弹防御系统

    2024-07-11 14:36:05       21 阅读
  9. UL认证与UL报告的区别,什么情况需要办理UL认证

    2024-07-11 14:36:05       20 阅读
  10. 实施团队人员配备计划

    2024-07-11 14:36:05       20 阅读