Open-Falcon学习笔记(一)Open-Falcon v0.3.0环境搭建

一、主机准备

操作系统

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)
主机名IP服务
nginx_master192.168.1.171Nginx、open-falcon-agent
nginx_backup192.168.1.172Nginx、open-falcon-agent、
tomcat_server1192.168.1.173Tomcat、open-falcon-agent、Redis
tomcat_server2192.168.1.174Tomcat、open-falcon-agent、MySQL
open-falcon_server192.168.1.175open-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

6.4 按照此操作加入其他主机

在这里插入图片描述

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Open-Falcon 是一款开源的监控系统,可以监控各种资源的状态,包括服务器负载、网络状态、应用程序指标等。它提供了丰富的监控指标和灵活的告警机制,可以帮助运维人员及时发现和解决问题。下面是 Spring Boot 整合 Open-Falcon 的简单示例。 1. 引入依赖 在 pom.xml 文件中添加 Open-Falcon 的客户端依赖: ```xml <dependency> <groupId>com.github.open-falcon</groupId> <artifactId>falcon-sdk-java</artifactId> <version>0.1.0</version> </dependency> ``` 2. 配置 Open-Falcon 客户端 在 application.properties 文件中配置 Open-Falcon 客户端相关属性: ```properties # Open-Falcon 服务地址 falcon.server=http://localhost:6060/api/push # 应用程序名称 falcon.endpoint=my-application ``` 3. 编写监控指标 在代码中编写需要监控的指标,如 CPU 使用率、内存使用率等。可以使用 Open-Falcon 客户端提供的 API 将指标发送到 Open-Falcon 服务端: ```java import com.github.openfalcon.push.PushClient; import com.github.openfalcon.push.PushEntity; public class MyMonitor { private PushClient pushClient; public MyMonitor(String falconServer, String endpoint) { pushClient = new PushClient(falconServer, endpoint); } public void reportCpuUsage(float usage) { PushEntity entity = new PushEntity("cpu.usage", String.valueOf(usage), "", ""); pushClient.push(entity); } public void reportMemoryUsage(float usage) { PushEntity entity = new PushEntity("memory.usage", String.valueOf(usage), "", ""); pushClient.push(entity); } // 其他监控指标 } ``` 4. 启动应用程序 在应用程序启动时,创建监控对象,并在需要监控的地方调用相应的监控方法。 ```java import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); MyMonitor monitor = new MyMonitor("http://localhost:6060/api/push", "my-application"); while (true) { float cpuUsage = getCpuUsage(); float memoryUsage = getMemoryUsage(); monitor.reportCpuUsage(cpuUsage); monitor.reportMemoryUsage(memoryUsage); Thread.sleep(1000); } } private static float getCpuUsage() { // 获取 CPU 使用率 return 0.5f; } private static float getMemoryUsage() { // 获取内存使用率 return 0.6f; } } ``` 以上是一个简单的 Spring Boot 整合 Open-Falcon 的示例,具体的监控指标和告警机制可以根据实际需求进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值