专栏首页云计算大冒险open-falcon安装使用监控树莓派

抱歉,你查看的文章已删除

open-falcon安装使用监控树莓派

简介

open-falcon是一款用golang和python写的监控系统,由小米启动这个项目。 官方网址 http://open-falcon.org/ 文档 https://book.open-falcon.org/zh_0_2/ 今天我要安装的是0.2版本,监控的是树莓派。系统是阿里云ecs centos7.4

安装准备

  • 安装redis yum install redis 启动redis服务 systemctl start redis 让redis开机自启 systemctl enable redis
  • 安装mariadb yum install mariadb-server 启动mariadb服务 systemctl start mariadb 让mariadb开机启动 systemctl enable mariadb 初始化mariadb密码
[root@izuf6hyujh57q98bebkndoz ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

我解释下上面每步都是做什么的 Enter current password for root (enter for none): 当你第一次运行时直接回车就好,就是问你原来的root密码是什么,因为第一次运行,所以直接回车就好 Set root password? [Y/n] y 问你是不是设置root密码 Remove anonymous users? [Y/n] y 问你是不是移除匿名用户 Disallow root login remotely? [Y/n] y 禁止root远程登录 Remove test database and access to it? [Y/n] y 移除test数据库 Reload privilege tables now? [Y/n] y 重新加载权限表 最后运行mysql -uroot -p登入mariadb验证下

  • 导入open-falcon数据表 安装git yum install git 下载falcon-plus里面有open-falcon的数据库导入就好 git clone https://github.com/open-falcon/falcon-plus.git 进入下面这个目录,然后执行下面命令 cd /root/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

之后你会发现数据库中多出了下面这些数据库

+--------------------+
| Database           |
+--------------------+
| information_schema |
| alarms             |
| dashboard          |
| falcon_portal      |
| graph              |
| mysql              |
| performance_schema |
| uic                |
+--------------------+
  • 下载open-falcon的安装包

如果你是其他平台的比如arm或是32位系统的要自己编译下,我就直接使用二进制包安装好了 wget https://github.com/open-falcon/falcon-plus/releases/download/v0.2.1/open-falcon-v0.2.1.tar.gz 因为网速较慢所以建议本地挂代理下载之后上传到服务器上

启动后端

因为是编译好的包,所以我们就不需要各种复杂的设置了,直接启动就好了 我把所有文件放在home文件夹中work下 mkdir -p /home/work/open-falcon tar -zxvf open-falcon-v0.2.1.tar.gz -C /home/work/open-falcon/ 修改配置文件,其实就是修改所有组件的cfg.json的mariadb密码,我的意思是如果这个组件用到mariadb的话 首先修改aggregator的 vim /home/work/open-falcon/aggregator/config/cfg.json 改为

    "database": {
        "addr": "root:Yuncan1803@tcp(127.0.0.1:3306)/falcon_portal?loc=Local&parseTime=true",
        "idle": 10,
        "ids": [1, -1],
        "interval": 55
    },

注意第二行Yuncan1803是密码,root是用户名其他的都一样 接着修改graph的 vim graph/config/cfg.json

    "db": {
        "dsn": "root:Yuncan1803@tcp(127.0.0.1:3306)/graph?loc=Local&parseTime=true",
        "maxIdle": 4
    },

修改hbs的 vim hbs/config/cfg.json

{
    "debug": true,
    "database": "root:Yuncan1803@tcp(127.0.0.1:3306)/falcon_portal?loc=Local&parseTime=true",
    "hosts": "",
    "maxConns": 20,
    "maxIdle": 15,
    "listen": ":6030",
    "trustable": [""],
    "http": {
        "enabled": true,
        "listen": "0.0.0.0:6031"
    }
}

修改nodata的 vim nodata/config/cfg.json

    "config": {
        "enabled": true,
        "dsn": "root:Yuncan1803@tcp(127.0.0.1:3306)/falcon_portal?loc=Local&parseTime=true&wait_timeout=604800",
        "maxIdle": 4
    },

修改api的 vim api/config/cfg.json

        "db": {
                "falcon_portal": "root:Yuncan1803@tcp(127.0.0.1:3306)/falcon_portal?charset=utf8&parseTime=True&loc=Local",
                "graph": "root:Yuncan1803@tcp(127.0.0.1:3306)/graph?charset=utf8&parseTime=True&loc=Local",
                "uic": "root:Yuncan1803@tcp(127.0.0.1:3306)/uic?charset=utf8&parseTime=True&loc=Local",
                "dashboard": "root:Yuncan1803@tcp(127.0.0.1:3306)/dashboard?charset=utf8&parseTime=True&loc=Local",
                "alarms": "root:Yuncan1803@tcp(127.0.0.1:3306)/alarms?charset=utf8&parseTime=True&loc=Local",
                "db_bug": true
        },

修改alarm的 vim alarm/config/cfg.json

    "falcon_portal": {
        "addr": "root:Yuncan1803@tcp(127.0.0.1:3306)/alarms?charset=utf8&loc=Asia%2FChongqing",
        "idle": 10,
        "max": 100
    },

最好,终于他妈最后了,启动后端 ./open-falcon start 你可以用下面的命令检查所有组件的状态 ./open-falcon check

[root@izuf6hyujh57q98bebkndoz open-falcon]# ./open-falcon check
        falcon-graph         UP           27849 
          falcon-hbs         UP           27858 
        falcon-judge         UP           27868 
     falcon-transfer         UP           27876 
       falcon-nodata         UP           27883 
   falcon-aggregator         UP           27891 
        falcon-agent         UP           27901 
      falcon-gateway         UP           27908 
          falcon-api         UP           27915 
        falcon-alarm         UP           27929

更多命令的用法 ./open-falcon [start|stop|restart|check|monitor|reload] module 比如./open-falcon start agent 这样就启动了agent ./open-falcon check这个是检查组件状态的 所有组件的日志都在组件目录下logs目录中

安装前端

首先把代码clone下来 cd /home/work/open-falcon 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 dashboard virtualenv ./env 安装python依赖 ./env/bin/pip install -r pip_requirements.txt 修改配置 vim rrd/config.py PORTAL_DB_PASS = os.environ.get("PORTAL_DB_PASS","Yuncan1803") ALARM_DB_PASS = os.environ.get("ALARM_DB_PASS","Yuncan1803") 在生产环境启动

[root@izuf6hyujh57q98bebkndoz dashboard]# bash control start
falcon-dashboard started..., pid=8190

下面是一些其他操作 开发者模式启动 ./env/bin/python wsgi.py

停止 bash control stop

查看日志 bash control tail

账号管理

首先我们用ip:8081访问open-falcon,接着要知道的是falcon默认没有任何用户,新建的第一个root用户就是管理员,为了安全你可以修改api组件的配置文件 vim api/config/cfg.json 中的 "signup_disable": false, 设置为true就可以禁止注册了

树莓派上安装

这个肯定是要编译的了,所以先下载golang安装 因为实在树莓派下,所以golang要编译安装,但是现在最新版本的golang都是用go编译的,所以因为我们系统中没有go,只能先安装1.4版本的c语言版本go,之后安装最新版本的go 首先下载 wget https://dl.google.com/go/go1.4.3.src.tar.gz 解压 tar -zxvf go1.4.3.src.tar.gz 编译 cd go/src ./make.bash 因为是树莓派所以编译肯定花点时间 移动go到/root/go1.4 mv go /root/go1.4 /root/go1.4是默认$GOROOT_BOOTSTRAP的值 接着下载最新版本的go wget https://dl.google.com/go/go1.9.3.src.tar.gz 解压 tar -zxvf go1.9.3.src.tar.gz 编译 cd go/src ./make.bash 编译好后接着移动到/usr/local/目录下 mv go /usr/local 设置环境变量 vim ~/.zshrc

export GOROOT=/usr/local/go
export GOPATH=/root/go
export PATH=$PATH:GOROOT/bin

使环境变量生效 source ~/.zshrc

接着编译安装open-falcon的agent 新建一个目录下载源码 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 进入agent源码目录 cd falcon-plus/modules/agent 下载依赖 go get 编译 ./control build 接着把agent这个文件夹放入/usr/loca/目录 mv agent /usr/local 启动agent生成配置文件 cd /usr/local/agent ./control start 编辑配置文件

{
    "debug": true,
    "hostname": "raspberry",
    "ip": "",
    "plugin": {
        "enabled": false,
        "dir": "./plugin",
        "git": "https://github.com/open-falcon/plugin.git",
        "logs": "./logs"
    },
    "heartbeat": {
        "enabled": true,
        "addr": "ip:6030",
        "interval": 60,
        "timeout": 1000
    },
    "transfer": {
        "enabled": true,
        "addrs": [
            "ip:8433"
        ],
        "interval": 60,
        "timeout": 1000
    },
    "http": {
        "enabled": true,
        "listen": ":1988",
        "backdoor": false
    },
    "collector": {
        "ifacePrefix": ["eth", "em"],
        "mountPoint": []
    },
    "default_tags": {
    },
    "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
    }
}

重启 ./control restart 和zabbix比起来这个配置真的少了很多,除了HOSTNAME以外就是ip要改,而且挺简单的,dashboard上也不用设置,等会就会有数据出来

欢迎关注Bboysoul的博客www.bboysoul.com Have Fun

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • 查找当前目录下的大于1M的文件的各种实现

    用户3765803
  • DC-7靶机渗透实战

    这次的靶机渗透实战是一个找寻靶机中的flag的过程,并以获得最终的flag为目标。靶机下载地址[1],需要更详细的资料可以参考文章1[2]、文章2[3]、文章3...

    轩辕小子
  • Oracle通过HSODBC访问mysql

    一、环境 OS:Linux myhostname 2.6.9-42.ELsmp #1 SMP Sat Aug 12 09:39:11 CDT 2006 i686...

    用户1148526
  • 127个常用的JS代码片段,每段代码花30秒就能看懂(四)

    用于判断参数的值是否是对象,这里运用了Object 构造函数创建一个对象包装器,如果是对象类型,将会原值返回。

    前端达人
  • 速读原著-TCP/IP(Unix选路守护程序)

    U n i x系统上常常运行名为r o u t e d路由守护程序。几乎在所有的 T C P / I P实现中都提供该程序。该程序只使用R I P进行通信,我们...

    cwl_java
  • Swagger自动生成API文档

    最近安装并使用了一下Swagger-ui、Swagger-editor和Swagger-codegen,感觉还不错。

    javascript.shop
  • 带你认识 flask 时间日期

    使用服务器端的Python渲染日期和时间来展示到用户的浏览器并非一个好主意。考虑如下的例子, 我在2017年9月28日下午4点06分写这篇文章。我身处的时区是P...

    公众号---人生代码

扫码关注云+社区

领取腾讯云代金券