OpenBSD中的网络管理

这些天我花了一些时间研究了一下OpenBSD中的系统/网络监控软件,走了不少弯路,在这里跟与诸位分享一些心得体会。

一开始,我直奔主题,花了不少精力尝试了大量网管软件,考察的对象包括:Munin、Monit、collectd、nagios/icinga和symon。

Munin

Munin is programmed in Perl, which can be installed on most operating systems. In addition, it needs some perl modules, which you can fetch from CPAN.

Munin的框架基于perl,这意味着执行效率低,所以一开始我就不怎么看好它,特别是体验了官方的demo之后,我就对munin失望了,因为有不少rrd图片出现断断续续的现象,如下图所示:

图片

当初我就是因为这个原因而放弃cacti的。

Monit

Monit is a free open source utility for managing and monitoring, processes, programs, files, directories and filesystems on a UNIX system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations.

Monit的目的很明确,就是要监控Unix系统中的进程、程序、文件等信息,发现问题后执行相应指令进行修复。

再者,Monit的设计理念吸引了我:

Monit is designed as an autonomous system and does not depend on plugins nor any special libraries to run. Instead it works right out of the box and can utilize existing infrastructure already on your system. For instance, Monit will easily integrate with init and can use existing runlevel rc-scripts to manage services. There are also flexibility for those special cases when you need a certain setup for a service.

Monit compiles and run on most flavors of UNIX. It is a small program and weights in at just over 500kB. There is support for compiling with glibc replacements such as uClibc if you need it to be even smaller.

它没有流行的插件概念,全部通过一个的主程序搞定,这似乎跟unix的哲学背道而驰,不过对于监控软件而言,Monit的设计理念才是正确的,因为插件越多,依赖性就越强,效率和兼容性就无法得到保障,collectd就是一个例子,collectd有些插件可以在linux下很好的运行,却无法在OpenBSD中,而且在google上找不到答案。
所以说,对于单机而言,Monit是一个很好的监控软件。另外,Monit还有一个主控程序:M/Monit

M/Monit expand upon Monit's capabilities to provide monitoring and management of all Monit enabled hosts from one easy to use web-interface.

通过M/Monit,可以将多个Monit enabled host进行统一管理,唯一可惜的是M/Monit需要银子。

collectd

collectd遵循了Unix的设计哲学,每个程序只做好一件事。所以它最骄傲的地方就是拥有高达90个插件,然而成也萧何,败也萧何,并不是所有的插件都能很好的兼容OpenBSD,还有一点比较烦人,collectd尚无一个成熟的前端可用。实际上collectd的系统资源占用低,提供10s扫描粒度小,是一个非常有竞争力的for OpenBSD系统管理软件,可惜了。

nagios/icinga

icinga fork自nagios,虽然在OpenBSD有port,但是我一直无法正常的安装,所以这里只考虑nagios,nagios号称是*nix界的监控软件事实的标准,的确,nagios发展多年,代码成熟,应用范围极广,是一款理想的监控软件,然而,我只是想找一个可以查看本机系统资源的网管软件而已,不需要这么大的块头。

symon

symon is a lightweight system monitor that measures cpu, load, filesys-
tem, interface, disk, memory, pf, pf queues, mbuf, proc and sensor sta-
tistics every 5 seconds. This information is then spooled to symux(8) for
further processing.

symon has been designed to inflict minimal performance and security
impact on the system it monitors. symux(8) has performance impact pro-
portional to the amount of streams it needs to manage. Ideally symux
should live on a different system and collect data from several symon
instances in a LAN.

玩到这,我开始茫然了,每一个都有自己的优劣势,没有一个是完美的,到底应该选哪一个呢?我陷入沉思…等等,真的需要那么完美吗,或者说,我对网管系统的功能需求明确吗?于是我开始反思:我到底需要什么功能需求,这些功能可以解决什么样的问题?很幸运的,在网上看到Unix system monitoring,此文提到系统管理需要考虑的几个方面:

  • 硬件层

    CPU、内存和硬盘利用率、设备温度,风扇电压和转速

  • 网络层

    网络流量:监控网卡的网络流量;

    netflow:用于监控每个IP地址的流量;

  • 系统层

    指的是在系统中所运行的服务,我的OpenBSD运行的服务包括:

    1. apache/nginx
    2. unbound
    3. OpenNTPd

我整理了一下,需要回答几个问题:
1. 需要监控什么信息

需要监控CPU、内存、硬盘容量、网络流量、netflow

  1. 是否需要查看历史记录

需要,而且需要用rrd图形来显示历史记录

  1. 是否一定要安装在OpenBSD中

不一定,实际上,商业的防火墙不会内嵌网管软件,一般都提供snmp agent和sflow/netflow,由统一网管进行管理。

  • 是否拥有活跃的开发团队和社区

是的,这个很重要,一个软件假如缺乏活跃的开发团队和社区,那其后期的维护成本将很高。

综合考虑了以上几个因素,我决定使用Monit+SNMP这两个组合。

  • Monit监控CPU、内存、硬盘容量,一些基础数据可以直接在OpenBSD中进行查看;
  • OpenBSD/snmpd提供网络流量、pf等数据,并集中到zenoss进行统一网管;
  • OpenBSD/pflog提供netflow,使用intermapper flow进行分析处理。

UPDATE
关于网管软件,我的思路一直在变,前段时间迷上了graphite,于是果断抛弃了zenoss和zabbix这种大而全的软件模式,现在更佳倾向于collectd+graphite这样的组合。实际上,服务器的各种性能参数可以通过各种各样的daemon收集,然后输出给graphite进行绘图,graph everything是网管系统的终极目标。