﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-liuyf8688-文章分类-Redis</title><link>http://www.blogjava.net/liuyf8688/category/53878.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 10 Sep 2013 12:30:11 GMT</lastBuildDate><pubDate>Tue, 10 Sep 2013 12:30:11 GMT</pubDate><ttl>60</ttl><item><title>Redis配置文件redis.conf</title><link>http://www.blogjava.net/liuyf8688/articles/403818.html</link><dc:creator>风沙</dc:creator><author>风沙</author><pubDate>Sun, 08 Sep 2013 07:23:00 GMT</pubDate><guid>http://www.blogjava.net/liuyf8688/articles/403818.html</guid><wfw:comment>http://www.blogjava.net/liuyf8688/comments/403818.html</wfw:comment><comments>http://www.blogjava.net/liuyf8688/articles/403818.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liuyf8688/comments/commentRss/403818.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liuyf8688/services/trackbacks/403818.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 复制到这边，备查（2.6.16）Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->&nbsp; 1&nbsp;#&nbsp;Redis&nbsp;configuration&nbsp;file&nbsp;example&nbsp;&nbsp;2&nbsp...&nbsp;&nbsp;<a href='http://www.blogjava.net/liuyf8688/articles/403818.html'>阅读全文</a><img src ="http://www.blogjava.net/liuyf8688/aggbug/403818.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liuyf8688/" target="_blank">风沙</a> 2013-09-08 15:23 <a href="http://www.blogjava.net/liuyf8688/articles/403818.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Failed opening .rdb for saving: Permission denied</title><link>http://www.blogjava.net/liuyf8688/articles/403801.html</link><dc:creator>风沙</dc:creator><author>风沙</author><pubDate>Sat, 07 Sep 2013 16:38:00 GMT</pubDate><guid>http://www.blogjava.net/liuyf8688/articles/403801.html</guid><wfw:comment>http://www.blogjava.net/liuyf8688/comments/403801.html</wfw:comment><comments>http://www.blogjava.net/liuyf8688/articles/403801.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liuyf8688/comments/commentRss/403801.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liuyf8688/services/trackbacks/403801.html</trackback:ping><description><![CDATA[查看Redis后台，有如下错误日志：<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; ">1</span>&nbsp;<span style="color: #800000; font-weight: bold; ">[</span><span style="color: #800000; ">2963</span><span style="color: #800000; font-weight: bold; ">]</span>&nbsp;07&nbsp;Sep&nbsp;09:15:07.053&nbsp;*&nbsp;10&nbsp;changes&nbsp;in&nbsp;300&nbsp;seconds.&nbsp;Saving<img src="http://www.blogjava.net/Images/dot.gif" alt="" /><br /><span style="color: #008080; ">2</span>&nbsp;<span style="color: #800000; font-weight: bold; ">[</span><span style="color: #800000; ">2963</span><span style="color: #800000; font-weight: bold; ">]</span>&nbsp;07&nbsp;Sep&nbsp;09:15:07.055&nbsp;*&nbsp;Background&nbsp;saving&nbsp;started&nbsp;by&nbsp;pid&nbsp;3143<br /><span style="color: #008080; ">3</span>&nbsp;<span style="color: #800000; font-weight: bold; ">[</span><span style="color: #800000; ">3143</span><span style="color: #800000; font-weight: bold; ">]</span>&nbsp;07&nbsp;Sep&nbsp;09:15:07.058&nbsp;#&nbsp;Failed&nbsp;opening&nbsp;.rdb&nbsp;for&nbsp;saving:&nbsp;Permission&nbsp;denied<br /><span style="color: #008080; ">4</span>&nbsp;<span style="color: #800000; font-weight: bold; ">[</span><span style="color: #800000; ">2963</span><span style="color: #800000; font-weight: bold; ">]</span>&nbsp;07&nbsp;Sep&nbsp;09:15:07.156&nbsp;#&nbsp;Background&nbsp;saving&nbsp;error</div><br />根据提示，可以看出是权限问题。<br />进入redis.conf配置文件。<br />搜索dir，找到如下内容：<br /><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; ">&nbsp;1</span>&nbsp;#&nbsp;The&nbsp;working&nbsp;directory.<br /><span style="color: #008080; ">&nbsp;2</span>&nbsp;#<br /><span style="color: #008080; ">&nbsp;3</span>&nbsp;#&nbsp;The&nbsp;DB&nbsp;will&nbsp;be&nbsp;written&nbsp;inside&nbsp;this&nbsp;directory,&nbsp;with&nbsp;the&nbsp;filename&nbsp;specified<br /><span style="color: #008080; ">&nbsp;4</span>&nbsp;#&nbsp;above&nbsp;using&nbsp;the&nbsp;'dbfilename'&nbsp;configuration&nbsp;directive.<br /><span style="color: #008080; ">&nbsp;5</span>&nbsp;#&nbsp;<br /><span style="color: #008080; ">&nbsp;6</span>&nbsp;#&nbsp;The&nbsp;Append&nbsp;Only&nbsp;File&nbsp;will&nbsp;also&nbsp;be&nbsp;created&nbsp;inside&nbsp;this&nbsp;directory.<br /><span style="color: #008080; ">&nbsp;7</span>&nbsp;#&nbsp;<br /><span style="color: #008080; ">&nbsp;8</span>&nbsp;#&nbsp;Note&nbsp;that&nbsp;you&nbsp;must&nbsp;specify&nbsp;a&nbsp;directory&nbsp;here,&nbsp;not&nbsp;a&nbsp;file&nbsp;name.<br /><span style="color: #008080; ">&nbsp;9</span>&nbsp;dir&nbsp;./</div><br />如果是./表示：运行reides命令的目录(例如，$redis_home中，执行./bin/redis-server etc/redis.conf命令，./则代表的是$redis_home)。<br /><br />查看当前用户对dir所配置的路径是否有写权限。<br /><br />调整权限后，应该能看到如下信息：<br /><br /><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; ">1</span>&nbsp;<span style="color: #800000; font-weight: bold; ">[</span><span style="color: #800000; ">3223</span><span style="color: #800000; font-weight: bold; ">]</span>&nbsp;07&nbsp;Sep&nbsp;09:29:57.007&nbsp;*&nbsp;10&nbsp;changes&nbsp;in&nbsp;300&nbsp;seconds.&nbsp;Saving<img src="http://www.blogjava.net/Images/dot.gif" alt="" /><br /><span style="color: #008080; ">2</span>&nbsp;<span style="color: #800000; font-weight: bold; ">[</span><span style="color: #800000; ">3223</span><span style="color: #800000; font-weight: bold; ">]</span>&nbsp;07&nbsp;Sep&nbsp;09:29:57.008&nbsp;*&nbsp;Background&nbsp;saving&nbsp;started&nbsp;by&nbsp;pid&nbsp;3270<br /><span style="color: #008080; ">3</span>&nbsp;<span style="color: #800000; font-weight: bold; ">[</span><span style="color: #800000; ">3270</span><span style="color: #800000; font-weight: bold; ">]</span>&nbsp;07&nbsp;Sep&nbsp;09:29:57.028&nbsp;*&nbsp;DB&nbsp;saved&nbsp;on&nbsp;disk<br /><span style="color: #008080; ">4</span>&nbsp;<span style="color: #800000; font-weight: bold; ">[</span><span style="color: #800000; ">3270</span><span style="color: #800000; font-weight: bold; ">]</span>&nbsp;07&nbsp;Sep&nbsp;09:29:57.029&nbsp;*&nbsp;RDB:&nbsp;6&nbsp;MB&nbsp;of&nbsp;memory&nbsp;used&nbsp;by&nbsp;copy-on-write<br /><span style="color: #008080; ">5</span>&nbsp;<span style="color: #800000; font-weight: bold; ">[</span><span style="color: #800000; ">3223</span><span style="color: #800000; font-weight: bold; ">]</span>&nbsp;07&nbsp;Sep&nbsp;09:29:57.112&nbsp;*&nbsp;Background&nbsp;saving&nbsp;terminated&nbsp;with&nbsp;success</div><br />表示成功写入磁盘文件，即该问题解决。<br />现在查看dir所配置的目录下应该有dump.rdb文件。<img src ="http://www.blogjava.net/liuyf8688/aggbug/403801.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liuyf8688/" target="_blank">风沙</a> 2013-09-08 00:38 <a href="http://www.blogjava.net/liuyf8688/articles/403801.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WARNING overcommit_memory is set to 0! </title><link>http://www.blogjava.net/liuyf8688/articles/403797.html</link><dc:creator>风沙</dc:creator><author>风沙</author><pubDate>Sat, 07 Sep 2013 15:31:00 GMT</pubDate><guid>http://www.blogjava.net/liuyf8688/articles/403797.html</guid><wfw:comment>http://www.blogjava.net/liuyf8688/comments/403797.html</wfw:comment><comments>http://www.blogjava.net/liuyf8688/articles/403797.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liuyf8688/comments/commentRss/403797.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liuyf8688/services/trackbacks/403797.html</trackback:ping><description><![CDATA[如果细心的同学，可能会发现Redis启动时，应该会给出如下警告信息：<br /><br /><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; ">1</span>&nbsp;<span style="color: #800000; font-weight: bold; ">[</span><span style="color: #800000; ">29446</span><span style="color: #800000; font-weight: bold; ">]</span>&nbsp;07&nbsp;Sep&nbsp;08:14:14.162&nbsp;#&nbsp;<span style="background-color: #ffff00;">WARNING&nbsp;overcommit_memory&nbsp;is&nbsp;set&nbsp;to&nbsp;0!&nbsp;</span>Background&nbsp;save&nbsp;may&nbsp;fail&nbsp;under&nbsp;low&nbsp;memory&nbsp;condition.&nbsp;To&nbsp;fix&nbsp;this&nbsp;issue&nbsp;add&nbsp;'vm.overcommit_memory&nbsp;=&nbsp;1'&nbsp;to&nbsp;/etc/sysctl.conf&nbsp;and&nbsp;then&nbsp;reboot&nbsp;or&nbsp;run&nbsp;the&nbsp;command&nbsp;'sysctl&nbsp;vm.overcommit_memory=1'&nbsp;for&nbsp;this&nbsp;to&nbsp;take&nbsp;effect.</div><br />顺便提一下：overcommit_memory的作用。<br /><br /><div><span style="background-color: #c0c0c0;">overcommit_memory:</span></div><div>&nbsp;</div><div><span style="background-color: #c0c0c0;">This value contains a flag that enables memory overcommitment.</span></div><div>&nbsp;</div><div><span style="background-color: #c0c0c0;">When this flag is 0, the kernel attempts to estimate the amount</span></div><div><span style="background-color: #c0c0c0;">of free memory left when userspace requests more memory.</span></div><div>&nbsp;</div><div><span style="background-color: #c0c0c0;">When this flag is 1, the kernel pretends there is always enough</span></div><div><span style="background-color: #c0c0c0;">memory until it actually runs out.</span></div><div>&nbsp;</div><div><span style="background-color: #c0c0c0;">When this flag is 2, the kernel uses a "never overcommit"</span></div><div><span style="background-color: #c0c0c0;">policy that attempts to prevent any overcommit of memory.</span></div><div>&nbsp;</div><div><span style="background-color: #c0c0c0;">This feature can be very useful because there are a lot of</span></div><div><span style="background-color: #c0c0c0;">programs that malloc() huge amounts of memory "just-in-case"</span></div><div><span style="background-color: #c0c0c0;">and don't use much of it.</span><br /><br /><div><span style="background-color: #c0c0c0;">The default value is 0. (很容易联想到上面的：</span><span style="font-size: 13px; background-color: #ffff00;">WARNING&nbsp;overcommit_memory&nbsp;is&nbsp;set&nbsp;to&nbsp;0!</span><span style="background-color: #c0c0c0;">)</span></div><div>&nbsp;</div><div><span style="background-color: #c0c0c0;">See Documentation/vm/overcommit-accounting and</span></div><div><span style="background-color: #c0c0c0;">security/commoncap.c::cap_vm_enough_memory() for more information.</span></div><div><span style="background-color: #c0c0c0;">==============================================================</span></div><div><span style="background-color: #c0c0c0;">overcommit_ratio:</span></div><div><span style="background-color: #c0c0c0;">When overcommit_memory is set to 2, the committed address</span></div><div><span style="background-color: #c0c0c0;">space is not permitted to exceed swap plus this percentage</span></div><div><span style="background-color: #c0c0c0;">of physical RAM. &nbsp;See above.</span></div><br />明白了原因，那就根据提示进行修改吧！<br /><br />方法1：只影响本次<br />1.验证系统中overcommit_memory的值，执行如下命令<br /><div><span style="background-color: #c0c0c0;">sysctl -n vm.overcommit_memory<br /></span><br />2.设置overcommit_memory的值为1<br /><span style="background-color: #c0c0c0;">sysctl -w vm.overcommit_memory=1<br /></span><br />3.验证系统中overcommit_memory的值是否被改成了1<br /><div><span style="background-color: #c0c0c0;">sysctl -n vm.overcommit_memory<br /><br /></span><span style="background-color: #ffffff;">方法2:(需重启)<br />1.将vm.overcommit_memory = 1添加到/etc/sysctl.conf中<br />2.重启电脑<br /></span><span style="background-color: #ffffff;"><br /><br /></span></div></div>重新运行redis，验证警告是否消失</div><img src ="http://www.blogjava.net/liuyf8688/aggbug/403797.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liuyf8688/" target="_blank">风沙</a> 2013-09-07 23:31 <a href="http://www.blogjava.net/liuyf8688/articles/403797.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Redis安装</title><link>http://www.blogjava.net/liuyf8688/articles/403792.html</link><dc:creator>风沙</dc:creator><author>风沙</author><pubDate>Sat, 07 Sep 2013 12:15:00 GMT</pubDate><guid>http://www.blogjava.net/liuyf8688/articles/403792.html</guid><wfw:comment>http://www.blogjava.net/liuyf8688/comments/403792.html</wfw:comment><comments>http://www.blogjava.net/liuyf8688/articles/403792.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liuyf8688/comments/commentRss/403792.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liuyf8688/services/trackbacks/403792.html</trackback:ping><description><![CDATA[<div><div>Where to find complete Redis documentation?</div><div>-------------------------------------------</div><div></div><div>This README is just a fast "quick start" document. You can find more detailed</div><div>documentation at http://redis.io</div><div></div><div>Building Redis</div><div>--------------</div><div></div><div>Redis can be compiled and used on Linux, OSX, OpenBSD, NetBSD, FreeBSD.</div><div>We support big endian and little endian architectures.</div><div></div><div>It may compile on Solaris derived systems (for instance SmartOS) but our</div><div>support for this platform is "best effort" and Redis is not guaranteed to</div><div>work as well as in Linux, OSX, and *BSD there.</div><div></div><div>It is as simple as:</div><div></div><div>&nbsp; &nbsp; % make</div><div></div><div>You can run a 32 bit Redis binary using:</div><div></div><div>&nbsp; &nbsp; % make 32bit</div><div></div><div>After building Redis is a good idea to test it, using:</div><div></div><div>&nbsp; &nbsp; % make test</div><div></div><div>Fixing problems building 32 bit binaries</div><div>---------</div><div></div><div>If after building Redis with a 32 bit target you need to rebuild it</div><div>with a 64 bit target, or the other way around, you need to perform a</div><div>"make distclean" in the root directory of the Redis distribution.</div><div></div><div>In case of build errors when trying to build a 32 bit binary of Redis, try</div><div>the following steps:</div><div></div><div>* Install the packages libc6-dev-i386 (also try g++-multilib).</div><div>* Try using the following command line instead of "make 32bit":</div><div></div><div>&nbsp; &nbsp; make CFLAGS="-m32 -march=native" LDFLAGS="-m32"</div><div></div><div>Allocator</div><div>---------</div><div></div><div>Selecting a non-default memory allocator when building Redis is done by setting</div><div>the `MALLOC` environment variable. Redis is compiled and linked against libc</div><div>malloc by default, with the exception of jemalloc being the default on Linux</div><div>systems. This default was picked because jemalloc has proven to have fewer</div><div>fragmentation problems than libc malloc.</div><div></div><div>To force compiling against libc malloc, use:</div><div></div><div>&nbsp; &nbsp; % make MALLOC=libc</div><div></div><div>To compile against jemalloc on Mac OS X systems, use:</div><div></div><div>&nbsp; &nbsp; % make MALLOC=jemalloc</div><div></div><div>Verbose build</div><div>-------------</div><div></div><div>Redis will build with a user friendly colorized output by default.</div><div>If you want to see a more verbose output use the following:</div><div></div><div>&nbsp; &nbsp; % make V=1</div><div></div><div>Running Redis</div><div>-------------</div><div></div><div>To run Redis with the default configuration just type:</div><div></div><div>&nbsp; &nbsp; % cd src</div><div>&nbsp; &nbsp; % ./redis-server</div><div>&nbsp; &nbsp;&nbsp;</div><div>If you want to provide your redis.conf, you have to run it using an additional</div><div>parameter (the path of the configuration file):</div><div></div><div>&nbsp; &nbsp; % cd src</div><div>&nbsp; &nbsp; % ./redis-server /path/to/redis.conf</div><div></div><div>It is possible to alter the Redis configuration passing parameters directly</div><div>as options using the command line. Examples:</div><div></div><div>&nbsp; &nbsp; % ./redis-server --port 9999 --slaveof 127.0.0.1 6379</div><div>&nbsp; &nbsp; % ./redis-server /etc/redis/6379.conf --loglevel debug</div><div></div><div>All the options in redis.conf are also supported as options using the command</div><div>line, with exactly the same name.</div><div></div><div>Playing with Redis</div><div>------------------</div><div></div><div>You can use redis-cli to play with Redis. Start a redis-server instance,</div><div>then in another terminal try the following:</div><div></div><div>&nbsp; &nbsp; % cd src</div><div>&nbsp; &nbsp; % ./redis-cli</div><div>&nbsp; &nbsp; redis&gt; ping</div><div>&nbsp; &nbsp; PONG</div><div>&nbsp; &nbsp; redis&gt; set foo bar</div><div>&nbsp; &nbsp; OK</div><div>&nbsp; &nbsp; redis&gt; get foo</div><div>&nbsp; &nbsp; "bar"</div><div>&nbsp; &nbsp; redis&gt; incr mycounter</div><div>&nbsp; &nbsp; (integer) 1</div><div>&nbsp; &nbsp; redis&gt; incr mycounter</div><div>&nbsp; &nbsp; (integer) 2</div><div>&nbsp; &nbsp; redis&gt;&nbsp;</div><div></div><div>You can find the list of all the available commands here:</div><div></div><div>&nbsp; &nbsp; http://redis.io/commands</div><div></div><div>Installing Redis</div><div>-----------------</div><div></div><div>In order to install Redis binaries into /usr/local/bin just use:</div><div></div><div>&nbsp; &nbsp; % make install</div><div></div><div>You can use "make PREFIX=/some/other/directory install" if you wish to use a</div><div>different destination.</div><div></div><div>Make install will just install binaries in your system, but will not configure</div><div>init scripts and configuration files in the appropriate place. This is not</div><div>needed if you want just to play a bit with Redis, but if you are installing</div><div>it the proper way for a production system, we have a script doing this</div><div>for Ubuntu and Debian systems:</div><div></div><div>&nbsp; &nbsp; % cd utils</div><div>&nbsp; &nbsp; % ./install_server</div><div></div><div>The script will ask you a few questions and will setup everything you need</div><div>to run Redis properly as a background daemon that will start again on</div><div>system reboots.</div><div></div><div>You'll be able to stop and start Redis using the script named</div><div>/etc/init.d/redis_&lt;portnumber&gt;, for instance /etc/init.d/redis_6379.</div><div></div><div>Code contributions</div><div>---</div><div></div><div>Note: by contributing code to the Redis project in any form, including sending</div><div>a pull request via Github, a code fragment or patch via private email or</div><div>public discussion groups, you agree to release your code under the terms</div><div>of the BSD license that you can find in the COPYING file included in the Redis</div><div>source distribution.</div><div></div><div>Please see the CONTRIBUTING file in this source distribution for more</div><div>information.</div><div></div><div>Enjoy!</div><div></div></div><img src ="http://www.blogjava.net/liuyf8688/aggbug/403792.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liuyf8688/" target="_blank">风沙</a> 2013-09-07 20:15 <a href="http://www.blogjava.net/liuyf8688/articles/403792.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>