一、Open-Falcon元件簡述
【Open-Falcon繪圖相關元件】
- Agent: 部署在目標機器採集機器監控項
- Transfer : 資料接收端,轉發資料到後端Graph和Judge
- Graph:操作rrd檔案儲存監控資料
- Query:查詢各個Graph資料,提供統一http查詢介面
- Dashboard:查詢監控歷史趨勢圖的web端
- Task:負責一些定時任務,索引全量更新、垃圾索引清理、自身元件監控等
【Open-Falcon報警相關元件】
- Sender :報警傳送模組,控制併發度,提供傳送的緩衝queue
- UIC(FE):使用者組管理,單點登入
- Portal:配置報警策略,管理機器分組的web端
- HBS:HeartBeat Server,心跳伺服器
- Judge:報警判斷模組
- Links:報警合併依賴的web端,存放報警詳情
- Alarm:報警時間處理器
【Open-Falcon架構圖】
官網架構圖:
網友:
二、安裝準備
1.安裝Redis
http://www.cnblogs.com/xialiaoliao0911/p/7523952.html
2.安裝MySQL
http://www.cnblogs.com/xialiaoliao0911/p/7523931.html
3.Open-Falocn下載地址
二進位制版本:https://pan.baidu.com/s/1jOb6z-HRJ7i6nSFxf7I5Bg
4. 初始化MySQL表結構
# open-falcon所有元件都無需root賬號啟動,推薦使用普通賬號安裝,提升安全性。此處我們使用普通賬號:work來安裝部署所有元件 # 當然了,使用yum安裝依賴的一些lib庫的時候還是要有root許可權的。 git clone https://github.com/open-falcon/scripts.git cd ./scripts/ mysql -h localhost -u root --password="" < db_schema/graph-db-schema.sql mysql -h localhost -u root --password="" < db_schema/dashboard-db-schema.sql mysql -h localhost -u root --password="" < db_schema/portal-db-schema.sql mysql -h localhost -u root --password="" < db_schema/links-db-schema.sql mysql -h localhost -u root --password="" < db_schema/uic-db-schema.sql
5.解壓open-falcon.tar.gz
#新建使用者falcon useadd falcon #新建臨時目錄tmp su - falcon cd /home/falcon mkdir tmp #解壓 tar -zxf of-release-v0.1.0.tar.gz -C ./tmp/ for x in `find ./tmp/ -name "*.tar.gz"`;do \ app=`echo $x|cut -d '-' -f2`; \ mkdir -p $app; \ tar -zxf $x -C $app; \ done
三、安裝Open-Falcon繪圖相關元件
1.Agent
每臺機器上,都需要部署agent,agent會自動採集預先定義的各種採集項,每隔60秒,push到transfer。
cd $WORKSPACE/agent/ mv cfg.example.json cfg.json vim cfg.json - 修改 transfer這個配置項的enabled為 true,表示開啟向transfer傳送資料的功能 - 修改 transfer這個配置項的addr為:["127.0.0.1:8433"] (改地址為transfer元件的監聽地址, 為列表形式,可配置多個transfer例項的地址,用逗號分隔) # 預設情況下(所有元件都在同一臺伺服器上),保持cfg.json不變即可 # cfg.json中的各配置項,可以參考 https://github.com/open-falcon/agent/blob/master/README.md # 啟動 ./control start # 檢視日誌 ./control tail
#啟動完成後,通過瀏覽器進行訪問
http://192.168.102.141:1988/
【配置檔案】
/home/falcon/tmp/agent/cfg.json
[falcon@open-falcon-demo agent]$ more cfg.json { "debug": false, "hostname": "open-falcon-demo", "ip": "192.168.102.141", "plugin": { "enabled": false, "dir": "./plugin", "git": "https://github.com/open-falcon/plugin.git", "logs": "./logs" }, "heartbeat": { "enabled": true, "addr": "127.0.0.1:6030", "interval": 60, "timeout": 1000 }, "transfer": { "enabled": true, "addrs": [ "127.0.0.1:8433", "127.0.0.1:8433" ], "interval": 60, "timeout": 1000 }, "http": { "enabled": true, "listen": ":1988", "backdoor": false }, "collector": { "ifacePrefix": ["eth", "em"] }, "ignore": { "cpu.busy": true, "df.bytes.free": true, "df.bytes.total": true, "df.bytes.used": true, "df.bytes.used.percent": true, "df.inodes.total": true, "df.inodes.free": true, "df.inodes.used": true, "df.inodes.used.percent": true, "mem.memtotal": true, "mem.memused": true, "mem.memused.percent": true, "mem.memfree": true, "mem.swaptotal": true, "mem.swapused": true, "mem.swapfree": true } }
通過瀏覽器開啟後的介面:
2.aggregator
cd $WORKSPACE/aggregator/
mv cfg.example.json cfg.json
【配置檔案】
/home/falcon/tmp/aggregator/cfg.json
[falcon@open-falcon-demo aggregator]$ more cfg.json { "debug": false, "http": { "enabled": true, "listen": "0.0.0.0:6055" }, "database": { "addr": "root:mysql@tcp(127.0.0.1:3306)/falcon_portal?loc=Local&parseTime=true", "idle": 10, "ids": [1, -1], "interval": 55 }, "api": { "hostnames": "http://127.0.0.1:5050/api/group/%s/hosts.json", "push": "http://127.0.0.1:6060/api/push", "graphLast": "http://127.0.0.1:9966/graph/last" } }
3.Transfer
transfer預設監聽在:8433埠上,agent會通過jsonrpc的方式來push資料上來。
cd $WORKSPACE/transfer/ mv cfg.example.json cfg.json # 預設情況下(所有元件都在同一臺伺服器上),保持cfg.json不變即可 # cfg.json中的各配置項,可以參考 https://github.com/open-falcon/transfer/blob/master/README.md # 如有必要,請酌情修改cfg.json # 啟動transfer ./control start # 校驗服務,這裡假定服務開啟了6060的http監聽埠。檢驗結果為ok表明服務正常啟動。 curl -s "http://127.0.0.1:6060/health" #檢視日誌 ./control tail # 停止transfer ./control stop
[falcon@open-falcon-demo transfer]$ more cfg.json { "debug": false, "minStep": 30, "http": { "enabled": true, "listen": "0.0.0.0:6060" }, "rpc": { "enabled": true, "listen": "0.0.0.0:8433" }, "socket": { "enabled": false, "listen": "0.0.0.0:4444", "timeout": 3600 }, "judge": { "enabled": true, "batch": 200, "connTimeout": 1000, "callTimeout": 5000, "maxConns": 32, "maxIdle": 32, "replicas": 500, "cluster": { "judge-00" : "127.0.0.1:6080" } }, "graph": { "enabled": true, "batch": 200, "connTimeout": 1000, "callTimeout": 5000, "maxConns": 32, "maxIdle": 32, "replicas": 500, "cluster": { "graph-00" : "127.0.0.1:6070" } }, "tsdb": { "enabled": false, "batch": 200, "connTimeout": 1000, "callTimeout": 5000, "maxConns": 32, "maxIdle": 32, "retry": 3, "address": "127.0.0.1:8088" } }
4.Graph
graph元件是儲存繪圖資料、歷史資料的元件。transfer會把接收到的資料,轉發給graph。
cd $WORKSPACE/graph/ mv cfg.example.json cfg.json
mkdir -p /home/falcon/data/6070 #新建graph資料儲存目錄 # 預設情況下(所有元件都在同一臺伺服器上),保持cfg.json不變即可 # cfg.json中的各配置項,可以參考 https://github.com/open-falcon/graph/blob/master/README.md # 啟動 ./control start # 檢視日誌 ./control tail # 校驗服務,這裡假定服務開啟了6071的http監聽埠。檢驗結果為ok表明服務正常啟動。 curl -s "http://127.0.0.1:6071/health"
[falcon@open-falcon-demo graph]$ more cfg.json { "pid": "/home/falcon/open-falcon/graph/var/app.pid", #修改為本機實際的目錄 "log": "info", "debug": false, "http": { "enabled": true, "listen": "0.0.0.0:6071" }, "rpc": { "enabled": true, "listen": "0.0.0.0:6070" }, "rrd": { "storage": "/home/falcon/data/6070" #graph資料儲存目錄,需要手動建立 }, "db": { "dsn": "root:mysql@tcp(127.0.0.1:3306)/graph?loc=Local&parseTime=true", #標記紅色的為MySQL資料的root密碼 "maxIdle": 4 }, "callTimeout": 5000, "migrate": { "enabled": false, "concurrency": 2, "replicas": 500, "cluster": { "graph-00" : "127.0.0.1:6070" } } }
5.Query
query元件,繪圖資料的查詢介面,query元件收到使用者的查詢請求後,會從後端的多個graph,查詢相應的資料,聚合後,再返回給使用者。
cd $WORKSPACE/query/ mv cfg.example.json cfg.json
#進入query目錄新建graph_backends.txt檔案,並寫入graph相關的內容,內容來源於graph的cfg.json的migrate>cluster
cd /home/falcon/tmp/query
vi graph_backends.txt
graph-00 127.0.0.1:6070
# 預設情況下(所有元件都在同一臺伺服器上),保持cfg.json不變即可 # cfg.json中的各配置項,可以參考 https://github.com/open-falcon/query/blob/master/README.md # 啟動 ./control start # 檢視日誌 ./control tail
[falcon@open-falcon-demo query]$ more cfg.json { "log_level": "info", "slowlog": 2000, "debug": "false", "http": { "enabled": true, "listen": "0.0.0.0:9966" }, "graph": { "backends": "./graph_backends.txt", "reload_interval": 60, "connTimeout": 1000, "callTimeout": 5000, "maxConns": 32, "maxIdle": 32, "replicas": 500, "cluster": { "graph-00": "127.0.0.1:6070" } }, "api": { "query": "http://127.0.0.1:9966", "dashboard": "http://127.0.0.1:8081", "max": 500 } }
6.Dashboard
dashboard是面向使用者的查詢介面,在這裡,使用者可以看到push到graph中的所有資料,並檢視其趨勢圖。
Install dependency #配置EPEL源,安裝virtualenv環境 rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm yum install -y python-pip pip install virtualenv
#根據MySQL實際路徑,新建兩個軟連線
ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib/libmysqlclient.so.20
ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/libmysqlclient.so.20
#將pip_requirements.txt中的mysql-python這一行去掉,使用easy_install單獨安裝
#進入到virtualenv環境
[falcon@open-falcon-demo dashboard]$ virtualenv env
[falcon@open-falcon-demo dashboard]$ source env/bin/activate
#安裝mysql-python
(env)[falcon@open-falcon-demo dashboard]$ easy_install mysql-python
#檢視READ.me檔案,找到./env/bin/pip install -r pip_requirements.txt -i http://pypi.douban.com/simple這行然後執行
(env)[falcon@open-falcon-demo dashboard]$ ./env/bin/pip install -r pip_requirements.txt -i http://pypi.douban.com/simple
#啟動Dashboard
(env)[falcon@open-falcon-demo dashboard]$ ./control start
#檢視Dashboard啟動狀態
(env)[falcon@open-falcon-demo dashboard]$ ./control status
#檢視日誌
(env)[falcon@open-falcon-demo dashboard]$ ./control tail
#退出virtualenv環境
(env)[falcon@open-falcon-demo dashboard]$ deactivate
#啟動完成後,可通過瀏覽器進行訪問
http://192.168.102.141:8081/
【配置檔案】
/home/falcon/tmp/dashboard/rrd/config.py
[falcon@open-falcon-demo rrd]$ more config.py #-*-coding:utf8-*- import os #-- dashboard db config -- DASHBOARD_DB_HOST = "127.0.0.1" DASHBOARD_DB_PORT = 3306 DASHBOARD_DB_USER = "root" DASHBOARD_DB_PASSWD = "mysql" DASHBOARD_DB_NAME = "dashboard" #-- graph db config -- GRAPH_DB_HOST = "127.0.0.1" GRAPH_DB_PORT = 3306 GRAPH_DB_USER = "root" GRAPH_DB_PASSWD = "mysql" GRAPH_DB_NAME = "graph" #-- app config -- DEBUG = True SECRET_KEY = "secret-key" SESSION_COOKIE_NAME = "open-falcon" PERMANENT_SESSION_LIFETIME = 3600 * 24 * 30 SITE_COOKIE = "open-falcon-ck" #-- query config -- QUERY_ADDR = "http://127.0.0.1:9966" #BASE_DIR = "/home/falcon/open-falcon/dashboard/" BASE_DIR="/home/falcon/data/6070" #和graph新建的資料儲存目錄相同 LOG_PATH = os.path.join(BASE_DIR,"log/") try: from rrd.local_config import * except: pass
7.task
cd /home/falcon/tmp/task
mv cfg.example.json cfg.json
#修改配置檔案
[falcon@open-falcon-demo task]$ more cfg.json { "debug": false, "http": { "enable": true, "listen": "0.0.0.0:8002" }, "index": { "enable": true, "dsn": "root:mysql@tcp(127.0.0.1:3306)/graph?loc=Local&parseTime=true", #MySQL的root密碼 "maxIdle": 4, "autoDelete": false, "cluster":{ "test.hostname01:6071" : "0 0 0 ? * 0-5", "test.hostname02:6071" : "0 30 0 ? * 0-5" } }, "collector" : { "enable": true, "destUrl" : "http://127.0.0.1:1988/v1/push", "srcUrlFmt" : "http://%s/statistics/all", "cluster" : [ "transfer,test.hostname:6060", "graph,test.hostname:6071", "task,test.hostname:8001" ] } }
#啟動task [falcon@open-falcon-demo task]$ ./control start #檢視啟動狀態 [falcon@open-falcon-demo task]$ ./control status #檢視日誌 [falcon@open-falcon-demo task]$ ./control tail #重啟 [falcon@open-falcon-demo task]$ ./control restart
四、安裝Open-Falcon報警相關元件
1.Sender
呼叫各個公司提供的mail-provider和sms-provider,按照某個併發度,從redis中讀取郵件、簡訊併傳送,alarm生成的報警簡訊和報警郵件都是直接寫入redis即可,sender來傳送。
cd $WORKSPACE/sender/ mv cfg.example.json cfg.json # vi cfg.json # redis地址需要和後面的alarm、judge使用同一個 # queue維持預設 # worker是最多同時有多少個執行緒玩命得呼叫簡訊、郵件傳送介面 # api要給出sms-provider和mail-provider的介面地址 ./control start
[falcon@open-falcon-demo sender]$ more cfg.json { "debug": false, "http": { "enabled": true, "listen": "0.0.0.0:6066" }, "redis": { "addr": "127.0.0.1:6379", "maxIdle": 5 }, "queue": { "sms": "/sms", "mail": "/mail" }, "worker": { "sms": 10, "mail": 50 }, "api": { "sms": "http://11.11.11.11:8000/sms", "mail": "http://11.11.11.11:9000/mail" } }
2.UIC(FE)
cd $WORKSPACE/fe/ mv cfg.example.json cfg.json # 請基於cfg.example.json 酌情修改相關配置項 # 啟動 ./control start # 檢視日誌 ./control tail # 停止服務 ./control stop
[falcon@open-falcon-demo fe]$ more cfg.json { "log": "debug", "company": "MI", "http": { "enabled": true, "listen": "0.0.0.0:1234" }, "cache": { "enabled": true, "redis": "127.0.0.1:6379", "idle": 10, "max": 1000, "timeout": { "conn": 10000, "read": 5000, "write": 5000 } }, "salt": "", "canRegister": true, "ldap": { "enabled": false, "addr": "ldap.example.com:389", "baseDN": "dc=example,dc=com", "bindDN": "cn=mananger,dc=example,dc=com", "bindPasswd": "12345678", "userField": "uid", "attributes": ["sn","mail","telephoneNumber"] }, "uic": { "addr": "root:mysql@tcp(127.0.0.1:3306)/uic?charset=utf8&loc=Asia%2FChongqing", #紅色為MySQL資料庫root密碼 "idle": 10, "max": 100 }, "shortcut": { "falconPortal": "http://192.168.102.141:5050/", #Portal訪問地址 "falconDashboard": "http://192.168.102.141:8081/", #Dashboard訪問地址 "falconAlarm": "http://192.168.102.141:9912/" #Alarm訪問地址 } }
3.Portal
portal是用於配置報警策略的地方。
yum install -y python-virtualenv # run as root cd $WORKSPACE/portal/ virtualenv ./env ./env/bin/pip install -r pip_requirements.txt # vi frame/config.py # 1. 修改DB配置 # 2. SECRET_KEY設定為一個隨機字串 # 3. UIC_ADDRESS有兩個,internal配置為FE模組的內網地址,portal通常是和UIC在一個網段的, # 內網地址相互訪問速度快。external是終端使用者通過瀏覽器訪問的UIC地址,很重要! # 4. 其他配置可以使用預設的 ./control start portal預設監聽在5050埠,瀏覽器訪問即可
more /home/falcon/tmp/portal/frame/config.py # -*- coding:utf-8 -*- __author__ = 'Ulric Qin' # -- app config -- DEBUG = True # -- db config -- DB_HOST = "127.0.0.1" DB_PORT = 3306 DB_USER = "root" DB_PASS = "mysql" #資料庫密碼 DB_NAME = "falcon_portal" # -- cookie config -- SECRET_KEY = "4e.5tyg8-u9ioj" SESSION_COOKIE_NAME = "falcon-portal" PERMANENT_SESSION_LIFETIME = 3600 * 24 * 30 UIC_ADDRESS = { 'internal': 'http://127.0.0.1:1234', 'external': 'http://192.168.102.141:1234', #可通過瀏覽器訪問的地址 } UIC_TOKEN = '' MAINTAINERS = ['root'] CONTACT = 'ulric.qin@gmail.com' COMMUNITY = True try: from frame.local_config import * except Exception, e: print "[warning] %s" % e
4.HBS
心跳伺服器,只依賴Portal的DB cd $WORKSPACE/hbs/ mv cfg.example.json cfg.json # vi cfg.json 把資料庫配置配置為portal的db ./control start 如果先安裝的繪圖元件又來安裝報警元件,那應該已經安裝過agent了,hbs啟動之後會監聽一個http埠,一個rpc埠,agent要和hbs通訊,重新去修改agent的配置cfg.json,把heartbeat那項enabled設定為true,並配置上hbs的rpc地址,./control restart重啟agent,之後agent就可以和hbs心跳了
[falcon@open-falcon-demo hbs]$ more cfg.json { "debug": true, "database": "root:mysql@tcp(127.0.0.1:3306)/falcon_portal?loc=Local&parseTime=true", "hosts": "", "maxIdle": 100, "listen": ":6030", "trustable": [""], "http": { "enabled": true, "listen": "0.0.0.0:6031" } }
5.Judge
報警判斷模組,judge依賴於HBS,所以得先搭建HBS
cd $WORKSPACE/judge/ mv cfg.example.json cfg.json # vi cfg.json # remain: 這個配置指定了judge記憶體中針對某個資料存多少個點,比如host01這個機器的cpu.idle的值在記憶體中最多存多少個, # 配置報警的時候比如all(#3),這個#後面的數字不能超過remain-1 # hbs: 配置為hbs的地址,interval預設是60s,表示每隔60s從hbs拉取一次策略 # alarm: 報警event寫入alarm中配置的redis,minInterval表示連續兩個報警之間至少相隔的秒數,維持預設即可 ./control start
[falcon@open-falcon-demo judge]$ more cfg.json { "debug": true, "debugHost": "nil", "remain": 11, "http": { "enabled": true, "listen": "0.0.0.0:6081" }, "rpc": { "enabled": true, "listen": "0.0.0.0:6080" }, "hbs": { "servers": ["127.0.0.1:6030"], "timeout": 300, "interval": 60 }, "alarm": { "enabled": true, "minInterval": 300, "queuePattern": "event:p%v", "redis": { "dsn": "127.0.0.1:6379", "maxIdle": 5, "connTimeout": 5000, "readTimeout": 5000, "writeTimeout": 5000 } } }
6.Links
links元件的作用:當多個告警被合併為一條告警資訊時,簡訊中會附帶一個告警詳情的http連結地址,供使用者檢視詳情。
# yum install -y python-virtualenv $ cd $WORKSPACE/links/ $ virtualenv ./env $ ./env/bin/pip install -r pip_requirements.txt
./control start ./control status ./control tail
cd /home/falcon/tmp/links/frame [falcon@open-falcon-demo frame]$ more config.py # -*- coding:utf-8 -*- __author__ = 'Ulric Qin' # -- app config -- DEBUG = True # -- db config -- DB_HOST = "127.0.0.1" DB_PORT = 3306 DB_USER = "root" DB_PASS = "mysql" DB_NAME = "falcon_links" # -- cookie config -- SECRET_KEY = "4e.5tyg8-u9ioj" SESSION_COOKIE_NAME = "falcon-links" PERMANENT_SESSION_LIFETIME = 3600 * 24 * 30 try: from frame.local_config import * except Exception, e: print "[warning] %s" % e
7.Alarm
alarm模組是處理報警event的,judge產生的報警event寫入redis,alarm從redis讀取,這個模組被業務搞得很糟亂,各個公司可以根據自己公司的需求重寫.
cd $WORKSPACE/alarm/
mv cfg.example.json cfg.json
# vi cfg.json
# 把redis配置成與judge同一個
./control start
注意,alarm當前的版本,highQueues和lowQueues都不能為空,是個bug,稍候修復。我們可以把event:p0~event:p5配置到highQueues,把event:p6配置到lowQueues
[falcon@open-falcon-demo alarm]$ more cfg.json { "debug": true, "uicToken": "", "http": { "enabled": true, "listen": "0.0.0.0:9912" }, "queue": { "sms": "/sms", "mail": "/mail" }, "redis": { "addr": "127.0.0.1:6379", "maxIdle": 5, "highQueues": [ "event:p0", "event:p1", "event:p2", "event:p3", "event:p4", "event:p5" ], "lowQueues": [ "event:p6" ], "userSmsQueue": "/queue/user/sms", "userMailQueue": "/queue/user/mail" }, "api": { "portal": "http://192.168.102.141:5050", "uic": "http://127.0.0.1:1234", "links": "http://192.168.102.141:5090" } }
PS:本例安裝open-falcon時是使用falcon使用者安裝的。
falcon使用者的家目錄是:/home/falcon
所有配置好的配置檔案的打包在這裡:https://pan.baidu.com/s/1ii6r0-iJYYt4Mn_WzHcfcw
【agent】
http://192.168.102.141:1988/
【dashboard】
http://192.168.102.141:8081/
【uic/fe】
http://192.168.102.141:1234/
【Portal】
http://192.168.102.141:5050/
【alarm】
http://192.168.102.141:9912/
手動觸發graph
curl -s "http://127.0.0.1:6071/index/updateAll"