距离上次整理 open-falcon 的部署手册 ( https://www.cnblogs.com/straycats/p/7199209.html ) 已经一年多了, 当时才刚接触 Linux, 很多东西整理的并不是很合理(比如一些操作的描述), 一些部署的内容也不是很严谨(比如如何实现开机自启).
正好最近在做监控系统的选型, open-falcon 又被我拿出来作为试验的目标. 介于后来 0.2.1 与 0.2.0 的一些部署上的差异, 我决定重新针对 0.2.1 整理一份部署手册, 供路人一起参考.
由于新文档变更了之前文档的一些部署路径及配置内容, 建议基础能力还不是很强的同学可以忽略我 17 年整理的 0.2.0 版本的部署手册, 直接看这份手册.
部署一套系统之前, 首先关注整个架构, 这里直接把官方的图盗过来.
一, 环境准备
操作系统: CentOS 7.6(www.CentOS.org 下载的包是 CentOS-7-x86_64-Minimal-1810.iso)
虚拟机 IP:192.168.12.55
1.1 配置防火墙
- # 为了方便可以选择直接关闭防火墙
- systemctl stop firewalld
- systemctl disable firewalld
当然如果你需要开启防火墙, 那么开放几个业务上需要开放的端口.
服务模块 | 功能 | 端口 |
hbs | 连接所有 agent 的心跳服务 | 6030 |
transfer | 接收 agent 发送的监控数据 | 8433 |
dashboard | 页面 | 8081 |
- # 开放端口 6030,8433,8081, 允许任意 IP 访问
- firewall-cmd --add-port=6030/tcp --permanent
- firewall-cmd --add-port=8433/tcp --permanent
- firewall-cmd --add-port=8081/tcp --permanent
- # 重新加载防火墙配置
- firewall-cmd --reload
1.2 安装 wget,VIM
yum install -y wget VIM
1.3 安装 Git
yum install -y Git
安装结束后, 确认是否满足官方要求的 Git>= 1.7.5
Git version
1.4 安装 golang
- # 通过 fedora 的 epel 仓库来安装 golang
- yum install -y epel-release
- yum install -y golang
安装结束后, 确认是否满足官方要求的 Go>= 1.6
go version
1.5 安装 Redis
- # 通过 fedora 的 epel 仓库来安装 Redis
- yum install -y epel-release
- yum install -y Redis
- # 启动, 开机启动 Redis
- systemctl start Redis
- systemctl enable Redis
1.6 安装 MySQL 5.6
- # 获取 repo 源
- wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
- # 安装该 rpm 包
- rpm -ivh MySQL-community-release-el7-5.noarch.rpm
- # 安装 MySQL
- yum install -y MySQL-server
- # 启动 MySQL
- systemctl start MySQL
PS. 通过这种方式的 MySQL 是默认开机启动的.
1.7 设置临时变量 (临时生效的变量, 换一个会话(shell 终端) 这个变量就没有了)
- export GOROOT=/usr/lib/golang
- export GOPATH=/opt/Git
1.8 从 GitHub 上拉取后端 (open-falcon) 的源码
- # 创建存放源码文件的目录
- mkdir -p $GOPATH/src/GitHub.com/open-falcon
- # 进入该目录
- cd $GOPATH/src/GitHub.com/open-falcon
- # 拉取源码
- Git clone https://github.com/open-falcon/falcon-plus.git
PS. 通过 Git clone 经常龟速, 所以可以通过本地获取源码后, 将源码文件上传到 / opt/Git/src/GitHub.com/open-falcon/falcon-plus 目录下.
1.9 初始化数据库
- # 进入目录
- cd $GOPATH/src/GitHub.com/open-falcon/falcon-plus/scripts/MySQL/db_schema
- # 执行 5 个脚本初始化数据库
- 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
PS. 在运行 "mysql -h.................." 时会提示 "Enter password", 如果 MySQL 的 root 没有设置密码, 回车即可.
1.10 编译后端的源码并打包
- # 进入目录
- cd $GOPATH/src/GitHub.com/open-falcon/falcon-plus
- # 编译所有模块
- make all
PS.17 年部署 0.2.0 时还需要手动获取 rrdtool 工具包, 现在 (19 年) 的版本 (0.2.1) 试下来已经不用了.
- # 打包
- make pack
打包完成后,/opt/Git/src/GitHub.com/open-falcon/falcon-plus / 目录下多了刚才打的压缩包 "open-falcon-v0.2.1.tar.gz"(因为整理手册的时候版本已经到了 0.2.1).
PS. 官方也有提供编译好的二进制包(https://book.open-falcon.org/zh_0_2/quick_install/prepare.html), 如果编译过程不顺利可以直接下载.
二, 部署后端
v0.2 后端分为下面几个服务模块:
功能 | |
---|---|
alarm | alarm 模块是处理报警 event 的,judge 产生的报警 event 写入 redis,alarm 从 redis 读取处理,并进行不同渠道的发送。 |
agent | agent 用于采集机器负载监控指标,比如 cpu.idle、load.1min、disk.io.util 等等,每隔 60 秒 push 给 Transfer.agent 与 Transfer 建立了长连接,数据发送速度比较快,agent 提供了一个 http 接口 / v1/push 用于接收用户手工 push 的一些数据,然后通过长连接迅速转发给 Transfer |
aggregator | 集群聚合模块。聚合某集群下的所有机器的某个指标的值,提供一种集群视角的监控体验。 |
api | api 模块提供统一的 restAPI 操作接口。比如:api 组件接收查询请求,根据一致性哈希算法去相应的 graph 实例查询不同 metric 的数据,然后汇总拿到的数据,最后统一返回给用户。 |
gateway | 没有遇到机房分区问题,可以忽略此模块。 |
graph | graph 是存储绘图数据的组件。graph 组件 接收 transfer 组件推送上来的监控数据,同时处理 api 组件的查询请求、返回绘图数据。 |
hbs | HBS(Heartbeat Server)心跳服务器,公司所有 agent 都会连到 HBS,每分钟发一次心跳请求。 |
judge | 用于告警判断,agent 将数据 push 给 Transfer,Transfer 不但会转发给 Graph 组件来绘图,还会转发给 Judge 用于判断是否触发告警。 |
nodata | nodata 用于检测监控数据的上报异常。nodata 和实时报警 judge 模块协同工作,过程为: 配置了 nodata 的采集项超时未上报数据,nodata 生成一条默认的模拟数据;用户配置相应的报警策略,收到 mock 数据就产生报警。采集项上报异常检测,作为 judge 模块的一个必要补充,能够使 judge 的实时报警功能更加可靠、完善。 |
task | task 是监控系统一个必要的辅助模块。定时任务,实现了如下几个功能:index 更新(包括图表索引的全量更新 和 垃圾索引清理)、falcon 服务组件的自身状态数据采集(采集了 transfer、graph、task 这三个服务的内部状态数据)、falcon 自检控任务 |
transfer | 数据转发服务。它接收 agent 上报的数据,然后按照哈希规则进行数据分片、并将分片后的数据分别 push 给 graph&judge 等组件。 |
2.1 设置临时变量
- # 设置后端工作目录的环境变量 (临时生效的变量, 换一个会话(shell 终端) 这个变量就没有了)
- export BACKSPACE=/opt/open-falcon/back
2.2 创建目录
- # 创建后端工作目录
- mkdir -p $BACKSPACE
2.3 解压包
- # 进入目录
- cd $GOPATH/src/GitHub.com/open-falcon/falcon-plus
- # 将 "1.9 编译源码并打包" 中的 "open-falcon-v0.2.1.tar.gz" 解压到后端工作目录 (BACKSPACE) 下.
- tar -xzvf open-falcon-v0.2.1.tar.gz -C $BACKSPACE
2.4 修改配置文件 cfg.JSON
如果需要每个模块正常启动, 需要将下面每个模块的 cfg.JSON 的数据库信息进行修改.
根据本教程的配置, 需要修改模块如下:
配置文件所在路径 | |
---|---|
aggregator | /opt/open-falcon/back/aggregator/config/cfg.json |
graph | /opt/open-falcon/back/graph/config/cfg.json |
hbs | /opt/open-falcon/back/hbs/config/cfg.json |
nodata | /opt/open-falcon/back/nodata/config/cfg.json |
api | /opt/open-falcon/back/api/config/cfg.json |
alarm | /opt/open-falcon/back/alarm/config/cfg.json |
1)编辑 aggregator 的配置文件 cfg.JSON
VIM /opt/open-falcon/back/aggregator/config/cfg.JSON
PS. 我部署 MySQL 的 root 密码为空, 所以不需要填 "password"; 若 MySQL 的 root 密码不为空, 则用 root 密码替换 "password".
2)编辑 graph 的配置文件 cfg.JSON
VIM /opt/open-falcon/back/graph/config/cfg.JSON
PS. 我部署 MySQL 的 root 密码为空, 所以不需要填 "password"; 若 MySQL 的 root 密码不为空, 则用 root 密码替换 "password".
3)编辑 hbs 的配置文件 cfg.JSON
VIM /opt/open-falcon/back/hbs/config/cfg.JSON
PS. 我部署 MySQL 的 root 密码为空, 所以不需要填 "password"; 若 MySQL 的 root 密码不为空, 则用 root 密码替换 "password".
4)编辑 nodata 的配置文件 cfg.JSON
VIM /opt/open-falcon/back/nodata/config/cfg.JSON
PS. 我部署 MySQL 的 root 密码为空, 所以不需要填 "password"; 若 MySQL 的 root 密码不为空, 则用 root 密码替换 "password".
5)编辑 API 的配置文件 cfg.JSON
VIM /opt/open-falcon/back/API/config/cfg.JSON
PS. 我部署 MySQL 的 root 密码为空, 所以不需要填 "password"; 若 MySQL 的 root 密码不为空, 则用 root 密码替换 "password".
6)编辑 alarm 的配置文件 cfg.JSON
VIM /opt/open-falcon/back/alarm/config/cfg.JSON
PS. 我部署 MySQL 的 root 密码为空, 所以不需要填 "password"; 若 MySQL 的 root 密码不为空, 则用 root 密码替换 "password".
2.5 启动后端
- # 启动所有模块
- cd /opt/open-falcon/back
- ./open-falcon start
2.6 设置开机启动
请参考 "四, 设置开机启动".
2.7 其他操作命令
open-falcon 还提供了下面这些命令:
- # 检查所有模块的启动情况
- cd /opt/open-falcon/back
- ./open-falcon check
- # 停止所有模块
- cd /opt/open-falcon/back
- ./open-falcon stop
- # 启动指定的模块(以 alarm 模块为例)
- cd /opt/open-falcon/back
- ./open-falcon start alarm
- # 停止指定的模块(以 alarm 模块为例)
- cd /opt/open-falcon/back
- ./open-falcon stop alarm
- # 重启指定的模块(以 alarm 模块为例)
- cd /opt/open-falcon/back
- ./open-falcon restart alarm
三, 部署前端
3.1 设置临时变量
- # 设置前端工作目录的环境变量 (临时生效的变量, 换一个会话(shell 终端) 这个变量就没有了)
- export FRONTSPACE=/opt/open-falcon/front
3.2 创建目录
- # 创建前端工作目录
- mkdir -p $FRONTSPACE
3.3 从 GitHub 上拉取前端 (dashboard) 的源码
- cd $FRONTSPACE
- Git clone https://github.com/open-falcon/dashboard.git
PS. 通过 Git clone 经常龟速, 所以可以通过本地获取源码后, 将源码文件上传到 / opt/open-falcon/front/dashboard 目录下.
3.4 安装依赖
- yum install -y python-virtualenv
- yum install -y python-devel
- yum install -y openldap-devel
- yum install -y MySQL-devel
- yum groupinstall -y "Development tools"
- # 通过 virtualenv 创建目录 env 作为独立的运行环境
- cd $FRONTSPACE/dashboard
- virtualenv ./env
- # 生成 requirements.txt 并安装依赖
- ./env/bin/pip install -r pip_requirements.txt
PS. 官方教程中使用了下面的命令安装依赖包(指定了安装包的源地址)
./env/bin/pip install -r pip_requirements.txt -i https://pypi.douban.com/simple
3.5 修改配置
根据本教程的配置, dashboard 的配置文件在 / opt/open-falcon/front/dashboard/rrd/config.py
爬坑点:
原本不接入 LDAP, 数据库 root 账号密码为空不需要修改配置, 但是官方给出的配置文件在这里留了一个坑: PORTAL_DB 的用户名 / 密码初始为 falcon/falcon.
这个坑最终会导致 dashboard 登录后的 "HostGroups","Templates","Expressions","Nodata", 下面提供解决方案, 也就是将错误的初始配置改过来.
- # 编辑 dashboard 配置文件 config.py
- VIM /opt/open-falcon/front/dashboard/rrd/config.py +33
将 portal 的数据库用户名改为 root, 密码改为空, wq 保存.
3.6 启动前端
- # 启动
- cd $FRONTSPACE/dashboard
- bash control start
3.7 设置开机启动
参考 "四, 设置开机启动".
3.8 其他操作命令
dashboard 还提供了下面这些命令:
- # 检查 dashboard 的启动情况
- cd /opt/open-falcon/front/dashboard
- bash control status
- # 停止 dashboard
- cd /opt/open-falcon/front/dashboard
- bash control stop
- # 以开发者模式启动
- cd /opt/open-falcon/front/dashboard
- ./env/bin/python wsgi.py
四, 设置开机启动
由于 open-falcon 没有 service 实现开机启动, 所以需要额外找方案来解决这个问题.
这里提供一套方案: 通过进程守护服务 (Supervisor) 实现 open-falcon 的开机启动.
4.1 安装 supervisor
- yum install -y python-setuptools
- easy_install supervisor
4.2 修改配置文件 supervisord.conf
- # 创建目录
- mkdir -p /etc/supervisor/conf.d
- # 创建 supervisord.conf 的模板文件
- echo_supervisord_conf> /etc/supervisor/supervisord.conf
- # 编辑 supervisord.conf
- VIM /etc/supervisor/supervisord.conf
将下面的内容添加到 supervisord.conf 内, wq 保存.
- [include]
- files = conf.d/*.conf
4.3 创建 open-falcon 启动脚本
- # 创建目录
- mkdir -p /opt/sh
- # 编辑 open-falcon-startup.sh
- VIM /opt/sh/open-falcon-startup.sh
将下面的内容添加到 open-falcon-startup.sh 内, wq 保存.
- #!/bin/bash
- sleep 30s && /opt/open-falcon/back/open-falcon start
PS. 引入启动脚本 (延迟 30s 启动) 的原因: 在 open-falcon 启动时, MySQL 没有启动完成, 将会导致部分服务启动失败, 而 supervisord 又检测不到 open-falcon 每个服务的进程, 结果导致 open-falcon 部分服务 (aggregator,agent,gateway,API,alarm) 启动失败.
4.4 修改需要守护的进程配置
- # 编辑 open-falcon-back.conf
- VIM /etc/supervisor/conf.d/open-falcon-back.conf
将下面的内容添加到 open-falcon-back.conf 内, wq 保存.
[program:open-falcon-back]
command=/bin/bash /opt/sh/open-falcon-startup.sh ; 运行程序的命令
directory=/opt/open-falcon/back ; 命令执行的目录
user=root ; 进程执行的用户身份
autostart=true ; 在 supervisord 启动时运行该程序
autorestart=true ; 程序异常退出后自动重启
stdout_logfile=/var/log/open-falcon-back.out.log ; 输出日志文件
stdout_logfile_maxbytes=10MB ; 输出日志文件大小(10MB)
stdout_logfile_backups=5 ; 输出日志文件备份数
stderr_logfile=/var/log/open-falcon-back.err.log ; 错误日志文件
stderr_logfile_maxbytes=10MB ; 错误日志文件大小(10MB)
stderr_logfile_backups=5 ; 错误日志文件备份数
- # 编辑 open-falcon-front.conf
- VIM /etc/supervisor/conf.d/open-falcon-front.conf
将下面的内容添加到 open-falcon-front.conf 内, wq 保存.
[program:open-falcon-front]
command=/bin/bash /opt/open-falcon/front/dashboard/control start ; 运行程序的命令
directory=/opt/open-falcon/front/dashboard ; 命令执行的目录
user=root ; 进程执行的用户身份
autostart=true ; 在 supervisord 启动时运行该程序
autorestart=true ; 程序异常退出后自动重启
stdout_logfile=/var/log/open-falcon-front.out.log ; 输出日志文件
stdout_logfile_maxbytes=10MB ; 输出日志文件大小
stdout_logfile_backups=5 ; 输出日志文件备份数
stderr_logfile=/var/log/open-falcon-front.err.log ; 错误日志文件
stderr_logfile_maxbytes=10MB ; 错误日志文件大小
stderr_logfile_backups=5 ; 错误日志文件备份数
4.5 创建 supervisor 的 service 文件
- # 编辑 supervisord.service
- VIM /usr/lib/systemd/system/supervisord.service
将下面的内容添加到 supervisord.service 内, wq 保存.
- [Unit]
- Description=Supervisor
- [Service]
- Type=forking
- ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
- ExecStop=/usr/bin/supervisorctl shutdown
- ExecReload=/usr/bin/supervisorctl reload
- KillMode=process
- Restart=on-failure
- RestartSec=42s
- [Install]
- WantedBy=multi-user.target
4.6 启动, 开机启动 supervisor
- systemctl start supervisord
- systemctl enable supervisord
4.7 查看 supervisor 启动程序的状态
supervisorctl status
这里 open-falcon-front 状态为 FATAL 可能是因为启动比较快导致, 实际上 dashboard 已经成功启动了.
五, 使用 open-falcon
5.1 访问 open-falcon 的页面
由于手册部署用的虚拟机 IP 为 192.168.12.55, 故浏览器访问 http://192.168.12.55:8081
5.2 创建超级管理员(root)
dashboard 没有默认创建任何账号(包括管理员账号), 需要通过页面进行注册账号.
注册用户名为 root 的账号(第一个帐号名称为 root 的用户, 会被自动设置为超级管理员).
1)点击 "sign up"
2)填写用户名, 中文名, email, 密码后, 点击 "sign up" 创建 root 账号
5.3 关闭注册功能
注册账号能够被任何打开 dashboard 页面的人注册, 有时候我们不允许任何人都可以随便访问监控数据. 所以当创建完 root 账号 (系统管理员) 后, 可以关闭注册账号功能. 没有接入 LDAP 的话, 可以通过 root 账号增加用户账号.
根据本教程的配置, API 的配置文件所在路径如下:
配置文件所在路径 | |
---|---|
api | /opt/open-falcon/back/api/config/cfg.json |
- # 编辑 API 的配置文件 cfg.JSON
- VIM /opt/open-falcon/back/API/config/cfg.JSON
将 signup_disable 配置项修改为 true,wq 保存.
- # 重启 API 模块
- cd /opt/open-falcon/back
- ./open-falcon restart API
5.4 创建普通用户
没有接入 LDAP, 允许用户自由创建账号登录, 将 "4.3 关闭注册功能" 的配置改回来;
没有接入 LDAP, 不允许用户随意创建账号登录, 让管理员用 root 账号创建用户账号;
接入 LDAP, 直接使用 LDAP 账号登录;
来源: http://www.bubuko.com/infodetail-3333258.html