redis7.4.2单机配置过程

 更新时间:2026年05月25日 09:25:14   作者:PABL01  
这段文章详细介绍了通过源码编译安装Redis的过程,涵盖了从下载源码包到卸载Redis的每一步骤,并强调了实践中的实用性和重要性性,关键词包括:源码编译、Redis安装和卸载流程

解压源码包

将从官网下载的redis源码压缩包上传到服务器的相关目录下。

[root@hcss-ecs-2851 ~]# wget https://download.redis.io/redis-stable.tar.gz
[root@hcss-ecs-2851 ~]# mv redis-stable.tar.gz /opt/soft/redis/
[root@hcss-ecs-2851 ~]# cd /opt/soft/redis/
[root@hcss-ecs-2851 redis]# ls
redis-stable.tar.gz

解压并进入解压后的目录中。

[root@hcss-ecs-2851 redis]# tar -zxvf redis-stable.tar.gz
[root@hcss-ecs-2851 redis]# ls
redis-stable  redis-stable.tar.gz
[root@hcss-ecs-2851 redis]# cd redis-stable
[root@hcss-ecs-2851 redis-stable]# ls
00-RELEASENOTES  CODE_OF_CONDUCT.md  deps     LICENSE.txt  MANIFESTO  redis.conf              runtest          runtest-moduleapi  SECURITY.md    src    TLS.md
BUGS             CONTRIBUTING.md     INSTALL  Makefile     README.md  REDISCONTRIBUTIONS.txt  runtest-cluster  runtest-sentinel   sentinel.conf  tests  utils

安装gcc

[root@hcss-ecs-2851 redis-stable]# yum install -y gcc gcc-c++

安装redis

[root@hcss-ecs-2851 redis-stable]# make
root@hcss-ecs-2851 redis-stable]# make install

简单测试是否安装成功

[root@hcss-ecs-2851 redis-stable]# cd 
[root@hcss-ecs-2851 ~]# redis-server
9193:C 24 Mar 2025 12:03:19.847 # 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.
9193:C 24 Mar 2025 12:03:19.847 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9193:C 24 Mar 2025 12:03:19.847 * Redis version=7.4.2, bits=64, commit=00000000, modified=0, pid=9193, just started
9193:C 24 Mar 2025 12:03:19.847 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
9193:M 24 Mar 2025 12:03:19.847 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis Community Edition      
  .-`` .-```.  ```\/    _.,_ ''-._     7.4.2 (00000000/0) 64 bit
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 9193
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

9193:M 24 Mar 2025 12:03:19.848 * Server initialized
9193:M 24 Mar 2025 12:03:19.848 * Ready to accept connections tcp

自定义设置

自定义目录

[root@hcss-ecs-2851 ~]# cd /opt/soft/redis/
[root@hcss-ecs-2851 redis]# mkdir {etc,lib,log}
[root@hcss-ecs-2851 redis]# ls
etc  lib  log  redis-stable  redis-stable.tar.gz
[root@hcss-ecs-2851 redis]# cp redis-stable/redis.conf etc/
[root@hcss-ecs-2851 redis]# ls etc/
redis.conf

编辑redis.conf

bind 0.0.0.0 # 任意ip均可访问
protected-mode no
port 6379
daemonize yes # 后台运行
pidfile /var/run/redis.pid # 运行时进程id
logfile /opt/soft/redis/log/redis.log #日志文件
dir /opt/soft/redis/lib/
requirepass ********* # 设置密码

创建 systemd 服务文件

[root@hcss-ecs-2851 etc]# cd /etc/systemd/system/
[root@hcss-ecs-2851 system]# vim redis.service
[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
Type=forking
User=root
Group=root
ExecStart=/usr/local/bin/redis-server /opt/soft/redis/etc/redis.conf
ExecStop=/usr/local/bin/redis-cli -p 6379 shutdown
PIDFile=/var/run/redis.pid
Restart=on-failure

[Install]
WantedBy=multi-user.target
[root@hcss-ecs-2851 ~]# systemctl daemon-reload
[root@hcss-ecs-2851 ~]# systemctl start redis
[root@hcss-ecs-2851 ~]# systemctl status redis
● redis.service - Redis In-Memory Data Store
   Loaded: loaded (/etc/systemd/system/redis.service; disabled; vendor preset: disabled)
   Active: active (running) since 一 2025-03-24 12:43:28 CST; 8s ago
  Process: 3340 ExecStart=/usr/local/bin/redis-server /opt/soft/redis/etc/redis.conf (code=exited, status=0/SUCCESS)
 Main PID: 3341 (redis-server)
   CGroup: /system.slice/redis.service
           └─3341 /usr/local/bin/redis-server 0.0.0.0:6379

3月 24 12:43:28 hcss-ecs-2851 systemd[1]: Starting Redis In-Memory Data Store...
3月 24 12:43:28 hcss-ecs-2851 systemd[1]: Can't open PID file /var/run/redis.pid (yet?) after start: No such file or directory
3月 24 12:43:28 hcss-ecs-2851 systemd[1]: Started Redis In-Memory Data Store.
[root@hcss-ecs-2851 ~]# cd /opt/soft/redis/log/
[root@hcss-ecs-2851 log]# cat redis.log 
......
3341:M 24 Mar 2025 12:43:28.337 * Ready to accept connections tcp
[root@hcss-ecs-2851 log]# systemctl stop redis
[root@hcss-ecs-2851 log]# cat redis.log 
......
3341:M 24 Mar 2025 12:44:10.592 # Redis is now ready to exit, bye bye...

卸载redis

如果按照上述方法,即源码编译安装,则基本可以按照如下流程卸载redis。
进入源码包目录。

cd /opt/soft/redis/redis-stable/
make uninstall && make clean

删除redis相关文件和目录。

cd /opt/soft/ && rm -rf redis/
yum remove redis
rm /etc/systemd/system/redis.service 

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • Redis消息队列、阻塞队列、延时队列的实现

    Redis消息队列、阻塞队列、延时队列的实现

    Redis是一种常用的内存数据库,它提供了丰富的功能,通常用于数据缓存和分布式队列,本文主要介绍了Redis消息队列、阻塞队列、延时队列的实现,感兴趣的可以了解一下
    2023-11-11
  • Linux中Redis安装部署的操作步骤

    Linux中Redis安装部署的操作步骤

    公司一直在使用redis集群,寻思着自己也部署一套练练手,下面这篇文章主要给大家介绍了关于Linux中Redis安装部署的操作步骤,需要的朋友可以参考下
    2022-04-04
  • Redis内存碎片率调优处理方式

    Redis内存碎片率调优处理方式

    Redis集群因内存碎片率超过1.5触发告警,分析发现内因与外因导致内存碎片,内因为操作系统内存分配机制,外因为Redis操作特性,使用Redis内置内存碎片清理机制可有效降低碎片率,但需注意可能影响性能,建议使用MEMORY命令诊断内存使用情况,合理配置参数以优化性能
    2024-09-09
  • redis简介_动力节点Java学院整理

    redis简介_动力节点Java学院整理

    这篇文章主要介绍了redis简介,Redis是一个开源的,先进的 key-value 存储可用于构建高性能,可扩展的 Web 应用程序的解决方案,有兴趣的可以了解一下
    2017-08-08
  • CentOS 6.5 64位下安装Redis3.0.2的具体步骤

    CentOS 6.5 64位下安装Redis3.0.2的具体步骤

    这篇文章主要介绍了CentOS 6.5 64位下安装Redis3.0.2的具体步骤,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2018-08-08
  • 无法启动Redis打开redis-server闪退的问题解决办法

    无法启动Redis打开redis-server闪退的问题解决办法

    正常开启redis服务,首先要启动redis-server.exe,但是闪退,导致无法开启redis服务,这篇文章主要给大家介绍了关于无法启动Redis打开redis-server闪退问题的解决办法,需要的朋友可以参考下
    2024-07-07
  • Redis之Set和Zset使用及说明

    Redis之Set和Zset使用及说明

    文章介绍了Redis集合和有序集合的相关命令,包括添加、查询、修改、删除元素,集合间的交集、并集、差集操作,以及数据库管理操作,强调了在实际开发中合理使用这些功能的重要性
    2026-03-03
  • redis中跳表zset的具体使用

    redis中跳表zset的具体使用

    Redis跳表zset是一种结合了跳表和有序集合的高效数据结构,适用于实现排序和大规模数据的快速查询,本文主要介绍了redis中跳表zset的具体使用,感兴趣的可以了解一下
    2024-01-01
  • Redis锁与DB锁的使用与区别小结

    Redis锁与DB锁的使用与区别小结

    本文主要介绍了Redis锁与DB锁的使用与区别小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2026-03-03
  • 通过kubesphere部署redis的方法

    通过kubesphere部署redis的方法

    这篇文章主要介绍了通过kubesphere部署redis的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-11-11

最新评论