`
sjsky
  • 浏览: 905757 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Redis的编译安装

 
阅读更多

   blog迁移至 :http://www.micmiu.com

 

Redis 官网:http://redis.io/

 

实验环境:

  • OS:centos6
  • 软件:redis2.4.4(截至本文的最新版本)

测试整个编译安装的基本过程如下:

 

[1].编译安装过程

    # wget http://redis.googlecode.com/files/redis-2.4.4.tar.gz

    # tar -zxvf redis-2.4.4.tar.gz

    # mv redis-2.4.4 /usr/local/

    # cd /usr/local/redis-2.4.4

   ps: 该软件的编译安装不需要执行 ./configure 和make install 命令

    # make

 

    如果看到有以下提示信息:

Hint: To run 'make test' is a good idea ;)

    再执行命令# make test

 

    应该会看到如下信息:

\o/ All tests passed without errors!

Cleanup: may take some time... OK

    上面的提示信息表示:测试没有错误都通过,编译成功

 

[2]. 配置:

 

    # cp src/redis-server /usr/local/bin

    # cp src/redis-benchmark /usr/local/bin

    # cp src/redis-cli /usr/local/bin

    # cp src/redis-check-dump /usr/local/bin

    # cp src/redis-check-aof /usr/local/bin

     这样以后就可以直接在shell窗口下调用这些命令了。

 

    复制配置文件redis.conf:

    # mkdir /usr/local/etc/redis

    # cp redis.conf /usr/local/etc/redis

 

    启动redis:

    # redis-server /usr/local/etc/redis/redis.conf

 

    控制台会看到如下信息:

[28335] 16 Dec 16:37:41 * Server started, Redis version 2.4.4
[28335] 16 Dec 16:37:41 # 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.
[28335] 16 Dec 16:37:41 * The server is now ready to accept connections on port 6379
[28335] 16 Dec 16:37:41 - 0 clients connected (0 slaves), 717480 bytes in use
[28335] 16 Dec 16:37:46 - 0 clients connected (0 slaves), 717480 bytes in use
[28335] 16 Dec 16:37:51 - 0 clients connected (0 slaves), 717480 bytes in use

    ps:默认配置中redis程序启动不是以后台守护进程的模式启动的

 

[3]. 修改配置文件:/usr/local/etc/redis/redis.conf

 

    具体的参数含义可以看conf文件中的注释,测试时只是简单修改了下面几个参数:

 

daemonize no => yes 是否后天守护进程
logfile stdout => /var/log/redis.log 日志文件
dir ./ => /var/db/redis 目录设置

   ps: 要确保你设置的目录已经存在 

 

    执行下面的测试命令:

# redis-server /usr/local/etc/redis/redis.conf
# redis-cli
redis 127.0.0.1:6379> set myblog "sjsky.iteye.com"
OK
redis 127.0.0.1:6379> get myblog
"sjsky.iteye.com"
redis 127.0.0.1:6379> shutdown
redis 127.0.0.1:6379> exit

   可以看到数据库的数据文件:

# ls -lh /var/db/redis/
总用量 4.0K
-rw-r--r--. 1 root root 36 12月 16 17:05 dump.rdb
 

   可以看到redis的日志文件如下:

# cat /var/log/redis.log
[28468] 16 Dec 17:04:53 * Server started, Redis version 2.4.4
[28468] 16 Dec 17:04:53 # 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.
[28468] 16 Dec 17:04:53 * DB loaded from disk: 0 seconds
[28468] 16 Dec 17:04:53 * The server is now ready to accept connections on port 6379
[28468] 16 Dec 17:04:53 - 0 clients connected (0 slaves), 717512 bytes in use
[28468] 16 Dec 17:04:58 - 0 clients connected (0 slaves), 717512 bytes in use
[28468] 16 Dec 17:05:01 - Accepted 127.0.0.1:54313
[28468] 16 Dec 17:05:03 - 1 clients connected (0 slaves), 726040 bytes in use
[28468] 16 Dec 17:05:08 - 1 clients connected (0 slaves), 726040 bytes in use
[28468] 16 Dec 17:05:13 - DB 0: 1 keys (0 volatile) in 4 slots HT.
[28468] 16 Dec 17:05:13 - 1 clients connected (0 slaves), 726296 bytes in use
[28468] 16 Dec 17:05:18 - DB 0: 1 keys (0 volatile) in 4 slots HT.
[28468] 16 Dec 17:05:18 - 1 clients connected (0 slaves), 726280 bytes in use
[28468] 16 Dec 17:05:20 # User requested shutdown...
[28468] 16 Dec 17:05:20 * Saving the final RDB snapshot before exiting.
[28468] 16 Dec 17:05:21 * DB saved on disk
[28468] 16 Dec 17:05:21 * Removing the pid file.
[28468] 16 Dec 17:05:21 # Redis is now ready to exit, bye bye...

 

    有关上面日志中的告警信息的说明:

# 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.

    这个告警信息是由于当内存分配策略设置为“0”时,启动会有警告提示,根据它的提示我们可以修改相应的配置文件/etc/sysctl.conf或者是通过sysctl命令设置,使之生效即可。

 

 

 

本文连接:http://sjsky.iteye.com/blog/1313886

 

 

转载请注明来自:Michael's blog @ http://sjsky.iteye.com



----------------------------- 分 ------------------------------ 隔 ------------------------------ 线 ------------------------------

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics