> CentOS > CentOS教程 >

CentOS6安装RedisLive

RedisLive是一款开源的基于WEB的reids的监控工具,以WEB的形式展现出redis中的key的情况,实例数据等信息!

RedisLive在github上的地址:https://github.com/nkrode/RedisLive

安装配置:

RedisLive是使用Python语言写的,所以需要安装Python环境,安装python模块我这里使用的pip,如果没有pip需要手动安装一下,当然也可以使用easy_install来安装模块

 
 
yum install python-pip

安装相关的python模块

 
pip install tornado
pip install redis
pip install python-dateutil
pip install argparse

下载源码:

 
yum install git  //如果没有git命令需要运行安装git
git clone https://github.com/kumarnitin/RedisLive.git

编辑配置文件

 
cd RedisLive/src/
vi redis-live.conf  //文件内容如下
{
        "RedisServers":
        [
                {
                        "server": "22.4.8.10",
                        "port" : 6379
                },
 
                {
                        "server": "23.4.2.7",
                        "port" : 6379
                }
        ],
 
        "DataStoreType" : "sqlite",
        "SqliteStatsStore":
                {
        }
}

一定要注意逗号和对齐方式,不然可能会报错,上面已经是最简洁的写法了,没有使用redis来存储数据,而是使用了sqlite。如果redis有密码,可以加一条password即可

启动监控和服务

 
nohup ./redis-monitor.py --quiet --duration=120 &
nohup ./redis-live.py --log_file_prefix=/var/log/redislive/redislive.log &

redis-monitor.py是运行的监控脚本,使用–quiet来指定安静模式,即如果有报错,不把错误信息输出来。使用–duration来指定多长时间去取一次reids的数据

reids-live.py这个是运行了一个简单的web服务,使用–log_file_prefix来指定日志文件存储的地方,更多详细的参数可以使用–help来查看。默认监听的端口是8888.

访问 http://you-host-address/index.html   如果不加index.html会报403

redis-live

 

错误及解决:

错误一、

 
# ./redis-monitor.py --duration=120
Traceback (most recent call last):
  File "./redis-monitor.py", line 297, in <module>
    monitor.run(duration)
  File "./redis-monitor.py", line 247, in run
    redis_servers = settings.get_redis_servers()
  File "/var/www/html/RedisLive/src/api/util/settings.py", line 14, in get_redis_servers
    config = get_settings()
  File "/var/www/html/RedisLive/src/api/util/settings.py", line 10, in get_settings
    return json.load(config)
  File "/usr/lib64/python2.6/json/__init__.py", line 267, in load
    parse_constant=parse_constant, **kw)
  File "/usr/lib64/python2.6/json/__init__.py", line 307, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.6/json/decoder.py", line 319, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python2.6/json/decoder.py", line 336, in raw_decode
    obj, end = self._scanner.iterscan(s, **kw).next()
  File "/usr/lib64/python2.6/json/scanner.py", line 55, in iterscan
    rval, next_pos = action(m, context)
  File "/usr/lib64/python2.6/json/decoder.py", line 183, in JSONObject
    value, end = iterscan(s, idx=end, context=context).next()
  File "/usr/lib64/python2.6/json/scanner.py", line 55, in iterscan
    rval, next_pos = action(m, context)
  File "/usr/lib64/python2.6/json/decoder.py", line 217, in JSONArray
    value, end = iterscan(s, idx=end, context=context).next()
  File "/usr/lib64/python2.6/json/scanner.py", line 55, in iterscan
    rval, next_pos = action(m, context)
  File "/usr/lib64/python2.6/json/decoder.py", line 198, in JSONObject
    raise ValueError(errmsg("Expecting property name", s, end - 1))
ValueError: Expecting property name: line 12 column 3 (char 142)

出现这个问题是配置文件里有问题,一般是写,号了或者多,号,请更正一下即可

 

错误二、

 
KeyError: 'SqliteStatsStore'  详细信息如下
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib64/python2.6/threading.py", line 532, in __bootstrap_inner
    self.run()
  File "./redis-monitor.py", line 97, in run
    stats_provider = RedisLiveDataProvider.get_provider()
  File "/opt/RedisLive/src/dataprovider/dataprovider.py", line 22, in get_provider
    return sqliteprovider.RedisStatsProvider()
  File "/opt/RedisLive/src/dataprovider/sqliteprovider.py", line 11, in __init__
    stats = settings.get_sqlite_stats_store()
  File "/opt/RedisLive/src/api/util/settings.py", line 28, in get_sqlite_stats_store
    return config["SqliteStatsStore"]
KeyError: 'SqliteStatsStore'
 
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib64/python2.6/threading.py", line 532, in __bootstrap_inner
    self.run()
  File "./redis-monitor.py", line 188, in run
    stats_provider = RedisLiveDataProvider.get_provider()
  File "/opt/RedisLive/src/dataprovider/dataprovider.py", line 22, in get_provider
    return sqliteprovider.RedisStatsProvider()
  File "/opt/RedisLive/src/dataprovider/sqliteprovider.py", line 11, in __init__
    stats = settings.get_sqlite_stats_store()
  File "/opt/RedisLive/src/api/util/settings.py", line 28, in get_sqlite_stats_store
    return config["SqliteStatsStore"]
KeyError: 'SqliteStatsStore'

出现以上错误是没写有存储实例,如果使用的是sqlite存储,要写上

 
"SqliteStatsStore":
    {
    }

如果是redis,要写上redis实例相关的信息。

(责任编辑:IT)