Redis 5.0.3默认配置启动报错解决方法

本文详细解析了Redis启动时常见的三个警告信息及其解决方法,包括调整TCP backlog、内存分配策略和禁用透明大页,确保Redis在高负载环境下稳定运行。

一、redis默认配置启动报错误信息如下

# /usr/local/redis/bin/redis-server /usr/local/src/redis-5.0.3/redis.conf
5852:C 24 Jan 2019 23:00:07.676 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
5852:C 24 Jan 2019 23:00:07.676 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=5852, just started
5852:C 24 Jan 2019 23:00:07.676 # Configuration loaded
5852:M 24 Jan 2019 23:00:07.676 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 5.0.3 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 5852
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

5852:M 24 Jan 2019 23:00:07.677 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
5852:M 24 Jan 2019 23:00:07.677 # Server initialized
5852:M 24 Jan 2019 23:00:07.677 # WARNING overcommit_memory is set to 0! Background save 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.
5852:M 24 Jan 2019 23:00:07.677 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
5852:M 24 Jan 2019 23:00:07.677 * Ready to accept connections

 二、解决方法

1、WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

# 对一个高负载的环境来说tcp设置128这个值,太小了。

临时生效
echo 1024 > /proc/sys/net/core/somaxconn

永久生效
vim /etc/sysctl.conf
net.core.somaxconn = 1024
sysctl -p

2、WARNING overcommit_memory is set to 0! Background save 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.

# overcommit_memory参数说明:
设置内存分配策略(可选,根据服务器的实际情况进行设置)
/proc/sys/vm/overcommit_memory
可选值:0、1、2。
0、表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
1、表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
2、表示内核允许分配超过所有物理内存和交换空间总和的内存

临时生效
echo 1 > /proc/sys/vm/overcommit_memory

永久生效
vim /etc/syctl.conf
vm.overcommit_memory = 1
sysctl -p


3、WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

# 你使用的是透明大页,可能导致redis延迟和内存使用问题。

临时生效
echo never > /sys/kernel/mm/transparent_hugepage/enabled

永久生效
vim /etc/rc.local
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi

chmod +x /etc/rc.local

 三、修改后启动无报错状态

# /usr/local/redis/bin/redis-server /usr/local/src/redis-5.0.3/redis.conf
1228:C 24 Jan 2019 23:26:50.044 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1228:C 24 Jan 2019 23:26:50.044 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=1228, just started
1228:C 24 Jan 2019 23:26:50.044 # Configuration loaded
1228:M 24 Jan 2019 23:26:50.044 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 5.0.3 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1228
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

1228:M 24 Jan 2019 23:26:50.045 # Server initialized
1228:M 24 Jan 2019 23:26:50.045 * DB loaded from disk: 0.000 seconds
1228:M 24 Jan 2019 23:26:50.045 * Ready to accept connections

 

转载于:https://www.cnblogs.com/miclesvic/p/10317589.html

<think>嗯,我现在需要了解如何用指定的配置文件启动Redis 5.0.3。首先,我应该回忆一下Redis的基本启动命令。记得默认情况下,启动Redis服务端是用redis-server命令,不带参数的话会用默认配置。但用户想要指定配置文件,所以可能需要加上配置文件的路径作为参数。 接下来,我得确认配置文件的正确位置。通常,配置文件可能在Redis的安装目录下,比如/etc/redis/redis.conf,或者是用户自己创建的某个路径。用户需要确保这个路径确实存在,并且他们有读取权限。如果路径不对,启动会失败,这时候需要检查路径是否正确,或者是否拼写错误。 然后,具体的命令应该是这样的:redis-server /path/to/redis.conf。这里需要把/path/to/替换成实际的文件路径。比如,如果配置文件在/etc/redis/redis.conf,那么命令就是redis-server /etc/redis/redis.conf。这一步是否正确呢?可能还需要注意权限问题,如果用户没有足够的权限,可能需要用sudo来执行。 另外,启动后如何确认Redis是否真的在使用指定的配置呢?用户可能需要检查日志,或者使用redis-cli连接后执行CONFIG GET命令来查看当前配置的参数。例如,检查dir配置项是否和配置文件中的一致,可以运行CONFIG GET dir。 还有可能出现的问题包括配置文件本身的语法错误,这会导致Redis启动失败。这时候需要查看启动时的错误信息,通常是输出到终端或者日志文件中,根据错误提示进行修正。比如,如果配置文件中某个参数拼写错误,或者值不符合要求,Redis会指出具体哪一行有问题。 另外,如果用户想要以后台模式运行,应该在配置文件中设置daemonize为yes,或者启动时加上--daemonize yes参数。不过,最好是在配置文件中设置,这样启动命令更简洁。 总结一下,步骤应该是:1. 准备好正确的配置文件;2. 使用redis-server命令指定该文件路径启动3. 验证配置是否生效。同时,注意处理可能出现的权限、路径和配置文件语法问题。</think>以下是Redis 5.0.3以指定配置文件启动的详细步骤: --- ### 一、基本启动命令格式 使用`redis-server`可执行文件后接配置文件的绝对路径: ```shell $ redis-server /你的路径/redis.conf ``` 示例(假设配置文件在/etc/redis目录下): ```shell $ redis-server /etc/redis/redis.conf ``` --- ### 二、关键操作步骤 1. **验证配置文件存在性** ```shell $ ls -l /你的路径/redis.conf ``` 需确认输出结果包含文件且权限可读 2. **启动时附加参数(可选)** 可在命令末尾添加`--参数名 值`覆盖配置文件中的设置: ```shell $ redis-server /etc/redis/redis.conf --port 6380 --daemonize yes ``` 3. **后台运行配置** 建议在配置文件中设置: ```conf daemonize yes ``` 或启动时追加参数: ```shell $ redis-server /etc/redis/redis.conf --daemonize yes ``` --- ### 三、验证配置生效 1. **查看运行参数** 通过`redis-cli`连接后执行: ```shell $ redis-cli 127.0.0.1:6379> CONFIG GET dir 1) "dir" 2) "/data/redis" # 此处应显示配置文件中指定的目录 ``` 2. **检查启动日志** 启动时输出的日志会显示加载的配置文件路径: ```log # 正常启动时会出现类似提示 oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo Configuration loaded ``` --- ### 四、常见问题处理 | 问题现象 | 解决方案 | |---------|----------| | `Fatal error loading the config file` | 检查配置文件语法:`$ redis-server /path/redis.conf --test` | | `Permission denied` | 添加执行权限:`$ sudo chmod +x /path/redis.conf` | | 配置修改未生效 | 重启Redis服务:`$ redis-cli shutdown && redis-server /path/redis.conf` | --- ### 五、最佳实践建议 1. 生产环境推荐使用完整路径指定配置文件 2. 不同实例应使用独立配置文件 3. 修改配置后建议先验证语法: ```shell $ redis-check-config /path/redis.conf ``` 通过以上步骤即可正确使用指定配置文件启动Redis服务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值