文章目录
一、主机准备
操作系统
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
主机名 | IP | 服务 |
---|---|---|
nginx_master | 192.168.1.171 | Nginx、open-falcon-agent |
nginx_backup | 192.168.1.172 | Nginx、open-falcon-agent、 |
tomcat_server1 | 192.168.1.173 | Tomcat、open-falcon-agent、Redis |
tomcat_server2 | 192.168.1.174 | Tomcat、open-falcon-agent、MySQL |
open-falcon_server | 192.168.1.175 | open-falcon-server |
二、参考文档
官方文档
官方中文社区
运维监控系统之Open-Falcon
运维监控系统之Open-Falcon
小米运维架构服务监控Open-Falcon
三 、环境配置
3.1 配置阿里YUM源、安装基本工具
yum install -y wget \
&& mkdir -p /etc/yum.repos.d/repo_bak \
&& mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo_bak/ \
&& wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo \
&& wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo \
&& yum install -y vim git net-tools lrzsz ntp unzip \
&& yum makecache && yum clean all
3.2 关闭防火墙、Selinux
# 关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
# 关闭Selinux
setenforce 0 && sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
3.3 修改主机名
hostnamectl set-hostname open-falcon_server && echo "192.168.1.175 open-falcon_server" >> /etc/hosts
3.4 配置时间同步
关闭chrony服务
systemctl stop chronyd && systemctl disable chronyd
设置NTP服务
vim /etc/ntp.conf
# 将时钟服务器更改为如下4个
server 0.cn.pool.ntp.org
server 1.cn.pool.ntp.org
server 2.cn.pool.ntp.org
server 3.cn.pool.ntp.org
启动时间同步服务器
systemctl start ntpd \
&& systemctl enable ntpd \
&& ntpdate -u 0.cn.pool.ntp.org \
&& hwclock --systohc \
&& date
3.5 安装go环境
yum install -y golang && go version
3.6 安装pip环境
wget https://bootstrap.pypa.io/get-pip.py
# 这一步ERROR报错的话多试几次
python get-pip.py
3.7 安装Redis
yum install -y redis \
&& systemctl start redis \
&& systemctl enable redis
3.8 安装Mariadb
yum安装mariadb
yum install -y mariadb mariadb-server \
&& systemctl start mariadb \
&& systemctl enable mariadb
导入open-falcon数据库
mkdir -p /home/work/open-falcon \
&& cd /home/work/open-falcon \
&& git clone https://github.com/open-falcon/falcon-plus.git
执行MySQL脚本
cd ./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
# 查看数据库
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| alarms |
| dashboard |
| falcon_portal |
| graph |
| mysql |
| performance_schema |
| test |
| uic |
+--------------------+
9 rows in set (0.00 sec)
设置数据库密码
mysqladmin -uroot password "123456"
四、安装后端
4.1 下载安装包
wget https://github.com/open-falcon/falcon-plus/releases/download/v0.3/open-falcon-v0.3.tar.gz
tar -zxvf open-falcon_v0.3.tar.gz -C /home/work/open-falcon/
4.2 修改配置文件
每个模块都修改连接数据库的配置
模块 | 路径 |
---|---|
aggregator | ./aggregator/config/cfg.json |
graph | ./graph/config/cfg.json |
hbs | ./hbs/config/cfg.json |
nodata | ./nodata/config/cfg.json |
api | ./api/config/cfg.json |
alarm | ./alarm/config/cfg.json |
快捷修改脚本
sed -i 's#root:@tcp(127.0.0.1:3306)#root:123456@tcp(127.0.0.1:3306)#g' `find ./ -type f -name "cfg.json"|egrep "alarm|api|nodata|hbs|graph|aggregator"`
查看是否修改成功
cat `find ./ -type f -name "cfg.json"|egrep "alarm|api|nodata|hbs|graph|aggregator"` |grep 'root:123456@tcp(127.0.0.1:3306)'
显示如下内容
"addr": "root:123456@tcp(127.0.0.1:3306)/falcon_portal?loc=Local&parseTime=true",
"dsn": "root:123456@tcp(127.0.0.1:3306)/graph?loc=Local&parseTime=true",
"database": "root:123456@tcp(127.0.0.1:3306)/falcon_portal?loc=Local&parseTime=true",
"dsn": "root:123456@tcp(127.0.0.1:3306)/falcon_portal?loc=Local&parseTime=true&wait_timeout=604800",
"falcon_portal": "root:123456@tcp(127.0.0.1:3306)/falcon_portal?charset=utf8&parseTime=True&loc=Local",
"graph": "root:123456@tcp(127.0.0.1:3306)/graph?charset=utf8&parseTime=True&loc=Local",
"uic": "root:123456@tcp(127.0.0.1:3306)/uic?charset=utf8&parseTime=True&loc=Local",
"dashboard": "root:123456@tcp(127.0.0.1:3306)/dashboard?charset=utf8&parseTime=True&loc=Local",
"alarms": "root:123456@tcp(127.0.0.1:3306)/alarms?charset=utf8&parseTime=True&loc=Local",
"addr": "root:123456@tcp(127.0.0.1:3306)/alarms?charset=utf8&loc=Local",
4.3 启动
使用脚本启动
[root@open-falcon_server open-falcon]# ./open-falcon start
[falcon-graph] 28776
[falcon-hbs] 28787
[falcon-judge] 28798
[falcon-transfer] 28805
[falcon-nodata] 28814
[falcon-aggregator] 28823
[falcon-agent] 28833
[falcon-gateway] 28843
[falcon-api] 28852
[falcon-alarm] 28867
使用脚本检查
[root@open-falcon_server open-falcon]# ./open-falcon check
falcon-graph UP 28776
falcon-hbs UP 28787
falcon-judge UP 28798
falcon-transfer UP 28805
falcon-nodata UP 28814
falcon-aggregator UP 28823
falcon-agent UP 28833
falcon-gateway UP 28843
falcon-api UP 28852
falcon-alarm UP 28867
更多命令行工具用法
./open-falcon [start|stop|restart|check|monitor|reload] module
启动agent监控自身主机
[root@localhost open-falcon]# ./open-falcon start agent
[falcon-agent] 8357
五、安装前端
5.1 下载前端代码
mkdir - p /home/work/dashboard
cd /home/work/dashboard
git clone https://github.com/open-falcon/dashboard.git
5.2 安装依赖包
cd /home/work/dashboard/dashboard \
&& yum install -y python-virtualenv python-devel openldap-devel mysql-devel \
&& yum groupinstall -y "Development tools" \
&& virtualenv ./env \
&& ./env/bin/pip install -r pip_requirements.txt -i https://pypi.douban.com/simple
5.4 修改配置
修改数据库连接密码,dashboard的配置文件为: 'rrd/config.py'
## API_ADDR 表示后端api组件的地址
API_ADDR = "http://127.0.0.1:8080/api/v1"
5.5 启动前端
[root@open-falcon_server dashboard-master]# ./control start
falcon-dashboard started..., pid=32055
[root@open-falcon_server dashboard-master]# ./control tail
[2020-03-12 15:23:17 +0000] [32055] [INFO] Starting gunicorn 19.9.0
[2020-03-12 15:23:17 +0000] [32055] [INFO] Listening at: http://0.0.0.0:8081 (32055)
[2020-03-12 15:23:17 +0000] [32055] [INFO] Using worker: sync
[2020-03-12 15:23:17 +0000] [32060] [INFO] Booting worker with pid: 32060
[2020-03-12 15:23:17 +0000] [32061] [INFO] Booting worker with pid: 32061
[2020-03-12 15:23:17 +0000] [32070] [INFO] Booting worker with pid: 32070
[2020-03-12 15:23:17 +0000] [32071] [INFO] Booting worker with pid: 32071
更多命令行工具用法
./control start|stop|restart|status|tail|kill9|version|pack
登陆Web页面:http://192.168.1.175:8081/
注意事项
dashbord没有默认创建任何账号包括管理账号,需要你通过页面进行注册账号。
想拥有管理全局的超级管理员账号,需要手动注册用户名为root的账号(第一个帐号名称为root的用户会被自动设置为超级管理员)。
超级管理员可以给普通用户分配权限管理。
小提示:注册账号能够被任何打开dashboard页面的人注册,所以当给相关的人注册完账号后,需要去关闭注册账号功能。只需要去修改api组件的配置文件cfg.json,将signup_disable配置项修改为true,重启api即可。当需要给人开账号的时候,再将配置选项改回去,用完再关掉即可。
六、监控其他主机
将后端安装包中的agent目录和open-falcon脚本发送到需要被监控的主机
scp -r agent/ open-falcon 192.168.1.171:/root/
登陆被监控主机
6.1 配置环境
yum install -y vim ntp
修改主机名
hostnamectl set-hostname nginx_master && echo "192.168.1.171 nginx_master" >> /etc/hosts
关闭chrony服务
systemctl stop chronyd && systemctl disable chronyd
设置NTP服务
vim /etc/ntp.conf
# 将时钟服务器更改为如下4个
server 0.cn.pool.ntp.org
server 1.cn.pool.ntp.org
server 2.cn.pool.ntp.org
server 3.cn.pool.ntp.org
启动时间同步服务器
systemctl start ntpd \
&& systemctl enable ntpd \
&& ntpdate -u 0.cn.pool.ntp.org \
&& hwclock --systohc \
&& date
6.2 修改agent配置
vim agent/config/cfg.json
修改为监控主机的IP
{
"debug": true,
"hostname": "",
"ip": "",
"plugin": {
"enabled": false,
"dir": "./plugin",
"git": "https://github.com/open-falcon/plugin.git",
"logs": "./logs"
},
"heartbeat": {
"enabled": true,
"addr": "192.168.1.175:6030",
"interval": 60,
"timeout": 1000
},
"transfer": {
"enabled": true,
"addrs": [
"192.168.1.175:8433"
],
"interval": 60,
"timeout": 1000
},
"http": {
"enabled": true,
"listen": ":1988",
"backdoor": false
},
"collector": {
"ifacePrefix": ["eth", "em"],
"mountPoint": []
},
"default_tags": {
},
"ignore": { #该项为忽略监控项,存在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
}
}
6.3 启动服务
[root@localhost ~]# ./open-falcon start agent
[falcon-agent] 7538
# 停止进程
./open-falcon stop agent
# 查看日志
./open-falcon monitor agent