centos虚拟机部署redis踩坑

以前都是用的云服务器或windows本地启动的redis,想在本地linux虚拟机部署一个,踩了一些坑,记录一下。

部署流程:

整个redis部署流程就是:github官网下载源码,进入redis源码目录make命令编译,再进入src目录make install命令安装。安装成功后会将得到的文件默认放在/usr/local/bin目录下:

每个文件的具体功能说明:

  1. redis-server

    • 用途:这是 Redis 服务器的主要程序。运行这个程序可以启动一个 Redis 数据库实例。

    • 使用示例

      bash深色版本

      复制代码
      ./redis-server
    • 可以指定配置文件来定制 Redis 的运行参数:

      bash深色版本

      复制代码
      ./redis-server /path/to/redis.conf
  2. redis-cli

    • 用途:Redis 命令行客户端,用于与 Redis 服务器进行交互,发送命令并接收回复。

    • 使用示例

      bash深色版本

      复制代码
      ./redis-cli
    • 也可以直接在命令后跟上要执行的命令:

      bash深色版本

      复制代码
      ./redis-cli PING
  3. redis-benchmark

    • 用途:性能测试工具,用来模拟 N 个客户端同时发送 M 个请求来评估 Redis 的性能。

    • 使用示例

      bash深色版本

      复制代码
      ./redis-benchmark -h localhost -p 6379 -c 50 -n 100000
    • 上述命令表示使用 50 个客户端连接到本地 Redis 服务,并发送总共 100,000 个请求。

  4. redis-check-aof

    • 用途:AOF(Append Only File)文件检查工具,用于修复可能损坏的 AOF 文件。当 Redis 无法加载 AOF 文件时,可以使用此工具尝试恢复数据。

    • 使用示例

      bash深色版本

      复制代码
      ./redis-check-aof --fix /path/to/appendonly.aof
  5. redis-check-rdb

    • 用途:RDB(Redis DataBase file)文件检查工具,用于检查 RDB 文件是否损坏。这对于确保备份文件的有效性很有帮助。

    • 使用示例

      bash深色版本

      复制代码
      ./redis-check-rdb /path/to/dump.rdb
  6. redis-sentinel

    • 用途:Redis Sentinel 是 Redis 的高可用性解决方案。它监控主从实例的状态,并在检测到故障时自动进行故障转移。

    • 使用示例

      bash深色版本

      复制代码
      ./redis-sentinel /path/to/sentinel.conf
    • 注意:实际上,你可以通过 redis-server 来运行 Sentinel 配置文件,因为 redis-sentinelredis-server 的一个符号链接,专门用于运行 Sentinel 模式。

修改redis.conf配置:

将daemonize属性改为yes,代表以后台服务的方式启动Redis。

requirepass 更改密码

注释掉 bind 127.0.0.1 -::1 ,否则只能本地连接redis

部署中遇到的问题:

1.安装虚拟机时选择的最小安装,导致没有自带wget,ifconfig,vim等。

解决:选择更复杂的安装,例如基本网页服务器,右边勾选系统管理工具。

2.yum安装gcc时yum源报错:

已加载插件:fastestmirror, langpacks

Determining fastest mirrors

One of the configured repositories failed (未知),

and yum doesn't have enough cached data to continue. At this point the only

safe thing yum can do is fail. There are a few ways to work "fix" this:

复制代码
 1. Contact the upstream for the repository and get them to fix the problem.

 2. Reconfigure the baseurl/etc. for the repository, to point to a working
    upstream. This is most often useful if you are using a newer
    distribution release than is supported by the repository (and the
    packages for the previous distribution release still work).

 3. Run the command with the repository temporarily disabled
        yum --disablerepo=<repoid> ...

 4. Disable the repository permanently, so yum won't use it by default. Yum
    will then just ignore the repository until you permanently enable it
    again or use --enablerepo for temporary usage:

        yum-config-manager --disable <repoid>
    or
        subscription-manager repos --disable=<repoid>

 5. Configure the failing repository to be skipped, if it is unavailable.
    Note that yum will try to contact the repo. when it runs most commands,
    so will have to try and fail each time (and thus. yum will be be much
    slower). If it is a very temporary problem though, this is often a nice
    compromise:

        yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: base/7/x86_64

解决:更换yum源,将/etc/yum.repos.d目录下的文件全删掉:

bash 复制代码
rm -rf /etc/yum.repos.d

更换为其它源,例如华为云:repo.huaweicloud.com/repository/conf/

找到对应版本,wget下载到/etc/yum.repos.d目录下,清楚yum缓存

bash 复制代码
cd /etc/yum.repos.d
wget https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
yum clean all

3.编译redis时,cd src && make all which: no python3 in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin) make[1]: 进入目录"/software/redis-7.4.2/src" CC threads_mngr.o In file included from server.h:58:0, from threads_mngr.c:15: zmalloc.h:29:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录 #include <jemalloc/jemalloc.h> ^ 编译中断。 make[1]: * [threads_mngr.o] 错误 1 make[1]: 离开目录"/software/redis-7.4.2/src" make: * [all] 错误 2

新版redis默认用的jemalloc,但系统中没有。

解决:禁用jemalloc来编译:

bash 复制代码
make MALLOC=libc

或者安装jemalloc后编译

4.启动报错:

root@localhost bin\]# redis-server redis.conf 49754:C 14 Feb 2025 00:48:03.092 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. 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 因为redis需要更多的内存 解决:在/etc/sysctl.conf文件中添加一行:vm.overcommit_memory = 1,然后重启机器或者执行命令: ```bash sysctl vm.overcommit_memory=1 ``` (就是报错里说的解决办法) and 'sysctl vm.overcommit_memory=1' for this to take effect 因为redis需要更多的内存 解决:在/etc/sysctl.conf文件中添加一行:vm.overcommit_memory = 1,然后重启机器或者执行命令: ```bash sysctl vm.overcommit_memory=1 ``` (就是报错里说的解决办法)

相关推荐
松涛和鸣8 小时前
72、IMX6ULL驱动实战:设备树(DTS/DTB)+ GPIO子系统+Platform总线
linux·服务器·arm开发·数据库·单片机
简单中的复杂8 小时前
【避坑指南】RK3576 Linux SDK 编译:解决 Buildroot 卡死在 host-gcc-final 的终极方案
linux·嵌入式硬件
wVelpro9 小时前
如何在Pycharm 2025.3 版本实现虚拟环境“Make available to all projects”
linux·ide·pycharm
程序员老舅9 小时前
C++高并发精髓:无锁队列深度解析
linux·c++·内存管理·c/c++·原子操作·无锁队列
雨中风华10 小时前
Linux, macOS系统实现远程目录访问(等同于windows平台xFsRedir软件的目录重定向)
linux·windows·macos
爱吃生蚝的于勒10 小时前
【Linux】进程信号之捕捉(三)
linux·运维·服务器·c语言·数据结构·c++·学习
The森10 小时前
Linux IO 模型纵深解析 01:从 Unix 传统到 Linux 内核的 IO 第一性原理
linux·服务器·c语言·经验分享·笔记·unix
惊讶的猫10 小时前
redis分片集群
数据库·redis·缓存·分片集群·海量数据存储·高并发写
期待のcode11 小时前
Redis的主从复制与集群
运维·服务器·redis
翼龙云_cloud11 小时前
腾讯云代理商: Linux 云服务器搭建 FTP 服务指南
linux·服务器·腾讯云