基于nagios的运营监控系统安装配置指南

1 目标

基于nagios及cacti搭建网络及系统监控系统,在系统出现故障时候,第一时间以邮件及手机短信方式通知管理员,及时排查并解决系统故障。

2 相关软件版本说明

操作系统:RedHat AS 4.0

Nagios: nagios 2.10

Nagios Plugins:nagios-plugins-1.4.11

Nagios Core Addons:

NRPE:2.11

NSCA:2.7.2

Apache HTTPD: 2.0.52

安装操作系统时候,建议采用完整的安装方式,需要安装httpd、gd-devel、libpng-devel、libjpeg-devel几个包。

如果需要监控mysql,对mysql用的也是Redhat AS缺省安装

3 nagios安装配置指南

3.1 Nagios系统的结构图

clip_image002[4]

3.2 安装Nagios

3.3 安装nagios的插件

3.3.1 建立需要的目录,并赋予权限

useradd nagios

mkdir /usr/local/nagios

mkdir /usr/local/nagios/libexec

chown -R nagios:nagios /usr/local/nagios

3.3.2 解压nagios的安装包:

tar xzvf nagios-2.10.tar.gz

3.3.3 编译安装nagios

cd nagios-2.10;

./configure –prefix=/usr/local/nagios –with-cgiurl=/nagios/cgi-bin \

–with-htmurl=/nagios –with-nagios-user=nagios –with-nagios-group=nagios;

make all;

make install;

make install-init;

make install-commandmode;

make install-config;

3.3.4 安装Nagios plugins

tar xzvf nagios-plugins-1.4.7.tar.gz

cd /nagios-plugins-1.4.7

./configure –prefix=/usr/local/nagios –with-cgiurl=nagios/cgi-bin \

–with-mysql=/usr –enable-ssl –enable-command-args

make;

make install;

注意:此处要对mysql进行监控,采用的mysql是安装时候AS自带的mysql,安装路径为/usr(包含lib/mysql)

Nagios的安装路径为/usr/local/nagios/libexec,安装成功后确认/usr/local/nagios/libexec下有相关的脚本(例如check_http),如果没有安装到此处,修改resource.cfg中的$USER1$

3.3.5 apache 配置

l 修改/etc/httpd/conf/httpd.conf,在文件末尾添加如下内容:

ScriptAlias /nagios/cgi-bin “/usr/local/nagios/sbin/”

<Directory “/usr/local/nagios/sbin/”>

Options ExecCGI

AllowOverride None

Order allow,deny

Allow from all

AuthName “Nagios Access”

AuthType Basic

AuthUserFile /usr/local/nagios/etc/htpasswd.users

Require valid-user

</Directory>

Alias /nagios “/usr/local/nagios/share/”

<Directory “/usr/local/nagios/share/”>

Options None

AllowOverride None

Order allow,deny

Allow from all

AuthName “Nagios Access”

AuthType Basic

AuthUserFile /usr/local/nagios/etc/htpasswd.users

Require valid-user

</Directory>

l 创建nagios管理员nagiosadmin的用户认证密码文件

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

注意:这里的用户既是apache的nagios管理界面的登录认证用户也和nagios监控中的权限有关联。

l 重启apache使apache的配置生效.

apachectl restart

3.3.6 Nagios配置

在/usr/local/nagios的etc目录下的配置文件有:

Config file Description

cgi.cfg CGI脚本的相关设定,如用户认证等

commands.cfg commands定义文件

localhost.cfg localhost本机的一个配置范例

nagios.cfg nagios的主配置文件

resource.cfg 监控使用到的脚本文件

根据具体使用情况,将配置文件的结构做以下规划,为了方便将来的维护和管理:

配置文件结构如下:

etc/ |– cgi.cfg

|– commands.cfg

|– nagios.cfg

|– resource.cfg

(以上为nagios系统主配置文件)

etc/servers |– contacts.cfg 管理人员和管理人员组的的默认初始化设定文件

|– hosts.cfg 服务器的默认初始化设定文件

|– services.cfg 监控服务的默认初始化设定文件

|– timeperiod.cfg 时间周期默认初始化设定文件

以上为监控服务相关的配置文件,都是由原localhost.cfg文件中拆分出来的,这样方面理解和管理。

l 建立servers目录

mkdir /usr/local/nagios/etc/servers

chown –R nagios.nagios /usr/local/nagios/etc/servers

chown –R 755 /usr/local/nagios/etc/servers

l 设置 cgi.cfg :

authorized_for_system_information=nagiosadmin

authorized_for_configuration_information=nagiosadmin

authorized_for_system_commands=nagiosadmin

authorized_for_all_services=nagiosadmin

authorized_for_all_hosts=nagiosadmin

authorized_for_all_service_commands=nagiosadmin

authorized_for_all_host_commands=nagiosadmin

以上设定nagiosadmin为nagios最高权限,有权查看所有hosts和services的状态.

l 设置nagios.cfg :

#cfg_file=/usr/local/nagios/etc/localhost.cfg

cfg_file=/usr/local/nagios/etc/servers/contacts.cfg

cfg_file=/usr/local/nagios/etc/servers/hosts.cfg

cfg_file=/usr/local/nagios/etc/servers/hostgroups.cfg

cfg_file=/usr/local/nagios/etc/servers/services.cfg

cfg_file=/usr/local/nagios/etc/servers/timeperiods.cfg

cfg_file=/usr/local/nagios/etc/commands.cfg

#cfg_dir=/usr/local/nagios/etc/servers

其他相关的参数参看nagios的手册。

需要特别指出的的地方是参数interval_length=60定义了nagios所有配置文件中与时间相关的参数所采用的缺省单位,缺省为60秒。例如interval_length=60,如果在hosts.cfg中定义notification_interval=1,则表示主机的提醒周期为1分钟。

l 设置resource.cfg

$USER1$=/usr/local/nagios/libexec

l /usr/local/nagios/etc/servers目录下各文件的内容简介(红色标注的是需要修改或要注意的地方):

timeperiod.cfg

###############################################################################

###############################################################################

#

# TIME PERIODS

#

###############################################################################

###############################################################################

# This defines a timeperiod where all times are valid for checks,

# notifications, etc. The classic “24×7″ support nightmare. :-)

define timeperiod{

timeperiod_name 24×7

alias 24 Hours A Day, 7 Days A Week

sunday 00:00-24:00

monday 00:00-24:00

tuesday 00:00-24:00

wednesday 00:00-24:00

thursday 00:00-24:00

friday 00:00-24:00

saturday 00:00-24:00

}

# ‘workhours’ timeperiod definition

define timeperiod{

timeperiod_name workhours

alias “Normal” Working Hours

monday 09:00-17:00

tuesday 09:00-17:00

wednesday 09:00-17:00

thursday 09:00-17:00

friday 09:00-17:00

}

# ‘nonworkhours’ timeperiod definition

define timeperiod{

timeperiod_name nonworkhours

alias Non-Work Hours

sunday 00:00-24:00

monday 00:00-09:00,17:00-24:00

tuesday 00:00-09:00,17:00-24:00

wednesday 00:00-09:00,17:00-24:00

thursday 09:00-17:00

friday 09:00-17:00

}

# ‘none’ timeperiod definition

define timeperiod{

timeperiod_name none

alias No Time Is A Good Time

}

定义各种监控的时间段,如24X7全天候的监控, none不工作时间以及workhours工作和nonworkhours非工作时间段等,在hosts和services的定义中可以引用.

contacts.cfg

###############################################################################

###############################################################################

#

# CONTACTS

#

###############################################################################

###############################################################################

# In this simple config file, a single contact will receive all alerts.

# This assumes that you have an account (or email alias) called

# “nagios-admin” on the local host.

define contact{

contact_name nagiosadmin

alias nagiosadmin

service_notification_period 24×7

host_notification_period 24×7

service_notification_options w,u,c,r

host_notification_options d,r

service_notification_commands notify-by-sms, notify-by-email

host_notification_commands notify-by-sms, host-notify-by-email

email liangchuan@mobile-soft.cn

pager 13910823366

}

define contact{

contact_name nagiosadmin2

alias nagiosadmin2

service_notification_period 24×7

host_notification_period 24×7

service_notification_options w,u,c,r

host_notification_options d,r

service_notification_commands notify-by-sms, notify-by-email

host_notification_commands notify-by-sms, host-notify-by-email

email jincheng.xiao@mobile-soft.cn

pager 13141202288

}

###############################################################################

###############################################################################

#

# CONTACT GROUPS

#

###############################################################################

###############################################################################

# We only have one contact in this simple configuration file, so there is

# no need to create more than one contact group.

define contactgroup{

contactgroup_name nagios

alias nagios

members nagiosadmin,nagiosadmin2

}

定义nagios的管理员成员(contact)和管理员组(contactgroup),以及管理员(contact)的联系方式mail或sms(pager传呼机标识手机号)。

hosts.cfg

###############################################################################

###############################################################################

#

# HOSTS

#

###############################################################################

###############################################################################

# Generic host definition template - This is NOT a real host, just a template!

define host{

name generic-host

notifications_enabled 1

event_handler_enabled 1

flap_detection_enabled 1

failure_prediction_enabled 1

process_perf_data 1

retain_status_information 1

retain_nonstatus_information 1

notification_period 24×7

register 0

}

define host {

use generic-host

host_name 192.168.1.5

address 192.168.1.5

check_command check-host-alive

max_check_attempts 1

notification_interval 1

notification_period 24×7

notification_options d,u,r

contact_groups nagios

}

generic-host定义默认的hosts公共属性。192.168.1.5定义需要监控的服务器信息。

hostgroups.cfg

###############################################################################

###############################################################################

#

# HOST GROUPS

#

###############################################################################

###############################################################################

# We only have one host in our simple config file, so there is no need to

# create more than one hostgroup.

define hostgroup{

hostgroup_name mobilesoft

alias mobilesoft

members 192.168.1.5

}

定义hosts所属的分组,方便监控时的观察.hostgroup_name定义分组名称,alias为别名,members定义成员名称,内容为每台hosts配置文件中定义的host_name内容.

services.cfg

###############################################################################

###############################################################################

#

# SERVICES

#

###############################################################################

###############################################################################

# Generic service definition template - This is NOT a real service, just a template!

define service{

name generic-service

active_checks_enabled 1

passive_checks_enabled 1

parallelize_check 1

obsess_over_service 1

check_freshness 0

notifications_enabled 1

event_handler_enabled 1

flap_detection_enabled 1

failure_prediction_enabled 1

process_perf_data 1

retain_status_information 1

retain_nonstatus_information 1

is_volatile 0

register 0

}

define service{

use generic-service

host_name 192.168.1.5

service_description mobilessoft esales platform

is_volatile 0

check_period 24×7

max_check_attempts 1

normal_check_interval 1

retry_check_interval 1

contact_groups nagios

notification_options w,u,c,r

notification_interval 1

notification_period 24×7

check_command check-mobilesoft!www.mobile-soft.cn

}

generic-service定义默认的services公共属性,在每个service定义中引用.

192.168.1.5定义对最终监控主机192.168.1.5的配置文件,包含每台被监控主机的定义和需要监控的服务.

l 修改/usr/local/nagios/etc/commands.cfg,增加对notify-by-sms及check-mobilesoft的定义

#notify-by-sms

define command {

command_name notify-by-sms

command_line $USER1$/notify_by_sms $HOSTADDRESS$ $CONTACTPAGER$

}

#check-mobilesoft

define command {

command_name check-mobilesoft

command_line $USER1$/check_mobilesoft $ARG1$

}

l 创建check_mobilesoft 的plugin脚本

在/usr/local/nagios/libexec下创建check_mobilesoft

touch check_mobilesoft

chown nagios.nagios check_mobilesoft

chmod 755 check_mobilesoft

其中check_mobilesoft的内容如下:

#!/bin/sh

#use the nagios check_http shell to check the monitored machine has some problem

PROGNAME=`basename $0`

PROGPATH=`echo $0 | sed -e ’s,[\\/][^\\/][^\\/]*$,,’`

. $PROGPATH/utils.sh

hostip=$1

result=`/usr/local/nagios/libexec/check_http -H ${hostip} –u /test –s “success” -w 0.0009 -c 0.0040 -t 10 |grep “200 OK”`

if [ -z “${result}” ] ; then

exit $STATE_CRITICAL

else

exit $STATE_OK

fi

注意此处调用了libexec/utils.sh,此脚本文件定义了诸如返回码等变量及一些工具。

l 创建notify_by_sms 的plugin脚本

在/usr/local/nagios/libexec下创建notify_by_sms

touch notif_by_sms

chown nagios.nagios notify_by_sms

chmod 755 notify_by_sms

其中notify_by_sms的内容如下:

#!/bin/sh

#use the nagios check_http shell to check the monitored machine has some problem

#if having problem ,then use the sms gateway to notify the admin

hostip=$1

phonenumber=$2

result=`/usr/local/nagios/libexec/check_http -H ${hostip} -w 0.0009 -c 0.0040 -t 10 |grep “200 OK”`

if [ -z “${result}” ] ; then

/usr/bin/wget “http://my-sms-ip:8800/Send%20Text%20Message.htm?PhoneNumber=${phonenumber}&Text=${hostip}%20machine%20Have%20Problem”

fi

l 检查配置文件正确性

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

执行该命令检查所有配置文件是否正确,如有问题,继续修改配置文件。

l 配置开机时候自动启动nagios及apache服务

chkconfig –add nagios

chkconfig –add httpd

或者直接修改/etc/rc.local,增加如下内容

/sbin/service nagios start

/usr/sbin/ apachectl start

l 启动nagios服务及apache 服务

service nagios restart

apachectl restart

l 登录nagios管理界面,监控服务器情况

访问nagios的服务器web界面http://ip/nagios,输入nagiosadmin 的用户名及密码,开始进行监控。

3.3.7 客户端监控代理NRPE的安装配置:

<TBC>

4 cacti安装配置指南

<TBC>

5 参考文档

http://nagios.sourceforge.net/docs/2_0/toc.html

http://gentoo-wiki.com/HOWTO_Install_Nagios

Technorati 标签: ,,,,

电子商务系统之网络管理

  对于以“软件作为服务”的互联网公司而言,系统的可靠性、可用性、性能、安全性是互联网公司的核心竞争力之一,很大程度决定了服务质量、客户满意度。为了提升客户的服务满意度,要建立一种“主动维护”的综合运维机制,对网络及系统进行定期检测和实时监控,在用户还没有感知的情况下,及时发现网络的故障隐患并将其排除,从而保障电子商务系统的长期安全稳定运行,为客户提供满意的SLA服务。可以说有效的网络管理已不仅局限于网络层,它还面对着业务管理的需求,甚至影响着商业运行的方方面面。

  但是随着互联网公司的网络规模不断地扩展、网络类型逐渐增多,网络管理系统的作用越来越重要、也越来越复杂,数据配置、告警、统计和检测手段的不足直接影响了运维效率,排除网络故障、软件系统故障更加困难、维护成本也急剧上升,单靠日常的手工方式进行维护已经不能满足业务发展要求。通过网管系统对系统进行“主动维护”可以保证网管系统能够7×24小时对全网进行监控维护 ,满足系统高可用性、高可靠性、高性能、高安全性、高扩展性要求,同时有效降低运营成本,及时发现并排查故障,有效提升服务质量。

 

1、电子商务系统对网络管理的要求:

第一、管理对象的接入类型及系统的管理功能是水平可扩展的,随着被管理网络类型的多样化,网管系统具备管理各种类型网络的能力,而且功能实现也能够逐渐扩展。

第二、系统在处理能力方面要具有垂直可扩性。随着网络规模的不断扩大,网管系统必须满足能够管理始终处于增长态的网络的要求

第三、系统必须能够通过权限的划分,保证不同层次、不同地域的用户拥有不同层次的功能。

第四、网管系统应当具有较好的软件架构,提供较好的插件式扩展机制,以方便定制开发。对于电子商务系统核心业务功能的监控应该作为核心业务需求进行设计和开发,在规范上应当遵循网管系统的管理接口,以方便系统的集中统一管理。

第五:满足提供标准化的接口,包括JMX、SNMP等。

网管系统的功能分类:

  • 配置管理
  • 性能管理
  • 失效管理
  • 计费管理
  • 安全管理

2、开源网络管理系统解决方案

2.1、开源的网络管理平台:

Hyperic :http://www.hyperic.com/

Zenoss:http://zenoss.com/

GroundWorks:http://www.groundworkopensource.com/

OpenQRM:http://openqrm.org/

Nagios:http://nagios.org/

OpenNMS:http://www.opennms.org/

Zabbix:  http://www.zabbix.org/

以上几个提供功能相对完整的综合解决方案,也即所谓的“企业级网管软件”,其他的参考10 Great Open Source Network Tools

最佳选择:Hyperic

Hyperic HQ功能

Hyperic HQ 可以监控和管理:

  • 操作系统: AIX, HP/UX, Linux, Solaris, Windows, Mac OSX, FreeBSD
  • Web服务器: Apache, Microsoft IIS, Sun ONE Web Server
  • 应用服务器: BEA WebLogic, IBM WebSphere, JBoss, Apache Geronimo, Macromedia ColdFusion, Macromedia JRun, Microsoft .NET Runtime, Novell Silverstream, Tomcat, Caucho Resin
  • 数据库: IBM DB2, Microsoft SQL Server, MySQL, Oracle, PostgreSQL, Sybase Adaptive Server
  • 消息中间件: ActiveMQ,Weblogic MQ
  • 微软的产品: MS Exchange,MS ActiveDirectory,.NET
  • 虚拟产品: VMWare, Citrix Metaframe
  • 应用平台: LAMP, LAM-J, J2EE, MX4J
  • 其他技术网络设备交换机,路由器等。
Hyperic HQ架构 

 

diagram-server-arch-small

diagram-agent-arch-small

2.2、开源备份管理软件

http://www.bacula.org/

http://www.amanda.org/

http://www.cleversafe.org/

最佳选择:bacula

 

3、电子商务系统建设网络管理功能思考

系统的可监控性、可维护性、易部署性是电子商务系统建设必须考虑的核心功能之一,必须提前未雨绸缪,而不是上线之后再补充和完善。

基本原则:必须实现系统的集中统一管理、数据统一备份管理。

基本思路:选定一个相对完整的管理平台,然后在此基础上进行二次开发。在系统需求分析时候就必须把对核心功能的网管监控需求、系统的数据归档及备份需求体现到核心业务需求中去,而不是作为可有可无的功能。在架构设计时候就必须对核心功能设计网管接口、对系统数据的备份归档进行统一设计考虑。这样后期运营维护时候,才能够及时发现系统故障,降低系统的风险点。所有系统的管理监控功能、数据备份应当遵循网管系统、备份系统的接口要求。

使用 vs. 开发:网管系统不应当只是停留在监控数据库、操作系统等使用层面,必须让网管系统帮助把核心业务系统的功能管理起来。核心系统的网管接口由程序员完成,但与网管系统的融合及二次开发可以考虑让系统人员来做,这样可以帮助系统人员提升其职业技能,也可以让程序员集中精力完成业务功能的实现。

怎样利用网管系统来简化软件上线部署统一的分发管理、部署管理?

 

4、参考资料

https://www.theforbingroup.com/files/TFG%20-%20Monitoring%20Whitepaper.pdf

http://www.itmanagement.com/features/10-open-source-network-tools-052407/

http://redmonk.com/cote/2007/01/16/open-platforms-in-systems-management/

http://www.openxtra.co.uk/blog/network-managements-new-wave/

 

Technorati 标签: , , , , ,