Redis安装部署维护

Redis是个高性能的key-value数据库,它的key具备丰富的数据结构:string,hash,list set和sorted set。做为NOSQL,比起memcache之类,不单单key数据结构丰富,并且具备持久化的功能,而且可以支持主从复制,很方便构建集群。 redis高性能很大程度上源于它是个内存型数据库,它的高性能表如今:set操做11w/s,get操做8.1w/s,与其余类型数据库性能差别,能够 而参考:http://timyang.net/data/mcdb-tt-redis/   。为了进一步加深对redis的理解总结,我打算写个redis系列的博客。这里主要谈谈redis安装部署及运维维护。redis

一、下载安装数据库

[plain] view plaincopy服务器

  1. [root@xsf003 tool]# wget -c http://redis.googlecode.com/files/redis-2.4.17.tar.gz    #下载  数据结构

  2. [root@xsf003 tool]# tar -zxvf redis-2.4.17.tar.gz   #解压  运维

  3. [root@xsf003 tool]# cd redis-2.4.17  异步

  4. [root@xsf003 redis-2.4.17]# make  #编译  工具

  5. [root@xsf003 redis-2.4.17]# make install #安装  性能

安装完毕,经常使用工具会自动拷贝到/user/loca/bin目录下。作为服务器,咱们经常还须要把redis设置成开机自启动,源码包中有个很好用的脚本,执行脚步根据提示输入便可。this

[plain] view plaincopygoogle

  1. [root@xsf003 redis-2.4.17]# cd utils/  

  2. [root@xsf003 utils]# ./install_server.sh   

  3. Welcome to the redis service installer  

  4. This script will help you easily set up a running redis server  

  5.   

  6.   

  7. Please select the redis port for this instance: [6379]   

  8. Selecting default: 6379  

  9. Please select the redis config file name [/etc/redis/6379.conf]   

  10. Selected default - /etc/redis/6379.conf  

  11. Please select the redis log file name [/var/log/redis_6379.log]   

  12. Selected default - /var/log/redis_6379.log  

  13. Please select the data directory for this instance [/var/lib/redis/6379]   

  14. Selected default - /var/lib/redis/6379  

  15. Please select the redis executable path [/usr/local/bin/redis-server]   

  16. Copied /tmp/6379.conf => /etc/init.d/redis_6379  

  17. Installing service...  

  18. Successfully added to chkconfig!  

  19. Successfully added to runlevels 345!  

  20. Starting Redis server...  

  21. Installation successful!  


     注意执行install_server.sh,须要先进入utils目录,否则脚本会报错,提示找不到相应文件。安装完服务,redis自动启动,能够用ps命令查看到相关信息:

[plain] view plaincopy

  1. [root@xsf003 utils]# ps -ef | grep redis  

  2. root      4554     1  0 10:55 ?        00:00:02 /usr/local/bin/redis-server /etc/redis/6379.conf  

  3. root      4564  2808  0 10:59 pts/0    00:00:00 grep redis  


二、手动启动关闭服务

[plain] view plaincopy

  1. [root@xsf003 utils]# /etc/init.d/redis_6379 stop   #关闭  

  2. [root@xsf003 utils]# /etc/init.d/redis_6379 start  #启动  

也能够用下面相似的命令直接启动关闭redis服务:

[plain] view plaincopy

  1. /usr/local/bin/redis-server /etc/redis/redis.conf   #指定配置文件 启动  

  2. /usr/local/bin/redis-cli -p 6379 shutdown   # 关闭,若是默认端口6379 能够直接 /usr/local/bin/redis-cli shutdown  

    

   三、经过客户端命令行工具链接redis服务查看redis相关信息

a)链接

[plain] view plaincopy

  1. [root@xsf003 utils]# redis-cli   

  2. redis 127.0.0.1:6379>  


b)其余指令

[plain] view plaincopy

  1. redis 127.0.0.1:6379> info  #查看server版本内存使用链接等信息  

  2.   

  3. redis 127.0.0.1:6379> client list  #获取客户链接列表  

  4.   

  5. redis 127.0.0.1:6379> client kill 127.0.0.1:33441 #终止某个客户端链接  

  6.   

  7. redis 127.0.0.1:6379> dbsize #当前保存key的数量  

  8.   

  9. redis 127.0.0.1:6379> save #当即保存数据到硬盘  

  10.   

  11. redis 127.0.0.1:6379> bgsave #异步保存数据到硬盘  

  12.   

  13. redis 127.0.0.1:6379> flushdb #当前库中移除全部key  

  14.   

  15. redis 127.0.0.1:6379> flushall #移除全部key从全部库中  

  16.   

  17. redis 127.0.0.1:6379> lastsave #获取上次成功保存到硬盘的unix时间戳  

  18.   

  19. redis 127.0.0.1:6379> monitor #实时监测服务器接收到的请求  

  20.   

  21. redis 127.0.0.1:6379> slowlog len #查询慢查询日志条数  

  22. (integer) 3   

  23.   

  24. redis 127.0.0.1:6379> slowlog get #返回全部的慢查询日志,最大值取决于slowlog-max-len配置  

  25.   

  26. redis 127.0.0.1:6379> slowlog get 2 #打印两条慢查询日志  

  27.   

  28. redis 127.0.0.1:6379> slowlog reset #清空慢查询日志信息  


经过以上操做,单台服务器基本跑起来了,不事后面的路还很长很长。。。。


参考文章:

http://redis.io/topics/introduction

http://timyang.net/data/mcdb-tt-redis/

http://redis.io/commands#server

http://code.google.com/p/redis/

相关文章
相关标签/搜索