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 ``` (就是报错里说的解决办法)

相关推荐
Zfox_1 小时前
Redis:Hash数据类型
服务器·数据库·redis·缓存·微服务·哈希算法
呼拉拉呼拉1 小时前
Redis内存淘汰策略
redis·缓存
apocelipes4 小时前
Linux c 运行时获取动态库所在路径
linux·c语言·linux编程
努力学习的小廉5 小时前
深入了解linux系统—— 进程池
linux·运维·服务器
咖啡啡不加糖5 小时前
Redis大key产生、排查与优化实践
java·数据库·redis·后端·缓存
MickeyCV5 小时前
使用Docker部署MySQL&Redis容器与常见命令
redis·mysql·docker·容器·wsl·镜像
秃头菜狗5 小时前
各个主要目录的功能 / Linux 常见指令
linux·运维·服务器
2301_793102496 小时前
Linux——MySql数据库
linux·数据库
肥仔哥哥19306 小时前
springCloud2025+springBoot3.5.0+Nacos集成redis从nacos拉配置起服务
redis·缓存·最新boot3集成
jiunian_cn7 小时前
【Linux】centos软件安装
linux·运维·centos