引言:Redis是目前最为流行的缓存服务,本文将详细介绍如何搭建RedisLive的监控环境。本文安装之后的功能仍不完整,无实时的数据显示。
1. 环境介绍
Centos 4.7.4, Python 2.6.6,
检查环境信息, 打开命令行:
[abcd@ZC_VM_10_100_138_xx ~]$ cat /proc/version
Linux version 2.6.32-431.el6.x86_64 (mockbuild@c6b8.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) ) #1 SMP Fri Nov 22 03:15:09 UTC 2013
检查Linux下的Python版本:
[abcd@ZC_VM_10_100_138_xx redismonitor]$ python
Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
由此可以目前基本的环境信息。
2. Redis Live介绍
项目主页地址: https://github.com/nkrode/RedisLive
功能强大,界面直观,非常的好用,同时可以支持多个Redis实例的监控。
3. Python Pip的安装
pip是Python中的包管理工具,这里首先确认其是否已经安装,如未安装,则优先安装。先下载安装文件。
[abcd@ZC_VM_10_100_138_xx redismonitor]$ wget https://bootstrap.pypa.io/get-pip.py
--2016-09-27 14:22:32-- https://bootstrap.pypa.io/get-pip.py
正在解析主机 bootstrap.pypa.io... 151.101.16.175
正在连接 bootstrap.pypa.io|151.101.16.175|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1524722 (1.5M) [text/x-python]
正在保存至: “get-pip.py”20% [======================================> ] 310,803 101K/s eta(英国中部时22% [===========================================> ] 343,571 102K/s eta(英国中部时24% [===============================================> ] 376,339 103K/s eta(英国中部时25% [=================================================> ] 392,723 99.4K/s eta(英国中部时27% [=====================================================> ] 425,491 101K/s eta(英国中部时28% [=======================================================> ] 441,875 98.0K/s eta(英国中部时30% [=========================================================> ] 458,259 96.2K/s eta(英国中部时32% [==============================================================> ] 491,027 96.7K/s eta(英国中部时33% [================================================================> ] 507,411 95.0K/s eta(英国中部时34% [==================================================================> ] 523,795 92.9K/s eta(英国中部时35% [====================================================================> ] 540,179 91.2K/s eta(英国中部时36% [======================================================================> ] 556,563 85.9K/s eta(英国中部时37% [========================================================================> ] 572,947 84.7K/s eta(英国中部时38% [==========================================================================> ] 589,331 81.3K/s eta(英国中部时39% [============================================================================> ] 605,715 79.1K/s eta(英国中部时40% [==============================================================================> ] 622,099 75.2K/s eta(英国中部时41% [=================================================================================> ] 638,483 69.9K/s eta(英国中部时42% [===================================================================================>
在下载完成之后,进行安装PIP:
[abcd@ZC_VM_10_100_138_xx redismonitor]# python get-pip.py
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
Collecting pip
/tmp/tmpixMJsm/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
/tmp/tmpixMJsm/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.Downloading pip-8.1.2-py2.py3-none-any.whl (1.2MB)5% |██ | 71kB 14kB/s eta 0:01:20
安装成功后,检查pip是否安装成功,打开teminal,
[abcd@ZC_VM_10_100_138_xxx redismonitor]# pipUsage: pip <command> [options]Commands:install Install packages.download Download packages.uninstall Uninstall packages.freeze Output installed packages in requirements format.list List installed packages.show Show information about installed packages.search Search PyPI for packages.wheel Build wheels from your requirements.hash Compute hashes of package archives.completion A helper command used for command completionhelp Show help for commands.General Options:-h, --help Show help.--isolated Run pip in an isolated mode, ignoring environment variables and user configuration.-v, --verbose Give more output. Option is additive, and can be used up to 3 times.-V, --version Show version and exit.-q, --quiet Give less output.--log <path> Path to a verbose appending log.--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.--retries <retries> Maximum number of retries each connection should attempt (default 5 times).--timeout <sec> Set the socket timeout (default 15 seconds).--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup.--trusted-host <hostname> Mark this host as trusted, even though it does not have valid or any HTTPS.--cert <path> Path to alternate CA bundle.--client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.--cache-dir <dir> Store the cache data in <dir>.--no-cache-dir Disable the cache.--disable-pip-version-checkDon't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index
上述信息标识安装成功。
参考内容: https://pip.pypa.io/en/latest/installing/
4. 安装redislive
安装依赖包:
- tornado
pip install tornado
- redis.py
pip install redis
- python-dateutil
pip install python-dateutil
安装argparse,由于当前python版本小于2.7
- argparse
pip install argparse
git clone https://github.com/kumarnitin/RedisLive.git
5. 配置RedisLive
复制redis-live.conf的配置信息:
[abcd@ZC_VM_10_100_138_xxx src]$ vi redis-live.conf{"RedisServers":[{ # 添加 monitor target redis"server": "10.100.141.40","port" : 6394,"password":"abcdpwd"}],#将当前的存储模式设置sqlite,也可以为redis"DataStoreType" : "sqlite",# 存储用的redis server"RedisStatsServer":{"server" : "ec2-184-72-166-144.compute-1.amazonaws.com","port" : 6385},"SqliteStatsStore" :{ "path": "monitor.sqlite" #注意这里一定要设置到db目录下的sqlite文件,且需要绝对路径,否则将无法找到表,# 出现no table 'monitor'之类的错误信息。}
}
~
保存修改内容即可。
6. 启动RedisLive
进入RedisLive目录, 启动如下命令:
>>> ./redis-live.py 启动执行
>>> ./redis-monitor.py --duration=20 #间隔20s之后执行该命令
说明: 这里只是执行了一次该monitor命令,无法做到循环执行,这是让我非常困惑的地方,为什么没有做成循环执行呢,还是我没有发现其设置选项吗?
参考资料:http://www.nkrode.com/article/real-time-dashboard-for-redis
7. 场景错误信息:
a. 错误信息:OperationError : no table 'monitor'
[E 160927 15:16:35 web:1548] Uncaught exception GET /api/topkeys?from=Tue%2C+20+Sep+2016+07%3A16%3A37+GMT&to=Tue%2C+27+Sep+2016+07%3A16%3A37+GMT&server=10.100.141.40%3A6394 (10.10.153.123)HTTPServerRequest(protocol='http', host='10.100.138.82:8888', method='GET', uri='/api/topkeys?from=Tue%2C+20+Sep+2016+07%3A16%3A37+GMT&to=Tue%2C+27+Sep+2016+07%3A16%3A37+GMT&server=10.100.141.40%3A6394', version='HTTP/1.1', remote_ip='10.10.153.123', headers={'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3', 'Accept-Encoding': 'gzip, deflate', 'Host': '10.100.138.82:8888', 'Accept': 'application/json, text/javascript, */*; q=0.01', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0', 'Connection': 'keep-alive', 'X-Requested-With': 'XMLHttpRequest', 'Referer': 'http://10.100.138.82:8888/index.html'})Traceback (most recent call last):File "/usr/lib64/python2.6/site-packages/tornado/web.py", line 1467, in _executeresult = method(*self.path_args, **self.path_kwargs)File "/home/yxgly/redismonitor/RedisLive/src/api/controller/TopKeysController.py", line 25, in getfor data in self.stats_provider.get_top_keys_stats(server, start, end):File "/home/yxgly/redismonitor/RedisLive/src/dataprovider/sqliteprovider.py", line 178, in get_top_keys_statsreturn [[r[0], r[1]] for r in c.execute(query, values)]OperationalError: no such table: monitor
[E 160927 15:16:35 web:1971] 500 GET /api/topkeys?from=Tue%2C+20+Sep+2016+07%3A16%3A37+GMT&to=Tue%2C+27+Sep+2016+07%3A16%3A37+GMT&server=10.100.141.40%3A6394 (10.10.153.123) 3.13ms
解决办法: 将sqlite模式下的file Location设置到db/redislive.sqlite,重新启动即可。
8. 总结
这是一次失败的环境搭建,因为这里还暂时没有做到实时的显示信息,后续还需要继续研究和实验。
9. 参考资料:
- RedisLive的安装: http://sofar.blog.51cto.com/353572/1369266
- Redis Stat/RedisLive http://ckl893.blog.51cto.com/8827818/1791301
- 官方带评论的安装指南 http://www.nkrode.com/article/real-time-dashboard-for-redis
- redis监控方案 https://my.oschina.net/guol/blog/182265
- crontab http://www.cnblogs.com/ccdc/archive/2012/06/01/2529471.html