本文共 3391 字,大约阅读时间需要 11 分钟。
开始之前,先来百度下redis是什么?
Redis 是一个高性能的key-value数据库。 redis的出现,很大程度补偿了memcached这类keyvalue存储的不足,在部分场合可以对关系数据库起到很好的补充作用。它提供了Python,Ruby,Erlang,PHP客户端,使用很方便!
简单来说,redis和memcache这种东西用的好,可以很好的减轻后端数据库的压力,作为DBA,不能一成不变的停留在自己的一亩三分地上啊!
对于memcache和redis这种类似缓存数据库的东西,需要加大监控的力度,memcache的监控相对容易实现,可以借助memcache.php对memcache的使用情况用饼图的方式显示出来,还可以用nagios对memcache的端口或进程做实时监控,同样redis也可以对端口和进程做实时监控,但要看更多的信息,则需要用相应的监控软件,本文主要介绍在centos6.3上redmon和redis-live两款开源软件的使用情况,前者基于ruby,后者则基于python,从部署难度和功能上,我更青睐于后者!
一:redmon的安装和使用
1:安装rvm,rvm是ruby version manager的缩写,ruby语言是鬼子弄出来的,虽然不是程序员,我也一直不待见,真心觉得难用!
- #bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
- # echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
2:查看可用的ruby版本
- # /usr/local/rvm/bin/rvm list known
3:通过rvm安装ruby
- # /usr/local/rvm/bin/rvm install 1.9.2
- # /usr/local/rvm/bin/rvm alias create default ruby-1.9.2-p320
- # /usr/local/rvm/bin/rvm list
- rvm rubies
-
- =* ruby-1.9.2-p320 [ x86_64 ]
-
- # => - current
- # =* - current && default
- # * - default
-
- # ruby -v
- ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-linux]
4:通过gem安装bundler
- # gem install bundler
5:通过git获取redmon源代码并安装
- # git clone
Initialized empty Git repository in /root/redmon/.git/
remote: Counting objects: 975, done.
remote: Compressing objects: 100% (506/506), done.
remote: Total 975 (delta 483), reused 928 (delta 436)
Receiving objects: 100% (975/975), 2.57 MiB | 714 KiB/s, done.
Resolving deltas: 100% (483/483), done.
- # grep -A 4 'option :redis_url' redmon/bin/redmon option :redis_url, :short => '-r URL', :long => '--redis URL', :default => 'redis://192.168.1.78:6377', :description => "The Redis url for monitor (default: redis://192.168.1.78:6377)"
- # grep -A 9 'class Config' redmon/lib/redmon/config.rb class Config DEFAULTS = { :namespace => 'redmon', :redis_url => 'redis://192.168.1.78:6377', :app => true, :worker => true, :web_interface => ['0.0.0.0', 4567], :poll_interval => 10, :secure => false }
- # cd redmon/ # bundle exec /root/redmon/bin/redmon >> Maximum connections set to 1024 >> Listening on 0.0.0.0:4567, CTRL+C to stop [12-09-25 11:03:20] listening on http#0.0.0.0:4567
6:web接口情况,使用上存在无法添加对多个redis实例的监控
redmon监控安装参考下列文章,在此感谢作者分享!
二:redis-live的安装和使用,同redmon相比,添加多个redis实例监控显得非常容易!而且实时性强,大赞!
- # wget http://dl.fedoraproject.org/pub/epel/6/x86_64/python-pip-0.8-1.el6.noarch.rpm
- # rpm -ivh python-pip-0.8-1.el6.noarch.rpm
- # pip-python install tornado
- # pip-python install redis
- # pip-python install python-dateutil
- # pip-python install argparse
-
- # git clone https://github.com/kumarnitin/RedisLive.git
- Initialized empty Git repository in /root/RedisLive/.git/
- remote: Counting objects: 715, done.
- remote: Compressing objects: 100% (377/377), done.
- remote: Total 715 (delta 338), reused 699 (delta 323)
- Receiving objects: 100% (715/715), 2.59 MiB | 353 KiB/s, done.
- Resolving deltas: 100% (338/338), done.
-
- # cd RedisLive/src
- # cat redis-live.conf
- {
- "RedisServers":
- [
- {
- "server" : "192.168.1.78",
- "port" : 6377
- },
-
- {
- "server" : "192.168.1.78",
- "port" : 6380
- },
-
- {
- "server" : "192.168.1.78",
- "port" : 6381
- }
- ],
-
-
- "DataStoreType" : "sqlite",
-
- "RedisStatsServer":
- {
- "server" : "127.0.0.1",
- "port" : 6381
- }
- }
-
- # ./redis-monitor.py --duration 120 &
- # ./redis-live.py &
- # netstat -ntpl |grep python
- tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 6652/python
- tcp 0 0 :::8888 :::* LISTEN 6652/python
web接口情况:
参考官方文档:
转载地址:http://alsix.baihongyu.com/