監控Redis叢集服務
阿新 • • 發佈:2018-12-25
一、基礎環境安裝
tar xvzf backports.ssl_match_hostname-3.4.0.2.tar.gz
cd backports.ssl_match_hostname-3.4.0.2
python setup.py install
- 1
- 2
- 3
tar xvzf tornado-3.2.0.tar.gz
cd tornado-3.2.0
python setup.py install
- 1
- 2
tar xvzf redis-py-2.9.1.tar.gz
cd redis-py-2.9.1
python setup.py install
- 1
- 2
- 3
tar xvzf six-1.5.2.tar.gz
cd six-1.5.2
python setup.py install
- 1
- 2
- 3
tar xvzf python-dateutil-2.2.tar.gz
cd python-dateutil-2.2
python setup.py install
- 1
- 2
tar xvzf argparse-1.4.0.tar.gz
cd argparse-1.4.0
python setup.py install
- 1
- 2
- 3
unzip RedisLive-master.zip
mv RedisLive-master RedisLive
http://distfiles.macports.org/py-setuptools/
setuptools-36.2.7.zip
unzip setuptools-36.2.7.zip
sh setuptools*
二、RedisLive配置
1、安裝RedisLive
https: //github.com/nkrode/RedisLive
tar -xf RedisLive-master.zip -C /data/
cd /data/
mv RedisLive-master RedisLive
|
其中redis-live.conf.example是作者給出的一個示例配置檔案,啟動服務之前把.example字尾刪掉變成.conf檔案,開啟redis-live.conf,配置好redis例項的資訊:
[email protected]
api dataprovider db __init__.py redis-live.conf redis-live.conf.example redis-live.py redis-monitor.py util www
[email protected]:/home/redis/monitor/RedisLive-master/src#more redis-live.conf
{
"RedisServers":
[
{
"server": "192.168.1.247",
"port" : 6379
},
{
"server": "192.168.1.111",
"port" : 6379
}
],
"DataStoreType" : "sqlite",
"RedisStatsServer":
{
"server" : "192.168.1.247",
"port" : 6379
},
"SqliteStatsStore" :
{
"path": "/home/redis/monitor/RedisLive-master/src/db/redislive.sqlite"
}
}
[email protected]:/home/redis/monitor/RedisLive-master/src#
在RedisServers中設定需要監控的Redis-server;
DataStoreType決定使用那種型別的資料儲存,
如果是redis,使用RedisStatsServer作為資料儲存的目標;
如果是sqlite,使用SqliteStatsStore作為資料儲存的目標。
整個配置實際上是一個json物件,RedisServers是redis伺服器的資訊,由於是陣列型別所以配置多個redis例項。DataStoreType是監控資訊的儲存方式,有”redis”和” sqlite”兩種方式,分別對應下面RedisStatsServer和SqliteStatsStore,編輯完成後儲存。
redis-live.py是用來啟動web服務的,預設埠是8888 。redis-monitor.py就是redis監控的核心服務。
2、初始化DBcd db
cat schema.sql | sqlite3 redislive.sqlite
- 1
3、配置RedisLive的定期監控
*/5 * * * * cd /data/Redis-Monitor/RedisLive/src; ./redis-monitor.py --duration 20 >/dev/null 2>&1
4、服務啟動
RedisLive的功能分兩個部分:
一個部分是redis-server狀態資料的採集,通過src/redis-monitor.py來執行;
另外一部分功能是提供對狀態資料的查詢服務,通過src/redis-live.py來提供web服務。
./redis-monitor.py --duration 120 &
//啟動監控,duration是心跳時間
./redis-live.py&
//啟動web服務,預設監聽8888埠
注:./redis-live.py &
[[email protected] src]# Traceback (most recent call last):
File "./redis-live.py", line 10, in <module>
from api.controller.ServerListController import ServerListController
File "/data/RedisLive/src/api/controller/ServerListController.py", line 1, in <module>
from BaseController import BaseController
File "/data/RedisLive/src/api/controller/BaseController.py", line 1, in <module>
from dataprovider.dataprovider import RedisLiveDataProvider
File "/data/RedisLive/src/dataprovider/dataprovider.py", line 2, in <module>
import sqliteprovider
File "/data/RedisLive/src/dataprovider/sqliteprovider.py", line 3, in <module>
import sqlite3
File "/usr/local/python2.7/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/usr/local/python2.7/lib/python2.7/sqlite3/dbapi2.py", line 28, in <module>
from _sqlite3 import *
ImportError: No module named _sqlite3
解決:安裝sqlite
tar -xf setuptools-23.0.0.tar.gz
cd sqlite-autoconf-3130000
./configure --prefix=/usr/local/sqlite3
make && make install
netstat -ntpl |grep python
[email protected]:/home/redis/monitor/RedisLive-master/src#netstat -anltp|grep pythontcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 194074/python tcp 0 0 192.168.1.247:43929 192.168.1.247:3309
ESTABLISHED 126445/python3 tcp 0 0 192.168.1.247:45314 192.168.1.247:3309 ESTABLISHED 192761/python3 tcp 0 0 192.168.1.247:8888 192.168.0.250:65142 ESTABLISHED 194074/python tcp 0 0 192.168.1.247:8888
192.168.0.250:64907 ESTABLISHED 194074/python tcp 0 0 192.168.1.247:8888 192.168.0.250:64594 ESTABLISHED 194074/python tcp 0 0 192.168.1.247:45313 192.168.1.247:3309 ESTABLISHED 192761/python3 tcp
0 0 192.168.1.247:8888 192.168.0.250:63135 ESTABLISHED 194074/python tcp6 0 0 :::8888 :::* LISTEN 194074/python [email protected]:/home/redis/monitor/RedisLive-master/src#5、然後在瀏覽器中開啟http://192.168.1.247:8888/index.html,就可以看到監控資訊了:6、安裝redis-stat解除安裝老版本:
yum erase ruby ruby-libs ruby-mode ruby-rdoc ruby-irb ruby-ri ruby-docs1)安裝ruby 2.0以上 tar -xf ruby-2.1.9.tar.gz cd ruby-2.1.9./configure --prefix=/usr/local/ruby2.0makemake install配置連線: cd /usr/local/ruby2.0/for i in `ls`;do ln -s /usr/local/ruby2.0/bin/$i
/usr/bin/$i;done新增淘寶源: gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/2)安裝redis-stat cd /data/git clone https://github.com/junegunn/redis-stat.gitcd /data/redis-stat/bin/# ./redis-stat --help
命令列執行:
redis-stat
redis-stat 1
redis-stat 1 10
redis-stat --verbose
redis-stat localhost: 6380 1 10
redis-stat localhost localhost: 6380 localhost: 6381 5
redis-stat localhost localhost: 6380 1 10 --csv=/tmp/output.csv --verbose
|
redis-stat執行為服務:
redis-stat --server
redis-stat --verbose --server= 8080 5
# redis-stat server can be daemonized
redis-stat --server --daemon
# Kill the daemon
killall - 9 redis-stat-daemon
|
以守護程序模式啟動:
redis-stat --verbose --server= 8080 5 --daemon
|
執行其它主機例項:
./redis-stat
192.168
.
1.12
--auth=
'1234'
--verbose --server=
8080
5
--daemon