centos7 deployment of open-falcon 0.2.1

Deployment Guide from finishing the last of the open-falcon ( https://www.cnblogs.com/straycats/p/7199209.html ) has been more than a year, then just contact with linux, a lot of things in order is not very reasonable (for example, Some description of the operation), the deployment of some of the content is not very strict (such as how to boot from Kai).

Just recently doing the monitoring system of selection, open-falcon I was again out as a test target. Later, some of the differences between 0.2.1 and 0.2.0 deployment, I decided to re-deploy for 0.2.1 compile a manual for reference passers together.

 

As the new document to change some of the deployment paths and configure content before the document, based on the recommendations capability is not strong students can ignore my 17 years of finishing 0.2.0 version of the Deployment Guide, direct look at this manual.

 


Before deploying a system, the first concern of the entire architecture, where the official map directly to the Pirates over.

 

 


First, prepare the environment

OS: CentOS 7.6 ( www.centos.org download package is CentOS-7-x86_64-Minimal- 1810.iso)

Virtual machine IP: 192.168.12.55

 

1.1 Configure the firewall

# In order to facilitate you can choose to directly turn off the firewall

systemctl stop firewalld
systemctl disable firewalld

 

Of course, if you need to open the firewall, open ports on the need to open several businesses.

Service Module Features port
hbs Connect all service agent heartbeat 6030
transfer Receiving the monitoring data sent from the agent 8433
dashboard page 8081

# Open ports 6030,8433,8081, allows any IP access

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账号登录;

Guess you like

Origin www.cnblogs.com/hftian/p/12045977.html