Redis 缓存服务配置与使用
缓存服务器Couchbase另外一种选择Redis
documentation
http://redis.io/documentation
http://redis.cn/documentation.html
Redis 命令参考
http://redisdoc.com/
$ yum install tcl
$ wget http://download.redis.io/releases/redis-3.0.2.tar.gz
$ tar xzf redis-3.0..tar.gz
$ cd redis-3.0.
$ make
make test
You need 'tclsh8.5' in order to run the Redis test
yum install tcl
$ src/redis-server
[root@localhost redis-3.0.2]# src/redis-server
25946:C 02 Jul 11:02:26.749 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.2 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 25946
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
25946:M 02 Jul 11:02:26.751 # Server started, Redis version 3.0.2
25946:M 02 Jul 11:02:26.751 # 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.
25946:M 02 Jul 11:02:26.751 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
25946:M 02 Jul 11:02:26.751 * The server is now ready to accept connections on port 6379
警告:过量使用内存设置为0!在低内存环境下,后台保存可能失败。为了修正这个问题,请在/etc/sysctl.conf 添加一项 'vm.overcommit_memory = 1' ,然后重启(或者运行命令'sysctl vm.overcommit_memory=1' )使其生效。
$ vi /etc/sysctl.conf
vm.overcommit_memory =:wq
$ sysctl vm.overcommit_memory=
$echo never > /sys/kernel/mm/transparent_hugepage/enabled $ echo > /proc/sys/net/core/somaxconn
#查看进程
ps -ef | grep redis
#杀死进程
kill -9 25946
redis.conf 配置
#守护进程启动
daemonize yes
#数据文件路径
dir /opt/data/
#日志文件路径
logfile "/opt/data/redis.log"
#缓存数据名称
dbfilename dump.rdb
#启动服务
src/redis-server /opt/redis-3.0.2/redis.conf
$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"
redis> exit
#关闭服务
$ src/redis-cli shutdown
持久化(persistence)
RDB 持久化可以在指定的时间间隔内生成数据集的时间点快照(point-in-time snapshot)。
AOF 持久化记录服务器执行的所有写操作命令,并在服务器启动时,通过重新执行这些命令来还原数据集。 AOF 文件中的命令全部以 Redis 协议的格式来保存,新命令会被追加到文件的末尾。 Redis 还可以在后台对 AOF 文件进行重写(rewrite),使得 AOF 文件的体积不会超出保存数据集状态所需的实际大小。
Redis 还可以同时使用 AOF 持久化和 RDB 持久化。 在这种情况下, 当 Redis 重启时, 它会优先使用 AOF 文件来还原数据集, 因为 AOF 文件保存的数据集通常比 RDB 文件所保存的数据集更完整。
复制(Replication)
http://redisdoc.com/topic/replication.html
配置一个从服务器非常简单,只要在配置文件中增加以下的这一行就可以了:
slaveof 192.168.1.1 6379
另外一种方法是调用 SLAVEOF 命令输入主服务器的 IP 和端口,然后同步就会开始:
127.0.0.1:6379> SLAVEOF 172.23.100.220 6379
OK
#salve日志
redisdemo@021rjsh17217s:/opt/redis-3.0.2$ sudo src/redis-server /opt/redis-3.0.2/redis.conf
28971:M 02 Jul 13:51:57.192 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.2 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 28971
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
28971:M 02 Jul 13:51:57.193 # Server started, Redis version 3.0.2
28971:M 02 Jul 13:51:57.194 # 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.
28971:M 02 Jul 13:51:57.194 # 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.
28971:M 02 Jul 13:51:57.194 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
28971:M 02 Jul 13:51:57.194 * The server is now ready to accept connections on port 6379
28971:S 02 Jul 13:56:04.572 * SLAVE OF 172.23.100.220:6379 enabled (user request)
28971:S 02 Jul 13:56:04.960 * Connecting to MASTER 172.23.100.220:6379
28971:S 02 Jul 13:56:04.960 * MASTER <-> SLAVE sync started
28971:S 02 Jul 13:56:04.961 * Non blocking connect for SYNC fired the event.
28971:S 02 Jul 13:56:04.962 * Master replied to PING, replication can continue...
28971:S 02 Jul 13:56:04.962 * Partial resynchronization not possible (no cached master)
28971:S 02 Jul 13:56:04.963 * Full resync from master: 3179db3e14a2f3abc534bc0dc28a7c025d3dd259:1
28971:S 02 Jul 13:56:05.070 * MASTER <-> SLAVE sync: receiving 40 bytes from master
28971:S 02 Jul 13:56:05.071 * MASTER <-> SLAVE sync: Flushing old data
28971:S 02 Jul 13:56:05.071 * MASTER <-> SLAVE sync: Loading DB in memory
28971:S 02 Jul 13:56:05.071 * MASTER <-> SLAVE sync: Finished with success
#master日志
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.2 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 26132
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
26132:M 02 Jul 11:23:14.445 # Server started, Redis version 3.0.2
26132:M 02 Jul 11:23:14.445 * DB loaded from disk: 0.000 seconds
26132:M 02 Jul 11:23:14.445 * The server is now ready to accept connections on port 6379
26132:M 02 Jul 13:43:39.602 * 1 changes in 900 seconds. Saving...
26132:M 02 Jul 13:43:39.602 * Background saving started by pid 26692
26692:C 02 Jul 13:43:39.608 * DB saved on disk
26692:C 02 Jul 13:43:39.608 * RDB: 0 MB of memory used by copy-on-write
26132:M 02 Jul 13:43:39.704 * Background saving terminated with success
26132:M 02 Jul 14:10:20.543 * Slave 172.23.100.217:6379 asks for synchronization
26132:M 02 Jul 14:10:20.543 * Full resync requested by slave 172.23.100.217:6379
26132:M 02 Jul 14:10:20.543 * Starting BGSAVE for SYNC with target: disk
26132:M 02 Jul 14:10:20.544 * Background saving started by pid 26797
26797:C 02 Jul 14:10:20.549 * DB saved on disk
26797:C 02 Jul 14:10:20.550 * RDB: 0 MB of memory used by copy-on-write
26132:M 02 Jul 14:10:20.650 * Background saving terminated with success
26132:M 02 Jul 14:10:20.650 * Synchronization with slave 172.23.100.217:6379 succeeded
集群
http://www.oschina.net/p/codis
客户端
j2cache
http://www.oschina.net/p/j2cache
http://my.oschina.net/tinyframework/blog/390484
StackExchange.Redis
https://github.com/StackExchange/StackExchange.Redis
REFER:
Redis 启动警告错误解决http://skly-java.iteye.com/blog/2167400
Redis (二) 配置http://blog.csdn.net/chenggong2dm/article/details/8533206
Redis Sentinel集群方案--单机测试http://luyx30.blog.51cto.com/1029851/1349027
redis sentinel 主从切换(failover)解决方案,详细配置http://blog.mkfree.com/posts/5257683d479e1dd72e7c1b4e
Redis.conf 配置文件详解
http://h2ex.com/207谈Twitter的百TB级Redis缓存实践
http://h2ex.com/193
Redis 缓存服务配置与使用的更多相关文章
- 高级运维(六):源码安装Redis缓存服务、常用Redis数据库操作指令、配置Redis主从服务器
一.源码安装Redis缓存服务 目标: 本案例要求先快速搭建好一台Redis服务器,并测试该缓存服务器: 1> 设置变量test,值为123 2> 查看变量test的值 3> 设置计 ...
- Windows Azure Redis 缓存服务
8月20日,Windows Azure (中国版)开始提供Redis缓存服务,比较国际版的Microsoft Azure晚了差不多一年的时间.说实话,微软真不应该将这个重要的功能delay这么长时间, ...
- Linux系统下Redis缓存安装配置
Redis是一个高性能的key-value数据库,现时越来越多企业与应用使用Redis作为缓存服务器.楼主是一枚JAVA后端程序员,也算是半个运维工程师了.在Linux服务器上搭建Redis,怎么可以 ...
- 【转载】Redis Sentinel服务配置
转载地址:http://blog.csdn.net/vtopqx/article/details/49247285 redis官网文档:http://www.redis.cn/topics/senti ...
- Redis缓存服务搭建及实现数据读写
发现博客园中好多大牛在介绍自己的开源项目是很少用到缓存,比如Memcached.Redis.mongodb等,今天得空抽时间把Redis缓存研究了一下,写下来总结一下,跟大家一起分享 一下.由于小弟水 ...
- Redis缓存服务搭建及实现数据读写--转载
来自 http://www.cnblogs.com/lc-chenlong/p/3218157.html 1. 下载安装Redis 下载地址:https://github.com/MSOpenTec ...
- Redis缓存服务搭建及实现数据读写 - Eric.Chen
发现博客园中好多大牛在介绍自己的开源项目是很少用到缓存,比如Memcached.Redis.mongodb等,今天得空抽时间把Redis缓存研究了一下,写下来总结一下,跟大家一起分享 一下.由于小弟水 ...
- Key-value数据库:Redis缓存服务
Redis 是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.其提供了多种主流语言的客户端,方便使用:同时Redis支持主 ...
- 【Azure Redis 缓存 Azure Cache For Redis】在创建高级层Redis(P1)集成虚拟网络(VNET)后,如何测试VNET中资源如何成功访问及配置白名单的效果
当使用Azure Redis高级版时候,为了能更好的保护Redis的安全,启用了虚拟网路,把Redis集成在Azure中的虚拟网络,只能通过虚拟网络VENT中的资源进行访问,而公网是不可以访问的.但是 ...
随机推荐
- 解决普通用户sudo时出现/usr/bin/sudo must be owned by uid 0 and have the setuid bit set
一:因为之前误操作使用sudo chmod -R 777 /usr命令修改了usr文件的所有者导致了此问题: 二:网上说需要进入recovery mode,经过自己的测试是不需要的: 三:步骤(只需登 ...
- AngularJS实战之Controller之间的通信
我们时常会在不同controller之间进行通信,接下来就介绍三种controller之间的通信方式 一.使用$on.$emit和$broadcast进行controller通信 虽然AngularJ ...
- ActiveMQ -5.9和jms-1.1源码下载
ActiveMQ-5.9和jms-1.1源码下载:见附件
- 【慕课网实战】Spark Streaming实时流处理项目实战笔记二之铭文升级版
铭文一级: 第二章:初识实时流处理 需求:统计主站每个(指定)课程访问的客户端.地域信息分布 地域:ip转换 Spark SQL项目实战 客户端:useragent获取 Hadoop基础课程 ==&g ...
- git服务器使用
服务器版本:CentOS6.3 root用户密码:123456 服务器地址:192.168.1.125 搭建Git服务器参考:搭建Git服务器 使用git服务器首先要克隆仓库,即添加一个远程仓库,参考 ...
- Ubuntu 12.04 下安装 JDK 7
原文链接:http://hi.baidu.com/sanwer/item/370a23330a6a7b23b3c0c533 方法一1.下载 JDK 7从http://www.oracle.com/te ...
- Linux常用备份恢复工具
在 Linux 中可以通过各种各样的方法来执行备份.所涉及的技术从非常简单的脚本驱动的方法,到精心设计的商业化软件.备份可以保存到远程网络设备.磁带驱动器和其他可移动媒体上.备份可以是基于文件的或基于 ...
- QT中的线程与事件循环理解(2)
1. Qt多线程与Qobject的关系 每一个 Qt 应用程序至少有一个事件循环,就是调用了QCoreApplication::exec()的那个事件循环.不过,QThread也可以开启事件循环.只不 ...
- HDU2844买表——多重背包初探
HDU2844买表多重背包问题题目大意都不大好懂,是利用手头上的硬币看看能组合出多少种价格,也就是跑完背包,看看有多少背包符合要求 剩下的就是多重背包的问题了1.第一个处理办法就是直接当01背包进行存 ...
- iOS 5 故事板进阶(1)
译自<iOS 5 by tutorials> 在上一章,你已经学习了故事板的基本用法.包括如何向故事板中添加 View Controller,通过 segues 切换 View Contr ...