一、环境准备
安装redis&mysql
redis:4.0.
mysql:5.6.
wget http://mirrors.linuxeye.com/oneinstack.tar.gz tar zxf oneinstack.tar.gz
初始化mysql表结构
cd /tmp/ && git clone https://github.com/open-falcon/falcon-plus.git cd /tmp/falcon-plus/scripts/mysql/db_schema/ mysql -h 127.0.0.1 -u root -p < 1_uic-db-schema.sql mysql -h 127.0.0.1 -u root -p < 2_portal-db-schema.sql mysql -h 127.0.0.1 -u root -p < 3_dashboard-db-schema.sql mysql -h 127.0.0.1 -u root -p < 4_graph-db-schema.sql mysql -h 127.0.0.1 -u root -p < 5_alarms-db-schema.sql
下载编译好的https://github.com/open-falcon/falcon-plus/releases
open-falcon-v0.2.0.tar.gz 二进制版本
创建工作目录
export FALCON_HOME=/home/work export WORKSPACE=$FALCON_HOME/open-falcon mkdir -p $WORKSPACE
解压二进制包
tar -xzvf open-falcon-v0.2.0.tar.gz -C $WORKSPACE
二、后端安装启动
注意:以下是配置文件讲解,需要改动的地方很少,直接在原来配置文件改即可,以下是常用的工具配置,并不是所有工具都需要,按需搭建即可
修改配置文件
Agent
vim agent/config/cfg.json { "debug": true, # 控制一些debug信息的输出,生产环境通常设置为false "hostname": "", # agent采集了数据发给transfer,endpoint就设置为了hostname,默认通过hostname获取,如果配置中配置了hostname,就用配置中的 "ip": "", # agent与hbs心跳的时候会把自己的ip地址发给hbs,agent会自动探测本机ip,如果不想让agent自动探测,可以手工修改该配置 "plugin": { "enabled": false, # 默认不开启插件机制 "dir": "./plugin", # 把放置插件脚本的git repo clone到这个目录 "git": "https://github.com/open-falcon/plugin.git", # 放置插件脚本的git repo地址 "logs": "./logs" # 插件执行的log,如果插件执行有问题,可以去这个目录看log }, "heartbeat": { "enabled": true, # 此处enabled要设置为true "addr": "127.0.0.1:6030", # hbs的地址,端口是hbs的rpc端口 "interval": 60, # 心跳周期,单位是秒 "timeout": 1000 # 连接hbs的超时时间,单位是毫秒 }, "transfer": { "enabled": true, "addrs": [ "127.0.0.1:18433" ], # transfer的地址,端口是transfer的rpc端口, 可以支持写多个transfer的地址,agent会保证HA "interval": 60, # 采集周期,单位是秒,即agent一分钟采集一次数据发给transfer "timeout": 1000 # 连接transfer的超时时间,单位是毫秒 }, "http": { "enabled": true, # 是否要监听http端口 "listen": ":1988", "backdoor": false }, "collector": { "ifacePrefix": ["eth", "em"], # 默认配置只会采集网卡名称前缀是eth、em的网卡流量,配置为空就会采集所有的,lo的也会采集。可以从/proc/net/dev看到各个网卡的流量信息 "mountPoint": [] }, "default_tags": { }, "ignore": { # 默认采集了200多个metric,可以通过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 } }
Transfer
vim transfer/config/cfg.json
debug: true/false, 如果为true,日志中会打印debug信息
minStep: 30, 允许上报的数据最小间隔,默认为30秒 http - enabled: true/false, 表示是否开启该http端口,该端口为控制端口,主要用来对transfer发送控制命令、统计命令、debug命令等 - listen: 表示监听的http端口 rpc - enabled: true/false, 表示是否开启该jsonrpc数据接收端口, Agent发送数据使用的就是该端口 - listen: 表示监听的http端口 socket #即将被废弃,请避免使用 - enabled: true/false, 表示是否开启该telnet方式的数据接收端口,这是为了方便用户一行行的发送数据给transfer - listen: 表示监听的http端口 judge - enabled: true/false, 表示是否开启向judge发送数据 - batch: 数据转发的批量大小,可以加快发送速度,建议保持默认值 - connTimeout: 单位是毫秒,与后端建立连接的超时时间,可以根据网络质量微调,建议保持默认 - callTimeout: 单位是毫秒,发送数据给后端的超时时间,可以根据网络质量微调,建议保持默认 - pingMethod: 后端提供的ping接口,用来探测连接是否可用,必须保持默认 - maxConns: 连接池相关配置,最大连接数,建议保持默认 - maxIdle: 连接池相关配置,最大空闲连接数,建议保持默认 - replicas: 这是一致性hash算法需要的节点副本数量,建议不要变更,保持默认即可 - cluster: key-value形式的字典,表示后端的judge列表,其中key代表后端judge名字,value代表的是具体的ip:port graph - enabled: true/false, 表示是否开启向graph发送数据 - batch: 数据转发的批量大小,可以加快发送速度,建议保持默认值 - connTimeout: 单位是毫秒,与后端建立连接的超时时间,可以根据网络质量微调,建议保持默认 - callTimeout: 单位是毫秒,发送数据给后端的超时时间,可以根据网络质量微调,建议保持默认 - pingMethod: 后端提供的ping接口,用来探测连接是否可用,必须保持默认 - maxConns: 连接池相关配置,最大连接数,建议保持默认 - maxIdle: 连接池相关配置,最大空闲连接数,建议保持默认 - replicas: 这是一致性hash算法需要的节点副本数量,建议不要变更,保持默认即可 - cluster: key-value形式的字典,表示后端的graph列表,其中key代表后端graph名字,value代表的是具体的ip:port(多个地址用逗号隔开, transfer会将同一份数据发送至各个地址,利用这个特性可以实现数据的多重备份) tsdb - enabled: true/false, 表示是否开启向open tsdb发送数据 - batch: 数据转发的批量大小,可以加快发送速度 - connTimeout: 单位是毫秒,与后端建立连接的超时时间,可以根据网络质量微调,建议保持默认 - callTimeout: 单位是毫秒,发送数据给后端的超时时间,可以根据网络质量微调,建议保持默认 - maxConns: 连接池相关配置,最大连接数,建议保持默认 - maxIdle: 连接池相关配置,最大空闲连接数,建议保持默认 - retry: 连接后端的重试次数和发送数据的重试次数 - address: tsdb地址或者tsdb集群vip地址, 通过tcp连
Graph
{ "debug": false, //true or false, 是否开启debug日志 "http": { "enabled": true, //true or false, 表示是否开启该http端口,该端口为控制端口,主要用来对graph发送控制命令、统计命令、debug命令 "listen": "0.0.0.0:6071" //表示监听的http端口 }, "rpc": { "enabled": true, //true or false, 表示是否开启该rpc端口,该端口为数据接收端口 "listen": "0.0.0.0:6070" //表示监听的rpc端口 }, "rrd": { "storage": "./data/6070" // 历史数据的文件存储路径(如有必要,请修改为合适的路) }, "db": { "dsn": "root:@tcp(127.0.0.1:3306)/graph?loc=Local&parseTime=true", //MySQL的连接信息,默认用户名是root,密码为空,host为127.0.0.1,database为graph(如有必要,请修改) "maxIdle": 4 //MySQL连接池配置,连接池允许的最大连接数,保持默认即可 }, "callTimeout": 5000, //RPC调用超时时间,单位ms "migrate": { //扩容graph时历史数据自动迁移 "enabled": false, //true or false, 表示graph是否处于数据迁移状态 "concurrency": 2, //数据迁移时的并发连接数,建议保持默认 "replicas": 500, //这是一致性hash算法需要的节点副本数量,建议不要变更,保持默认即可(必须和transfer的配置中保持一致) "cluster": { //未扩容前老的graph实例列表 "graph-00" : "127.0.0.1:6070" } } }
API
{ "log_level": "debug", "db": { //数据库相关的连接配置信息 "faclon_portal": "root:@tcp(127.0.0.1:3306)/falcon_portal?charset=utf8&parseTime=True&loc=Local", "graph": "root:@tcp(127.0.0.1:3306)/graph?charset=utf8&parseTime=True&loc=Local", "uic": "root:@tcp(127.0.0.1:3306)/uic?charset=utf8&parseTime=True&loc=Local", "dashboard": "root:@tcp(127.0.0.1:3306)/dashboard?charset=utf8&parseTime=True&loc=Local", "alarms": "root:@tcp(127.0.0.1:3306)/alarms?charset=utf8&parseTime=True&loc=Local", "db_bug": true }, "graphs": { // graph模块的部署列表信息 "cluster": { "graph-00": "127.0.0.1:6070" }, "max_conns": 100, "max_idle": 100, "conn_timeout": 1000, "call_timeout": 5000, "numberOfReplicas": 500 }, "metric_list_file": "./api/data/metric", "web_port": ":8080", // http监听端口 "access_control": true, // 如果设置为false,那么任何用户都可以具备管理员权限 "salt": "pleaseinputwhichyouareusingnow", //数据库加密密码的时候的salt "skip_auth": false, //如果设置为true,那么访问api就不需要经过认证 "default_token": "default-token-used-in-server-side", //用于服务端各模块间的访问授权 "gen_doc": false, "gen_doc_path": "doc/module.html" } HBS(Heartbeat Server) { "debug": true, "database": "root:password@tcp(127.0.0.1:3306)/falcon_portal?loc=Local&parseTime=true", # Portal的数据库地址 "hosts": "", # portal数据库中有个host表,如果表中数据是从其他系统同步过来的,此处配置为sync,否则就维持默认,留空即可 "maxIdle": 100, "listen": ":6030", # hbs监听的rpc地址 "trustable": [""], "http": { "enabled": true, "listen": "0.0.0.0:6031" # hbs监听的http地址 } }
Judge
{ "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"], # hbs最好放到lvs vip后面,所以此处最好配置为vip:port "timeout": 300, "interval": 60 }, "alarm": { "enabled": true, "minInterval": 300, # 连续两个报警之间至少相隔的秒数,维持默认即可 "queuePattern": "event:p%v", "redis": { "dsn": "127.0.0.1:6379", # 与alarm、sender使用一个redis "maxIdle": 5, "connTimeout": 5000, "readTimeout": 5000, "writeTimeout": 5000 } } }
Alarm
{ "log_level": "debug", "http": { "enabled": true, "listen": "0.0.0.0:9912" }, "redis": { "addr": "127.0.0.1:6379", "maxIdle": 5, "highQueues": [ "event:p0", "event:p1", "event:p2" ], "lowQueues": [ "event:p3", "event:p4", "event:p5", "event:p6" ], "userIMQueue": "/queue/user/im", "userSmsQueue": "/queue/user/sms", "userMailQueue": "/queue/user/mail" }, "api": { "im": "http://127.0.0.1:10086/wechat", //微信发送网关地址 "sms": "http://127.0.0.1:10086/sms", //短信发送网关地址 "mail": "http://127.0.0.1:10086/mail", //邮件发送网关地址 "dashboard": "http://127.0.0.1:8081", //dashboard模块的运行地址 "plus_api":"http://127.0.0.1:8080", //falcon-plus api模块的运行地址 "plus_api_token": "default-token-used-in-server-side" //用于和falcon-plus api模块服务端之间的通信认证token }, "falcon_portal": { "addr": "root:@tcp(127.0.0.1:3306)/alarms?charset=utf8&loc=Asia%2FChongqing", "idle": 10, "max": 100 }, "worker": { "im": 10, "sms": 10, "mail": 50 }, "housekeeper": { "event_retention_days": 7, //报警历史信息的保留天数 "event_delete_batch": 100 } }
Task
debug: true/false, 如果为true,日志中会打印debug信息
http
- enable: true/false, 表示是否开启该http端口,该端口为控制端口,主要用来对task发送控制命令、统计命令、debug命令等
- listen: 表示http-server监听的端口
index
- enable: true/false, 表示是否开启索引更新任务
- dsn: 索引服务的MySQL的连接信息,默认用户名是root,密码为空,host为127.0.0.1,database为graph(如有必要,请修改)
- maxIdle: MySQL连接池配置,连接池允许的最大空闲连接数,保持默认即可
cluster: 后端graph索引更新的定时任务描述。一条记录的形如: "graph地址:执行周期描述",通过设置不同的执行周期,来实现负载在时间上的均衡。
eg. 后端部署了两个graph实例,cluster可以配置为
"cluster":{ "test.hostname01:6071" : "0 0 0 ? 0-5", //周0-5,每天的00:00:00,开始执行索引全量更新;"0 0 0 ? 0-5"为quartz表达式 "test.hostname02:6071" : "0 30 0 ? * 0-5", //周0-5,每天的00:30:00,开始执行索引全量更新 }
- autoDelete: true|false, 是否自动删除垃圾索引。默认为false
collector
- enable: true/false, 表示是否开启falcon的自身状态采集任务
- destUrl: 监控数据的push地址,默认为本机的1988接口
- srcUrlFmt: 监控数据采集的url格式, %s将由机器名或域名替换
- cluster: falcon后端服务列表,用具体的"module,hostname:port"表示,module取值可以为graph、transfer、task等
Nodata
{ "debug": true, "http": { "enabled": true, "listen": "0.0.0.0:6090" }, "plus_api":{ "connectTimeout": 500, "requestTimeout": 2000, "addr": "http://127.0.0.1:8080", #falcon-plus api模块的运行地址 "token": "default-token-used-in-server-side" #用于和falcon-plus api模块的交互认证token }, "config": { "enabled": true, "dsn": "root:@tcp(127.0.0.1:3306)/falcon_portal?loc=Local&parseTime=true&wait_timeout=604800", "maxIdle": 4 }, "collector":{ "enabled": true, "batch": 200, "concurrent": 10 }, "sender":{ "enabled": true, "connectTimeout": 500, "requestTimeout": 2000, "transferAddr": "127.0.0.1:6060", #transfer的http监听地址,一般形如"domain.transfer.service:6060" "batch": 500 } } Aggregator { "debug": true, "http": { "enabled": true, "listen": "0.0.0.0:6055" }, "database": { "addr": "root:@tcp(127.0.0.1:3306)/falcon_portal?loc=Local&parseTime=true", "idle": 10, "ids": [1, -1], "interval": 55 }, "api": { "connect_timeout": 500, "request_timeout": 2000, "plus_api": "http://127.0.0.1:8080", #falcon-plus api模块的运行地址 "plus_api_token": "default-token-used-in-server-side", #和falcon-plus api 模块交互的认证token "push_api": "http://127.0.0.1:1988/v1/push" #push数据的http接口,这是agent提供的接口 } }
Agent-updater
每台机器都要部署falcon-agent,如果公司机器量比较少,用pssh、ansible、fabric之类的工具手工安装问题也不大。但是公司机器量多了之后,手工安装、升级、回滚falcon-agent将成为噩梦。
个人开发了agent-updater这个工具,用于管理falcon-agent,agent-updater也有一个agent:ops-updater,可以看做是一个超级agent,用于管理其他agent的agent,呵呵,ops-updater推荐在装机的时候一起安装上。ops-updater通常是不会升级的。
具体参看:https://github.com/open-falcon/ops-updater
三、前端安装启动
克隆前端组件代码
cd $WORKSPACE git clone https://github.com/open-falcon/dashboard.git
安装依赖包
yum install -y python-virtualenv yum install -y python-devel yum install -y openldap-devel yum install -y mysql-devel yum groupinstall "Development tools" cd $WORKSPACE/dashboard/ virtualenv ./env ./env/bin/pip install -r pip_requirements.txt
修改配置文件
vim dashboard/rrd/config.py
启动
./control start
四、验证
浏览器输入192.168.100.227:8081(ip+端口)
点击sign up注册,第一个帐号名称为root的用户会被自动设置为超级管理员
五、grafana配置
注:这个只是好玩,安装不安装都行
下载安装包
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.2.0-1.x86_64.rpm rpm -ivh grafana-4.2.0-1.x86_64.rpm
安装插件
grafana-cli plugins install fastweb-openfalcon-datasource
编辑grafana.ini配置文件
vim /etc/grafana.ini
添加
[plugin.openfalcon] ;path = /var/lib/grafana/plugins/fastweb-openfalcon-datasource
启动grafana
service grafana-server restart
验证
浏览器访问192.168.100.227:3000(ip+3000端口)
默认登录名admin 密码admin
这个只是随便玩,想玩高大上多搞
六、OneAlert
这个就比较实用了,主要是邮件+短信+电话报警,而且是免费的,可以集成zabbix,nagios,falcon等等等等主流监控,可以在手机端app及PC端处理报警,配置及管理一切,灰常实用。
打开 onealert
- 添加应用
创建falcon应用,并获取appkey
- 添加falcon回调地址
登录open-falcon,选择template模块,点击你想要绑定OneAlert告警平台的template name.
注意:你可以一个template绑定一个appkey,也可以多个.这取决于你们的管理方式.
在回调地址中填写类似如下URL:
http://api.onealert.com/alert/api/event/falcon/your_appkey
- 查看告警
- 在「配置」->「应用」
模块添加新应用.选择「添加应用」后,您可以选择匹配的监控平台,系统会以向导的方式指引你完成配置
- 选择「配置」->「分派策略」
您可以将不同的应用、不同级别、不同内容的告警分派给不同的人员。你也可以将团队成员根据角色划分不同级别,比如一线运维人员实时接收告警,二线测试开发人员接收升级(长时间未处理解决)后的告警。
- 选择「配置」->「通知策略」
您可以设置自己或团队成员用何种渠道接收告警,在何种时间、接收什么级别的告警。详细了解通知策略
- 您可以在点击右上角「用户名」->「邀请成员」
选择添加团队成员
- 可以用微信与app管理,并且可以排班,分组。