哥伦布

博客园 首页 新随笔 联系 订阅 管理

1、安装必要前缀组件

我是使用root安装
yum install -y epel-release
yum install -y gcc make python3

2、下载Redis7.4.1

wget https://download.redis.io/releases/redis-7.4.1.tar.gz
上面这个我自己get不下来。
我在其他途径下好,放到放到城通网盘
redis-7.4.1.tar.gz (访问密码: 1133)下载链接

3、编译

解压缩
tar xzf redis-7.4.1.tar.gz
编译
cd redis-7.4.1
make install
编译完成后,默认文件位置在: /usr/local/bin

4、配置

复制源代码文件解压目录下的redis.conf文件到/etc/redis.conf
cp redis.conf /etc/redis.conf
修改/etc/redis.conf配置文件
需要修改2处。
bing 0.0.0.0
requirepass mypassword

以上2行分别是绑定全部IP,并设置密码为mypassword

5、服务和开机启动

新建一个配置文件
vim /etc/systemd/system/redis.service
文件内容为:

redis.service文件内容
[Unit]
Description=redis
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/redis-server /etc/redis.conf
ExecReload=/usr/local/bin/redis-server -s reload
ExecStop=/usr/local/bin/redis-server -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

重新载入服务配置
systemctl daemon-reload

启动redis
systemctl start redis

设置开机启动redis
systemctl enable redis

6、警告的处理。

Redis 的警告 WARNING Memory overcommit must be enabled! 是因为:

  • 内存过量分配(Overcommit):Linux 内核默认会允许进程申请超过物理内存+交换空间(swap)的内存(通过启发式算法评估)。但某些保守配置(如 vm.overcommit_memory=2)会严格限制内存分配,可能导致 Redis 在内存不足时崩溃或无法执行 fork() 操作(如生成 RDB 快照或 AOF 重写时)。
  • Redis 的依赖:Redis 依赖 fork() 创建子进程来持久化数据。如果系统禁止过量分配,fork() 可能因"内存不足"而失败。
    Redis 启动提示:The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128
    这个警告表明 Redis 的 TCP 连接队列(backlog)设置与系统内核参数不匹配,可能导致高并发时连接被丢弃。以下是详细分析和解决方法:
    解决方法:
    修改配置文件
    /etc/sysctl.conf
    添加2行:
    vm.overcommit_memory = 1
    net.core.somaxconn = 1024

重新加载配置
sudo sysctl -p

7、清理

建议删除解压出来的redis-7.4.1目录。

posted on 2024-11-26 17:08  Caraxes  阅读(764)  评论(0)    收藏  举报