Redis安装 For CentOS6.4_64

 

Redis安装 For CentOS6.4_64

分类: linux服务篇   291人阅读   评论(0)   收藏   举报

目录(?)[+]

下载

获取Redis源码

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

[html]   view plain copy
  1. cd /usr/src/  
  2. wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz  

解压

[html]   view plain copy
  1. tar -zxvf redis-2.6.14.tar.gz  
  2. cd redis-2.6.14  

测试

[html]   view plain copy
  1. [root@dev redis-2.6.14]# ls  
  2. 00-RELEASENOTES  CONTRIBUTING  deps     Makefile   README      runtest        src    utils  
  3. BUGS             COPYING       INSTALL  MANIFESTO  redis.conf  sentinel.conf  tests  
  4. [root@dev redis-2.6.14]# ./runtest  //测试运行  
  5. You need tcl 8.5 or newer in order to run the Redis test    //缺包tcl 8.5的支持  
  6. [root@dev redis-2.6.14]# yum list|grep tcl  
  7. db4-tcl.x86_64                            4.7.25-17.el6               CentOS6.4   
  8. graphviz-tcl.x86_64                       2.26.0-10.el6               CentOS6.4   
  9. libpurple-tcl.x86_64                      2.7.9-5.el6.2               CentOS6.4   
  10. postgresql-pltcl.x86_64                   8.4.13-1.el6_3              CentOS6.4   
  11. rrdtool-tcl.x86_64                        1.3.8-6.el6                 CentOS6.4   
  12. ruby-tcltk.x86_64                         1.8.7.352-7.el6_2           CentOS6.4   
  13. setools-libs-tcl.x86_64                   3.3.7-4.el6                 CentOS6.4   
  14. sqlite-tcl.x86_64                         3.6.20-1.el6                CentOS6.4   
  15. tcl.i686                                  1:8.5.7-6.el6               CentOS6.4   
  16. tcl.x86_64                                1:8.5.7-6.el6               CentOS6.4 //yum中有tcl包此处直接yum安装之  
  17. tcl-brlapi.x86_64                         0.5.4-7.el6                 CentOS6.4   
  18. tcl-devel.i686                            1:8.5.7-6.el6               CentOS6.4   
  19. tcl-devel.x86_64                          1:8.5.7-6.el6               CentOS6.4   
  20. tcl-pgtcl.x86_64                          1.6.2-3.el6                 CentOS6.4   
  21. tclx.i686                                 8.4.0-15.el6                CentOS6.4   
  22. tclx.x86_64                               8.4.0-15.el6                CentOS6.4   
  23. tclx-devel.i686                           8.4.0-15.el6                CentOS6.4   
  24. tclx-devel.x86_64                         8.4.0-15.el6                CentOS6.4   
  25. xchat-tcl.x86_64                          1:2.8.8-1.el6               CentOS6.4  
  26. <pre name="code" class="html">[root@dev redis-2.6.14]# yum -y install ctl.x86_64</pre>  

如果没有yum源的话可以去 此处 download

安装

[html]   view plain copy
  1. # make  
  2. ...//此处略去N个字  
  3. # make test  
  4. ...  
  5. \o/ All tests passed without errors!  
  6.   
  7. Cleanup: may take some time... OK  
  8. make[1]: Leaving directory `/usr/src/redis-2.6.14/src'   //install OK  
  9.   
  10. # cd /usr/src/  
  11. # mv /usr/src/redis-2.6.14 /usr/local/redis  
  12. # cd /usr/local/redis/  
  13. [root@dev redis]# src/redis-server   
  14. [28586] 21 Oct 15:50:14.705 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf  
  15. [28586] 21 Oct 15:50:14.707 * Max number of open files set to 10032     //可以指定配置文件 src/redis-server /path/to/redis.conf              _._                                                    
  16.            _.-``__ ''-._                                                //文件的最大打开数是10032   
  17.       _.-``    `.  `_.  ''-._           Redis 2.6.14 (00000000/0) 64 bit  
  18.   .-`` .-```.  ```\/    _.,_ ''-._                                     
  19.  (    '      ,       .-`  | `,    )     Running in stand alone mode  
  20.  |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379  
  21.  |    `-._   `._    /     _.-'    |     PID: 28586  
  22.   `-._    `-._  `-./  _.-'    _.-'                                     
  23.  |`-._`-._    `-.__.-'    _.-'_.-'|                                    
  24.  |    `-._`-._        _.-'_.-'    |           http://redis.io          
  25.   `-._    `-._`-.__.-'_.-'    _.-'                                     
  26.  |`-._`-._    `-.__.-'    _.-'_.-'|                                    
  27.  |    `-._`-._        _.-'_.-'    |                                    
  28.   `-._    `-._`-.__.-'_.-'    _.-'                                     
  29.       `-._    `-.__.-'    _.-'                                         
  30.           `-._        _.-'                                             
  31.               `-.__.-'                                                 
  32.   
  33. [28586] 21 Oct 15:50:14.709 # Server started, Redis version 2.6.14  
  34. [28581] 21 Oct 15:47:05.658 # 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.  
  35. [28586] 21 Oct 15:50:14.709 * The server is now ready to accept connections on port 6379  
  36. //[28581]内核参数vm.overcommit_memory这个目前是0 应该设置成1  
  37.   
  38. # echo "vm.overcommit_memory = 1>> /etc/sysctl.conf && sysctl -p            //解决28581的问题  
  39. # vi /etc/security/limits.conf        //解决28586 在此文件中加入如下内容  
  40. * soft nofile 387300    #此处的内容只要大于它所警告的10032就可以  
  41. * hard nofile 387300  
  42.   
  43. # ulimit -n 387300     //让参数立即生效  
  44. # ulimit -n  
  45. 387300  
  46. # src/redis-server /usr/local/redis/redis.conf  //启动服务 所有的警告都消失  

配置

[html]   view plain copy
  1. # pwd  
  2. /usr/local/redis  
  3. # cat redis.conf   
  4. daemonize yes         //后台运行  
  5. pidfile /var/run/redis.pid  
  6. port 6379  
  7. timeout 0  
  8. tcp-keepalive 0  
  9. loglevel notice  
  10. logfile stdout  
  11. databases 16  
  12. save 900 1  
  13. save 300 10  
  14. save 60 10000  
  15. stop-writes-on-bgsave-error yes  
  16. rdbcompression yes  
  17. rdbchecksum yes  
  18. dbfilename dump.rdb  
  19. dir ./  
  20. slave-serve-stale-data yes  
  21. slave-read-only yes  
  22. repl-disable-tcp-nodelay no  
  23. slave-priority 100  
  24. appendonly no  
  25. appendfsync everysec  
  26. no-appendfsync-on-rewrite no  
  27. auto-aof-rewrite-percentage 100  
  28. auto-aof-rewrite-min-size 64mb  
  29. lua-time-limit 5000  
  30. slowlog-log-slower-than 10000  
  31. slowlog-max-len 128  
  32. hash-max-ziplist-entries 512  
  33. hash-max-ziplist-value 64  
  34. list-max-ziplist-entries 512  
  35. list-max-ziplist-value 64  
  36. set-max-intset-entries 512  
  37. zset-max-ziplist-entries 128  
  38. zset-max-ziplist-value 64  
  39. activerehashing yes  
  40. client-output-buffer-limit normal 0 0 0  
  41. client-output-buffer-limit slave 256mb 64mb 60  
  42. client-output-buffer-limit pubsub 32mb 8mb 60  
  43. hz 10  
  44. aof-rewrite-incremental-fsync yes  
  45.   
  46. # src/redis-server /usr/local/redis/redis.conf  //用/usr/local/redis/redis.conf配置文件启动服务  

测试

[html]   view plain copy
  1. # netstat -nlp|grep 6379  
  2. tcp        0      0 0.0.0.0:6379                0.0.0.0:*                   LISTEN      28612/src/redis-ser   
  3. # ps -ef|grep redis |grep -v grep  
  4. root     28612     1  0 16:11 ?        00:00:00 src/redis-server /usr/local/redis/redis.conf  
  5. # src/redis-cli   
  6. redis 127.0.0.1:6379> ping  
  7. PONG  
  8. redis 127.0.0.1:6379> set foo br       //存入一个key是foo = valne是br的的值  
  9. OK                                     //存入成功  
  10. redis 127.0.0.1:6379> get foo          //获取key是foo的value  
  11. "br"  
  12. redis 127.0.0.1:6379> incr cai           
  13. (integer) 1  
  14. redis 127.0.0.1:6379> incr cai  
  15. (integer) 2  
  16. redis 127.0.0.1:6379> help              //帮助 帮助方法  
  17. redis-cli 2.6.14  
  18. Type: "help @<group>" to get a list of commands in <group>  
  19.       "help <command>" for help on <command>  
  20.       "help <tab>" to get a list of possible help topics  
  21.       "quit" to exit  
  22.   
  23. redis 127.0.0.1:6379> help set   //例如  
  24.   
  25.   SET key value [EX seconds] [PX milliseconds] [NX|XX]  
  26.   summary: Set the string value of a key  
  27.   since: 1.0.0  
  28.   group: string  
  29.   
  30. redis 127.0.0.1:6379> help incr  
  31.   
  32.   INCR key  
  33.   summary: Increment the integer value of a key by one  
  34.   since: 1.0.0  
  35.   group: string  
  36.   
  37. redis 127.0.0.1:6379> quit          //退出  

附加

[html]   view plain copy
  1. redis-benchmark -h localhost -p 6379 -c 100 -n 100000   
  2. 100个并发连接,100000个请求,检测host为localhost 端口为6379的redis服务性能测试  
  3.   
  4. redis-cli -h localhost -p 6379 monitor   
  5. Dump all the received requests in real time;   
  6. 监控host为localhost,端口为6379,redis的连接及读写操作   
  7.   
  8. redis-cli -h localhost -p 6380 info   
  9. 提供host为localhost,端口为6379,redis服务的统计信息   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值