设为首页 收藏本站
查看: 791|回复: 0

[经验分享] Redis系列-安装部署维护篇

[复制链接]

尚未签到

发表于 2016-12-18 09:44:09 | 显示全部楼层 |阅读模式
  http://blog.csdn.net/love__coder/article/details/8271832
 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安装部署及运维维护。
1、下载安装
 
[plain] view plaincopy



  • [iyunv@xsf003 tool]# wget -c http://redis.googlecode.com/files/redis-2.4.17.tar.gz    #下载  
  • [iyunv@xsf003 tool]# tar -zxvf redis-2.4.17.tar.gz   #解压  
  • [iyunv@xsf003 tool]# cd redis-2.4.17  
  • [iyunv@xsf003 redis-2.4.17]# make  #编译  
  • [iyunv@xsf003 redis-2.4.17]# make install #安装  

  安装完毕,常用工具会自动拷贝到/user/loca/bin目录下。做为服务器,我们常常还需要把redis设置成开机自启动,源码包中有个很好用的脚本,执行脚步根据提示输入即可。
 
 
[plain] view plaincopy



  • [iyunv@xsf003 redis-2.4.17]# cd utils/  
  • [iyunv@xsf003 utils]# ./install_server.sh   
  • Welcome to the redis service installer  
  • This script will help you easily set up a running redis server  
  •   
  •   
  • Please select the redis port for this instance: [6379]   
  • Selecting default: 6379  
  • Please select the redis config file name [/etc/redis/6379.conf]   
  • Selected default - /etc/redis/6379.conf  
  • Please select the redis log file name [/var/log/redis_6379.log]   
  • Selected default - /var/log/redis_6379.log  
  • Please select the data directory for this instance [/var/lib/redis/6379]   
  • Selected default - /var/lib/redis/6379  
  • Please select the redis executable path [/usr/local/bin/redis-server]   
  • Copied /tmp/6379.conf => /etc/init.d/redis_6379  
  • Installing service...  
  • Successfully added to chkconfig!  
  • Successfully added to runlevels 345!  
  • Starting Redis server...  
  • Installation successful!  

     注意执行install_server.sh,需要先进入utils目录,不然脚本会报错,提示找不到相应文件。安装完服务,redis自动启动,可以用ps命令查看到相关信息:
 
[plain] view plaincopy



  • [iyunv@xsf003 utils]# ps -ef | grep redis  
  • root      4554     1  0 10:55 ?        00:00:02 /usr/local/bin/redis-server /etc/redis/6379.conf  
  • root      4564  2808  0 10:59 pts/0    00:00:00 grep redis  

  
2、手动启动关闭服务
 
 
[plain] view plaincopy



  • [iyunv@xsf003 utils]# /etc/init.d/redis_6379 stop   #关闭  
  • [iyunv@xsf003 utils]# /etc/init.d/redis_6379 start  #启动  

也可以用下面类似的命令直接启动关闭redis服务:
 
[plain] view plaincopy



  • /usr/local/bin/redis-server /etc/redis/redis.conf   #指定配置文件 启动  
  • /usr/local/bin/redis-cli -p 6379 shutdown   # 关闭,如果默认端口6379 可以直接 /usr/local/bin/redis-cli shutdown  

      
 
   3、通过客户端命令行工具连接redis服务查看redis相关信息
 
a)连接
 
[plain] view plaincopy



  • [iyunv@xsf003 utils]# redis-cli   
  • redis 127.0.0.1:6379>  

  
b)其他指令
 
 
[plain] view plaincopy



  • redis 127.0.0.1:6379> info  #查看server版本内存使用连接等信息  
  •   
  • redis 127.0.0.1:6379> client list  #获取客户连接列表  
  •   
  • redis 127.0.0.1:6379> client kill 127.0.0.1:33441 #终止某个客户端连接  
  •   
  • redis 127.0.0.1:6379> dbsize #当前保存key的数量  
  •   
  • redis 127.0.0.1:6379> save #立即保存数据到硬盘  
  •   
  • redis 127.0.0.1:6379> bgsave #异步保存数据到硬盘  
  •   
  • redis 127.0.0.1:6379> flushdb #当前库中移除所有key  
  •   
  • redis 127.0.0.1:6379> flushall #移除所有key从所有库中  
  •   
  • redis 127.0.0.1:6379> lastsave #获取上次成功保存到硬盘的unix时间戳  
  •   
  • redis 127.0.0.1:6379> monitor #实时监测服务器接收到的请求  
  •   
  • redis 127.0.0.1:6379> slowlog len #查询慢查询日志条数  
  • (integer) 3   
  •   
  • redis 127.0.0.1:6379> slowlog get #返回所有的慢查询日志,最大值取决于slowlog-max-len配置  
  •   
  • redis 127.0.0.1:6379> slowlog get 2 #打印两条慢查询日志  
  •   
  • 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/

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-315854-1-1.html 上篇帖子: Redis监控方案和查看 下篇帖子: 基于Redis缓存的Session共享测试
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表