12【線上日誌分析】之RedisLive監控工具的詳細安裝

hackeruncle發表於2017-01-15

GitHub:


1.安裝python2.7.5 和pip
http://blog.itpub.net/30089851/viewspace-2132450/

2.下載RedisLive
[root@sht-sgmhadoopdn-04 app]# wget
[root@sht-sgmhadoopdn-04 app]# unzip master
[root@sht-sgmhadoopdn-04 app]# mv RedisLive-master RedisLive
[root@sht-sgmhadoopdn-04 app]# cd RedisLive/
[root@sht-sgmhadoopdn-04 RedisLive]# ll
total 20
drwxr-xr-x 2 root root 4096 Aug 20  2015 design
-rw-r--r-- 1 root root 1067 Aug 20  2015 MIT-LICENSE.txt
-rw-r--r-- 1 root root  902 Aug 20  2015 README.md
-rw-r--r-- 1 root root   58 Aug 20  2015 requirements.txt
drwxr-xr-x 7 root root 4096 Aug 20  2015 src
[root@sht-sgmhadoopdn-04 RedisLive]#

3.檢視版本要求(剛開始安裝沒注意版本,直接pip導致後面各種問題,所以請仔細看下面過程)
[root@sht-sgmhadoopdn-04 RedisLive]# cat requirements.txt
argparse==1.2.1
python-dateutil==1.5
redis
tornado==2.1.1

[root@sht-sgmhadoopdn-04 RedisLive]# cd ../

4.pip安裝環境要求
[root@sht-sgmhadoopdn-04 app]# pip install tornado
[root@sht-sgmhadoopdn-04 app]# pip install redis
[root@sht-sgmhadoopdn-04 app]# pip install python-dateutil
[root@sht-sgmhadoopdn-04 app]# pip install argparse


5.進入 /root/learnproject/app/RedisLive/src目錄,配置redis-live.conf檔案

[root@sht-sgmhadoopdn-04 app]# cd -
/root/learnproject/app/RedisLive
[root@sht-sgmhadoopdn-04 RedisLive]# cd src
[root@sht-sgmhadoopdn-04 src]# ll
total 40
drwxr-xr-x 4 root root 4096 Aug 20  2015 api
drwxr-xr-x 2 root root 4096 Aug 20  2015 dataprovider
drwxr-xr-x 2 root root 4096 Aug 20  2015 db
-rw-r--r-- 1 root root    0 Aug 20  2015 __init__.py
-rw-r--r-- 1 root root  381 Aug 20  2015 redis-live.conf.example
-rwxr-xr-x 1 root root 1343 Aug 20  2015 redis-live.py
-rwxr-xr-x 1 root root 9800 Aug 20  2015 redis-monitor.py
drwxr-xr-x 2 root root 4096 Aug 20  2015 util
drwxr-xr-x 4 root root 4096 Aug 20  2015 www
You have mail in /var/spool/mail/root
[root@sht-sgmhadoopdn-04 src]#
[root@sht-sgmhadoopdn-04 src]# cp redis-live.conf.example redis-live.conf
[root@sht-sgmhadoopdn-04 src]#
[root@sht-sgmhadoopdn-04 src]# vi redis-live.conf
{
        "RedisServers":
        [
                {
                        "server": "172.16.101.66",
                        "port" : 6379
                }

        ],

        "DataStoreType" : "redis",

        "RedisStatsServer":
        {
          "server" : "172.16.101.66",
          "port" : 6379
        }
}
~


6.第一次嘗試啟動redis-monitor.py拋錯 _sqlite3

[root@sht-sgmhadoopdn-04 src]# ./redis-monitor.py --duration 120
ImportError: No module named _sqlite3

[root@sht-sgmhadoopdn-04 src]# yum install -y sqlite-devel
[root@sht-sgmhadoopdn-04 src]# yum install -y sqlite

[root@sht-sgmhadoopdn-04 ~]# find / -name _sqlite3.so
/usr/local/python27/lib/python2.7/lib-dynload/_sqlite3.so
/usr/local/Python-2.7.5/build/lib.linux-x86_64-2.7/_sqlite3.so
/usr/lib64/python2.6/lib-dynload/_sqlite3.so

[root@sht-sgmhadoopdn-04 ~]# cp /usr/local/python27/lib/python2.7/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/lib-dynload/
[root@sht-sgmhadoopdn-04 ~]# python
Python 2.7.5 (default, Sep 17 2016, 15:34:31)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>>

參考:


7.第二次嘗試啟動redis-monitor.py拋錯 redis

[root@sht-sgmhadoopdn-04 src]# ./redis-monitor.py --duration 120
ImportError: No module named redis

[root@sht-sgmhadoopdn-04 src]# find / -name redis
/etc/rc.d/init.d/redis
/root/learnproject/app/redis
/root/learnproject/app/redis-monitor/src/main/java/sun/redis
/root/learnproject/app/redis-monitor/src/test/java/sun/redis
/usr/local/redis
/usr/local/python27/lib/python2.7/site-packages/redis
[root@sht-sgmhadoopdn-04 src]#
[root@sht-sgmhadoopdn-04 src]# cp -r  /usr/local/python27/lib/python2.7/site-packages/redis  /usr/local/lib/python2.7/lib-dynload/
[root@sht-sgmhadoopdn-04 src]# python
Python 2.7.5 (default, Sep 17 2016, 15:34:31)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>>

8.第三次嘗試啟動redis-monitor.py,成功;按ctrl+c中斷掉

[root@sht-sgmhadoopdn-04 src]# ./redis-monitor.py --duration 120
^Cshutting down...
You have mail in /var/spool/mail/root
[root@sht-sgmhadoopdn-04 src]#

 

9.嘗試第一次啟動redis-live.py ,tornado.ioloop

[root@sht-sgmhadoopdn-04 src]# ./redis-live.py
Traceback (most recent call last):
  File "./redis-live.py", line 3, in <module>
    import tornado.ioloop
ImportError: No module named tornado.ioloop
[root@sht-sgmhadoopdn-04 src]# find / -name  tornado
/usr/local/python27/lib/python2.7/site-packages/tornado
[root@sht-sgmhadoopdn-04 src]# cp -r /usr/local/python27/lib/python2.7/site-packages/tornado  /usr/local/lib/python2.7/lib-dynload/

10.嘗試第二次啟動redis-live.py ,singledispatch
[root@sht-sgmhadoopdn-04 src]# ./redis-live.py
Traceback (most recent call last):
  File "./redis-live.py", line 6, in <module>
    import tornado.web
  File "/usr/local/lib/python2.7/lib-dynload/tornado/web.py", line 84, in <module>
    from tornado import gen
  File "/usr/local/lib/python2.7/lib-dynload/tornado/gen.py", line 98, in <module>
    from singledispatch import singledispatch  # backport
ImportError: No module named singledispatch


###這個 singledispatch 錯誤,其實就是在tornado裡的,谷歌和思考過後,懷疑是版本問題,於是果斷解除安裝tornado
[root@sht-sgmhadoopdn-04 src]# pip uninstall tornado
[root@sht-sgmhadoopdn-04 src]# rm -rf  /usr/local/lib/python2.7/lib-dynload/tornado
[root@sht-sgmhadoopdn-04 src]# find / -name tornado
[root@sht-sgmhadoopdn-04 src]#
##假如find有的話 ,就要手工刪除掉

11.於是想想其他也是要解除安裝掉
[root@sht-sgmhadoopdn-04 src]# pip uninstall argparse
[root@sht-sgmhadoopdn-04 src]# pip uninstall python-dateutil
[root@sht-sgmhadoopdn-04 src]# find / -name argparse
[root@sht-sgmhadoopdn-04 src]# find / -name python-dateutil
##假如find有的話 ,就要手工刪除掉

 

12.關鍵一步: 根據step3的指定版本來安裝

[root@sht-sgmhadoopdn-04 src]# pip install -v tornado==2.1.1
[root@sht-sgmhadoopdn-04 src]# pip install -v argparse==1.2.1
[root@sht-sgmhadoopdn-04 src]# pip install -v python-dateutil==1.5


13.再次嘗試啟動redis-live.py ,拋錯dateutil.parser

[root@sht-sgmhadoopdn-04 src]# ./redis-live.py
Traceback (most recent call last):
  File "./redis-live.py", line 10, in <module>
    from api.controller.ServerListController import ServerListController
  File "/root/learnproject/app/RedisLive/src/api/controller/ServerListController.py", line 1, in <module>
    from BaseController import BaseController
  File "/root/learnproject/app/RedisLive/src/api/controller/BaseController.py", line 4, in <module>
    import dateutil.parser
ImportError: No module named dateutil.parser
[root@sht-sgmhadoopdn-04 src]#
[root@sht-sgmhadoopdn-04 src]#
[root@sht-sgmhadoopdn-04 src]#
[root@sht-sgmhadoopdn-04 src]#
[root@sht-sgmhadoopdn-04 src]# find / -name dateutil
/usr/local/python27/lib/python2.7/site-packages/dateutil
[root@sht-sgmhadoopdn-04 src]# cp -r /usr/local/python27/lib/python2.7/site-packages/dateutil  /usr/local/lib/python2.7/lib-dynload/
You have mail in /var/spool/mail/root

14.再在嘗試啟動redis-live.py ,成功了,然後按ctrl+c中斷掉

[root@sht-sgmhadoopdn-04 src]# ./redis-live.py
^CTraceback (most recent call last):
  File "./redis-live.py", line 36, in <module>
    tornado.ioloop.IOLoop.instance().start()
  File "/usr/local/lib/python2.7/lib-dynload/tornado/ioloop.py", line 283, in start
    event_pairs = self._impl.poll(poll_timeout)
KeyboardInterrupt
[root@sht-sgmhadoopdn-04 src]#

 
15.啟動

[root@sht-sgmhadoopdn-04 src]# ./redis-monitor.py --duration 120 &
[root@sht-sgmhadoopdn-04 src]# ./redis-live.py  &

開啟web介面

  12【線上日誌分析】之RedisLive監控工具的詳細安裝

16.總結
a.安裝 python2.7+pip
b.pip指定版本去安裝那幾個元件


17.說明: 
redis live   -- 實時redis監控皮膚
可以同時監控多個redis例項 , 包括 記憶體使用 、分db顯示的key數、客戶端連線數、 命令處理數、 系統執行時間 , 以及各種直觀的折線圖柱狀圖.
缺點是使用了monitor 命令監控 , 對效能有影響 ,最好不要長時間啟動 .

redis-monitor.py:  用來呼叫redis的monitor命令來收集redis的命令來進行統計
redis-live.py:    啟動web服務


 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30089851/viewspace-2132455/,如需轉載,請註明出處,否則將追究法律責任。

相關文章