CentOS 7 安装osquery监控系统

osquery 简介

  • osquery是一个SQL驱动操作系统检测和分析工具。osquery支持像SQL语句一样查询系统的各项指标,可以用于OSX和Linux操作系统。它使得底层操作系统分析和监控性能更加直观
  • 项目主页:http://osquery.io/
  • 代码托管地址:https://github.com/facebook/osquer
    这里写图片描述

osquery 安装

[root@linuxprobe~]# yum -y install https://osquery-packages.s3.amazonaws.com/centos7/noarch/osquery-s3-centos7-repo-1-0.0.noarch.rpm
[root@linuxprobe~]# yum -y install osquery 

osquery 使用文档: https://osquery.io/docs/tables/

# 使用例子
# run osquery shell
[root@linuxprobe~]# osqueryi
osquery - being built, with love, at Facebook
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Using a virtual database. Need help, type '.help'
osquery> 
# show all column of tables for OS version
osquery> select * from os_version; 
+--------------+----------+-------+-------+-------+-------+----------+---------------+----------+
| name         | version  | major | minor | patch | build | platform | platform_like | codename |
+--------------+----------+-------+-------+-------+-------+----------+---------------+----------+
| CentOS Linux | 7 (Core) | 7     |       |       |       | centos   | rhel fedora   |          |
+--------------+----------+-------+-------+-------+-------+----------+---------------+----------+

# show some column of tables for System info
osquery> select hostname, cpu_brand, hardware_vendor, hardware_model from system_info; 
+----------------+-----------------------------------------+-----------------+-------------------------+
| hostname       | cpu_brand                               | hardware_vendor | hardware_model          |
+----------------+-----------------------------------------+-----------------+-------------------------+
| linuxprobe.org | Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz | VMware, Inc.    | VMware Virtual Platform |
+----------------+-----------------------------------------+-----------------+-------------------------+

# show some column of tables and also specify over 1000 of UID for User info
osquery> select uid, gid, username, shell from users where uid >= 1000; 
+-------+-------+-----------+---------------+
| uid   | gid   | username  | shell         |
+-------+-------+-----------+---------------+
| 1000  | 1000  | shaon     | /bin/bash     |
| 1001  | 1001  | wang      | /bin/bash     |
| 65534 | 65534 | nfsnobody | /sbin/nologin |
+-------+-------+-----------+---------------+

# show all column of tables for CPU Time
osquery> select * from cpu_time; 
+------+------+------+--------+-------+--------+-----+---------+-------+-------+------------+
| core | user | nice | system | idle  | iowait | irq | softirq | steal | guest | guest_nice |
+------+------+------+--------+-------+--------+-----+---------+-------+-------+------------+
| 0    | 912  | 0    | 3679   | 54015 | 2149   | 0   | 157     | 0     | 0     | 0          |
+------+------+------+--------+-------+--------+-----+---------+-------+-------+------------+

# to quit shell, push Ctrl+D 
osquery> 

定时监控设置

  • 创建osquery配置文件
 [root@linuxprobe~]# vi /etc/osquery/osquery.conf
# create new
{
  "options": {
    // select the osquery config plugin (filesystem is default)
    "config_plugin": "filesystem",

    // select the osquery logging plugin (filesystem is default)
    "logger_plugin": "filesystem",

    // the PATH of log direcroty
    "logger_path": "/var/log/osquery",

    // PID file of the daemon
    "pidfile": "/var/osquery/osquery.pidfile",

    // the number of threads for concurrent query
    "worker_threads": "2",

    // enable schedule profiling
    // if adding a query "select * from osquery_schedule" in schedule section,
    // it's possible to record the performances
    "enable_monitor": "true"
  },

  "schedule": {
    // for example, get CPU Time per 300 seconds
    "cpu_time": {
      "query": "SELECT * FROM cpu_time;",
      "interval": 300
    },
    // for example, get settings of resolv.conf per an hour
    "dns_resolvers": {
      "query": "SELECT * FROM dns_resolvers;",
      "interval": 3600
    }
  },

   "packs": {
     // possible to include other configration files
     "hardware-monitoring": "/usr/share/osquery/packs/hardware-monitoring.conf"
   }
}
  • 启动osquery
[root@linuxprobe ~]# systemctl start osqueryd 
[root@linuxprobe ~]#  systemctl enable osqueryd 
Created symlink from /etc/systemd/system/multi-user.target.wants/osqueryd.service to /usr/lib/systemd/system/osqueryd.service.
  • 查看osquery日志
[root@linuxprobe osquery]# less /var/log/osquery/osqueryd.results.log
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
osquery 是 SQL 驱动的分析和监控操作系统的工具,是操作系统分析框架,支持 OS X 和 Linux 系统。osquery 能帮助监控和分析低水平的操作系统,提供更直观的性能监控。osquery 在操作系统中就像是一个高性能的关系数据库,允许你编写基于 SQL 的查询语句来洞察操作系统的数据。使用 osquery,SQL 表代表如下抽象概念:运行时的进程 加载内核模块开放网络连接 SQL 表通过一个简单的可扩展 API 实现,各种表已经存在并且还在不断增加。为了更好的理解 osquery,看看下面的 SQL 查询:-------------------------------------------------------- -- get the name, pid and attached port of all processes  -- which are listening on all interfaces -------------------------------------------------------- SELECT DISTINCT    process.name,    listening.port,    process.pid FROM processes AS process JOIN listening_ports AS listening ON process.pid = listening.pid WHERE listening.address = '0.0.0.0';-------------------------------------------------------- -- find every launchdaemon on an OS X host which  --   * launches an executable when the operating  --     system starts --   * keeps the executable running  -- return the name of the launchdaemon and the full  -- path (with arguments) of the executable to be ran. -------------------------------------------------------- SELECT    name,    program || program_arguments AS executable  FROM launchd  WHERE    (run_at_load = 'true' AND keep_alive = 'true')  AND    (program != '' OR program_arguments != '');这些查询可以:在特定条件下探索操作系统状态通过执行调度程序来监控操作系统的主机状态启动使用osquery api的自定义应用程序

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值