Redis 无法正常关闭服务
前置知识:Redis最简单的基本命令:
1. 系统终端
./redis-server 启动redis服务
./redis-cli 启动redis客户端
./redis-cli shutdown 关闭redis服务
2. 在使用./redis-cli进入redis命令终端之后,
shutdown 关闭redis服务
save 保存存储至磁盘
set [key] [value] 对键[key]赋值[value]
get [key] 获取键[key]对应的值
问题描述:
Redis安装完成,使用./redis-server启动之后,运行./redis-cli进入redis终端,对键值的操作可正常完成,但shutdown与save会报错,具体在终端或者日志中体现为:
1. shutdown请求失败:
1550:M 02 Jan 18:22:48.778 # User requested shutdown...
1550:M 02 Jan 18:22:48.779 * Saving the final RDB snapshot before exiting.
1550:M 02 Jan 18:22:48.781 # Failed opening the RDB file dump.rdb (in server root dir /usr/share/redis/redis-3.2.6/src) for saving: Permission denied
1550:M 02 Jan 18:22:48.782 # Error trying to save the DB, can't exit.
2. save失败
1550:M 02 Jan 18:42:05.298 # Failed opening the RDB file dump.rdb (in server root dir /usr/share/redis/redis-3.2.6/src) for saving: Permission denied
shutdown和save失败的原因是一样的,对rdb文件dump.rdb的操作过程出现问题(虽然日志中显示permission denied,但不一定为权限问题,可能是目录或则文件无法生成等多方面)
解决方法:
综合考虑了以下两点(非常抱歉,因为两部分都同时修改后问题解决,所以无法确定是哪一点导致上述问题)
1. 在服务启动之后,日志信息有如下Warning显示:
1550:M 02 Jan 18:16:12.147 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1550:M 02 Jan 18:16:12.148 # Server started, Redis version 3.2.6
1550:M 02 Jan 18:16:12.148 # 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.
1550:M 02 Jan 18:16:12.148 # 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.
据此推测可能由于某些存储上的上限极低(上述日志貌似默认0了),导致创建文件失败,这里笔者理解为:没有创建大小为X的文件的权限导致permission denied
2. 根据报错日志显示rdb文件是建立在 /usr/share/redis/redis-3.2.6/src(即redis安装目录)下,但实际查看时此目录并木有rdb文件,即使redis是在系统的root用户下启动服务,shutdown和save依旧会出现上述error。所以感觉在这里没有文件权限的可能性应该不大,不过最后还是修改配置文件更新了rdb文件的默认生成目录。
操作:
1. 解决Warning
A. 终端root用户执行:sysctl vm.overcommit_memory=1
B. 终端root用户执行:echo never > /sys/kernel/mm/transparent_hugepage/enabled
C. 终端root用户执行:vim /etc/rc.local,在打开文件之后,将echo never > /sys/kernel/mm/transparent_hugepage/enabled加入在语句exit 0之前
2. 更改rdb文件默认路径
修改conf文件,在这里建议,复制一份新的conf文件,如test.conf,在test.conf进行修改,之后启动redis时,使用脚本./redis-server test.conf启动服务。
修改方式:在redis原来的解压目录下找到redis.conf文件(也可以在终端用命令locate redis.conf查找其位置),
打开后定位到如下位置:
# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir ./
将其中的"dir ./"修改为相应的目录,如"dir /home/distance/redis_dbfiles/"(这里需要注意最后的斜杠不能忘记,如果缺失斜杠可能会解析为文件而非目录),保存。
上述操作完成之后,可以正常save与shutdown。
Redis 无法正常关闭服务的更多相关文章
- windows下安装Redis并部署成服务
windows下安装Redis并部署成服务 Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件. 一:下载 下载地址: windows版本: http ...
- Redis Sentinel 高可用服务搭建
阅读目录: 关于 Redis 的概念 关于 Redis Sentinel 的概念 搭建 Redis Server(master) 搭建 Redis Server(slave) 搭建 Redis Sen ...
- 使用Windows命令行启动关闭服务(net,sc用法)
下面两个命令最好以管理员方式启动cmd窗口,否则出现权限问题. 1.net用于打开没有被禁用的服务, NET命令是功能强大的以命令行方式执行的工具. 它包含了管理网络环境.服务.用户.登陆大部分重要的 ...
- Linux 下的 Redis 安装 && 启动 && 关闭 && 卸载
转自https://blog.csdn.net/zgf19930504/article/details/51850594 Redis 在Linux 和 在Windows 下的安装是有很大的不同的,和通 ...
- mysql和redis加入到windows服务
mysql加入到windows服务: mysqld --install Mysql5.6 mysqld --remove mysql5.6 从windows的服务中删除mysql服务 net st ...
- 在Windows下将Redis注册为本地服务
当前redis版本:3.2.100 通常情况下我们可以通过 redis-server.exe 和配置文件启动redis服务 : redis-server.exe redis.windows.conf ...
- 【转载】Redis Sentinel 高可用服务架构搭建
作者:田园里的蟋蟀 出处:http://www.cnblogs.com/xishuai/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接. 阅读 ...
- Ubuntu 16.04设置Redis为开机自动启动服务
继上一篇文章http://www.cnblogs.com/EasonJim/p/7599941.html安装好Redis后,假设文件已经安装到/usr/local/redis目录下.假设我安装的版本为 ...
- CentOS 7.3 安装redis 4.0.2服务
CentOS 7.3 安装redis 4.0.2服务 1.下载解压 下载地址:/home/xiaoming/ wget http://download.redis.io/releases/redis- ...
随机推荐
- Eclipse中全局搜索和更替
Eclipse全局搜索步骤 使用快捷键"ctrl+H"打开文件搜索对话框,选择"File Search"标签,在Containing text中输入你需要搜索 ...
- JavaScript判断、循环、Map、Set
本文是笔者在看廖雪峰老师JavaScript教程时的个人总结 一些判断条件 JavaScript把null.undefined.0.NaN和空字符串''视为 ...
- acm系统开发笔记
时间: 2016/2/29 遇到的困难: 数据库配置的mysql和java(Date)不一致,出现下面错误 Date date = new Date(); SimpleDateFormat ...
- lesson32 Shopping for food
EMPLOYEE: undefined763cff06-f7fc-4a01-b5f8-c78a2f0110ae.mp3 Can I help you, Sir? 0先生,我能帮你吗? BOB: und ...
- 通过页面调用APP【H5与APP互通】
现在H5和App原生的内容原来越互通,所涉及的业务也越来越复杂和融合,所以如何互相之间方便的调用才是王道. 场景1 比如用hybrid获取地理位置和短信信息,这当然需要框架封装好,比如利用框架的bri ...
- React Native 获取网络数据
getMoviesFromApiAsync() { return fetch('http://facebook.github.io/react-native/movies.json') .then(( ...
- tcpdump 获取http请求url
There are tcpdump filters for HTTP GET & HTTP POST (or for both plus message body): Run man tcpd ...
- iPhone / iPad UI界面设计与图标设计的尺寸设计规范+安卓+网页
①iPhone的设计尺寸 iPhone界面尺寸: 设备 分辨率 状态栏高度 导航栏高度 标签栏(工具栏)高度 iPhone6 plus设计版 1242 × 2208 60px 132px 146px ...
- c# 获取 本周、本月、本季度、本年 的开始时间或结束时间
#region 获取 本周.本月.本季度.本年 的开始时间或结束时间 /// <summary> /// 获取结束时间 /// </summary> /// <param ...
- ros语音交互(四)移植科大讯飞语音识别到ros
将以前下载的的语音包的 samples/iat_record/的iat_record.c speech_recognizer.c speech_recognizer.c 拷贝到工程src中, linu ...