您的位置:首页 > 运维架构 > Linux

Linux 中initrd的作用(转载)

2013-03-02 18:32 274 查看
Nagios是一款功能强大的网络监视工具,它可以有效的监控windows、linux、unix主机状态以及路由器交换机的网络设置,打印机工作状态等,并将状态出现异常的服务及时以邮件、msn短信等形式第一时间通告管理员。由于它是一款遵循GPLv2的开源网络监控软件,以其出色的性能低廉的使用成本,深受广大用户的好评。

[align=left]nagios的主要监控功能有:[/align]
[align=left]1)监控网络服务(HTTP、POP3、SMTP、PING、MySQL等)[/align]
[align=left]2)监控主机资源(磁盘空间利用率、内存利用率、CPU负载等)[/align]
[align=left]3)简洁的插件设计接口,使得用户可以轻松开发所需的检测脚本(运维则可直接找到相关脚本并使用)[/align]
[align=left]4)并行服务模式[/align]
[align=left]5)轻松描述网络结构,并且能够区辨“宕机”和“主机不可达”[/align]
[align=left]6)通过邮件或用户自定义的方式将主机或服务的工作状态变化情况通知给管理员6)当服务或主机问题产生与解决时将告警发送给联系人(通过EMail、短信、用户定义方式) 可以通过飞信,等方式实现时,既可传递给管理员,可高效的保证服务器的维护[/align]
[align=left]7)自动日志滚动[/align]
[align=left]8)支持以冗余方式进行主机监控[/align]
[align=left]工作原理不在赘述,直接上图:[/align]
[align=left][/align]
[align=left]下文将包括这些内容:安装配置最新版nagios V3.3.1、添加定义被监控Windows主机和Linux主机、具体服务的监控、出现异常情况报警手段定义以及配置过程中笔者所遇到并解决的一些问题。[/align]
[align=left]废话不多说,直接开始配置内容[/align]
[align=left]1.到nagios官网下载到最新版的nagios-3.3.1.tar、nagios-plugins-1.4.15.tar、nrpe-2.12.tar以及windows的客户端nsclient_201.zip[/align]
[align=left][/align]
[align=left]2.安装nagios部署过程中需要依赖到得其他软件和库文件[/align]

[align=left]yum groupinstall -y 'Development Libraries' 'Development Tools" 'Legacy Software Development' 'X Software Development'[/align]
[align=left] [/align]

yum -y install httpd gcc glibc glibc-common *gd* php php-mysql mysql mysql-server mysql-devel openssl-devel

# 安装Nagios必须的基本组件的运行依赖于httpd、mysql、gd以及编译用到的gcc
[align=left]Nagios 监控端程序的安装及配置[/align]
[align=left]1.添加nagios用户和组[/align]

groupadd nagcmd

#添加与nagios运行相关服务的组

useradd -m nagios

#添加nagios用户

usermod -a -G nagcmd nagios

#将nagios用户追加附加组

usermod -a -G nagcmd apache

#将apache用户追加nagcmd组使之工作时具有足够的权限
[align=left]2.编译安装nagios 3.3.1[/align]
[align=left] [/align]

tar xvf nagios-3.3.1.tar.gz

cd nagios

# ./configure --with-command-group=nagcmd --enable-event-broker

#默认安装路径在/usr/local/nagios/

make all && make install && make install-init && make install-config && make install-commandmode && make install-webconf

#安装主程序、添加初始化程序、生成配置文件、生成web配置文件
[align=left]make install-webconf的作用:在/etc/httpd/conf.d/nagios.conf生成web相关配置文件,用于定义nagios使用的CGI选项,web的身份认证等[/align]

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

New password:

Re-type new password:

Adding password for user nagios

#为nagios的web页面创建账号密码,对访问进行身份认证

service httpd restart

chkconfig httpd on

#启动httpd,并设置开机启动
[align=left]PS:此处用户名尽量使用默认nagiosadmin,否则就需要修改cgi.cfg文件中所有关于认证选项的用户 [/align]
[align=left]3.编译安装nagios-plugins[/align]
[align=left]nagios的所有监控工作都是由nagios-plugins插件完成的,因此,在启动nagios之前还需要为其安装nagios-plugins。[/align]

tar xvf nagios-plugins-1.4.15.tar.gz

cd nagios-plugins-1.4.15

./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-mysql

#添加mysql依赖

make && make install

#编译并安装

Ps:作者在安装nagios-cn-3.2.3.tar过程中,在此处编译完成发现mysql关联库文件本跳过。经分析原因是由于在编译nagios时修改了nagios的默认安装路径(非/usr/local/nagios)。 解决办法:
[align=left] [/align]

cp /usr/lib/mysql/mysql_config /usr/lib/pkgconfig/

#将mysql的配置文件放在这个目录下使之能够在编译过程中读到相关配置选项

再进行编译安装nagios-plugins
[align=left]4.测试配置文件语法并尝试启动nagios[/align]

chkconfig --add nagios

chkconfig nagios on

#添加nagios到开机启动项

vim /etc/profile

PATH=$PATH:/usr/local/nagios/bin

#向profile加入这一行,指明nagios命令的path

. /etc/profile

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

#检查配置文件的语法

service nagios start

#如语法监测为报错则尝试开启服务
[align=left]注意:此时需要关闭SELINUX或针对nagios对SELIUNX进行配置[/align]

方法一、直接关闭selinux

getenforce

#查看selinux的运行状态

setenforce 0

#如果是enforce(开启)状态,则关闭

Ps:如果您想在今后的使用中完全关闭selinux,可以通过编辑/etc/sysconfig/selinux文件,将其中的selinux后面的值“force”修改为“disable”即可。

方法二、修改相关文件的type

chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin

chcon -R -t httpd_sys_content_t /usr/local/nagios/share

#进行这些操作就可以在selinux开启的状态下正常访问nagios
[align=left]5.打开浏览器检测nagios的工作情况[/align]
[align=left]http://serverIP/nagios[/align]
[align=left][/align]
[align=left]注意:如果htpasswd生成的密码没有使用的默认的nagiosadmin则会导致无法正常显示监控信息,将cgi.cfg中use_authentication=1改成0虽能显示主机信息但在手动刷新服务状态时报错[/align]
[align=left][/align]
[align=left]解决方法:将cgi.cfg中认证用户改成htpasswd生成的用户;或按照cgi.cfg认证功能用户从新生成htpasswd。[/align]
[align=left]配置监控Windows主机[/align]
[align=left]1.修改nagios主配置文件[/align]

vim /usr/local/nagios/etc/nagios.cfg

cfg_file=/usr/local/nagios/etc/objects/windows.cfg

#将这一行注释去掉
[align=left]2.修改用来定义windows的配置文件[/align]

vim /usr/local/nagios/etc/objects/windows.cfg

define host{

use windows-server ; Inherit default values from a template

host_name winserver ; The name we're giving to this host

alias My Windows Server ; A longer name associated with the host

address 192.168.0.72 ; windowsIP

}

#修改IP,此ip为windows主机IP
[align=left]配置监控Linux主机[/align]
[align=left]1.编译安装nrpe[/align]

tar xvf nrpe-2.12.tar

cd nrpe-2.12

./configure --enable-ssl --with-ssl-lib=/lib/

make all && make install-plugin
[align=left]2.在nagios中定义nrpe[/align]

vi /usr/local/nagios/etc/objects/commands.cfg

#check nrpe

define command{

command_name check_nrpe

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

}

#在末行添加这些内容
[align=left]3.创建定义linux的配置文件[/align]

vim /usr/local/nagios/etc/objects/mylinux.cfg

define host{

use linux-server

host_name mylinux

alias mylinux

address 192.168.1.2#客户端IP即被监控的IP

}

define service{

use generic-service

host_name mylinux

service_description check-load

check_command check_nrpe!check_load

}

define service{

use generic-service

host_name mylinux

service_description check-users

check_command check_nrpe!check_users

}

define service{

use generic-service

host_name mylinux

service_description otal_procs

check_command check_nrpe!check_total_procs

}

chown -R nagios:nagios mylinux.cfg
[align=left]#修改配置文件的属主属组[/align]
[align=left]4.修改配置文件[/align]

vim /usr/local/nagios/etc/nagios.cfg

cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg

#在主配置文件指明linux主机的配置文件路径
[align=left]Windows 监控端配置[/align]
[align=left]安装NSClient,进入安装目录修改配置文件NSC.ini,将[module]下所有库文件的注释删去。运行nsclient。[/align]
[align=left]Linux 监控端配置[/align]
[align=left]1.添加nagios用户[/align]

[align=left]useradd nagios[/align]
[align=left]2.编译安装nagios-plugin[/align]

tar zxf nagios-plugins-1.4.15.tar.gz

cd nagios-plugins-1.4.15

./configure --with-nagios-user=nagios --with-nagios-group=nagios

make && make install
[align=left]3.编译安装nrpe [/align]

yum install openssl-devel

#先安装openssl解决依赖

tar -zxvf nrpe-2.12.tar.gz

cd nrpe-2.12.tar.gz

./configure --enable-ssl --with-ssl-lib=/usr/lib/

make all && make install-plugin && make install-daemon && make install-daemon-config

#编译安装
[align=left]4.配置并启用nrpe [/align]

vim /usr/local/nagios/etc/nrpe.cfg

allowed_hosts=192.168.1.1

#监控端的IP

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d

#开启进程
[align=left]监控端重启nagios服务 [/align]

[align=left]service nagiso restart[/align]
[align=left]浏览器刷新页面,即出现windows和linux被监控主机 [/align]
[align=left][/align]
[align=left]监控服务的添加[/align]
[align=left]下面就添加被监控主机mysql服务为例进行说明[/align]
[align=left]1.被监控机(192.168.1.2)安装mysql并创建监控用户[/align]

yum install mysql mysql-server

#简单起见yum安装mysql

service mysqld start

#启动mysql

mysqladmin -uroot -p password '123456'

#给root用户创建mysql密码

mysql -uroot -p

#进入mysql

mysql> create database nagios;

#创建数据库

mysql> grant select on nagios.* to nagios@'%' identified by 'redhat';

#给nagios用户赋予查询权限

mysql> flush privileges;

#刷新特权表
[align=left]2.监控机(192.168.1.1)修改相关配置文件 [/align]

vim /usr/local/nagios/etc/objects/command.cfg

#check mysql

define command{

command_name check_mysql

command_line $USER1$/check_mysql -H 192.168.1.2 -u nagios -d nagios -p redhat

}

#在命令配置文件中添加这些字段
[align=left] [/align]

vim /usr/local/nagios/etc/objects/mylinux.cfg

define service{

use generic-service

host_name mylinux

service_description check_mysql

check_command check_mysql

}

#在linux主机配置文件中定义服务
[align=left]重启服务[/align]

[align=left]service nagios restart[/align]
[align=left]刷新浏览器页面[/align]
[align=left][/align]
[align=left]异常报警[/align]
[align=left]这里选用飞信作为异常报警手段,异常事件出发直接以短信形式通知运维人员[/align]
[align=left]1.飞信的安装[/align]

unzip fetion.zip

cd ../fetion

mv fetion /usr/bin/

#将飞信脚本放在/usr/lib

chmod +x /usr/bin/fetion

#添加执行权限

mv ./* /usr/lib

#将剩余所有库文件移动到/usr/lib
[align=left]Ps:飞信程序已上传至本文附件中[/align]
[align=left]2.修改nagios相关配置文件[/align]

vim /usr/local/nagios/etc/templates.cfg

define contact{

name generic-contact

service_notification_period 24x7

host_notification_period 24x7

service_notification_options w,u,c,r,f,s

host_notification_options d,u,r,f,s

service_notification_commands notify-service-by-fetion

host_notification_commands notify-host-by-fetion

register 0

}

#修改成上面字段

vim /usr/local/nagios/etc/commands.cfg

commands.cfg

define command{

command_name notify-service-by-fetion

command_line /usr/bin/fetion --mobile 您的手机号 --pwd 您的飞信密码 --to 您的手机号 --msg-tpye=0 --msg-utf8 $HOSTNAME

}

#添加这些字段
[align=left]重启服务使配置文件生效[/align]
[align=center] [/align]
[align=left]9)可以通过web方式直观的查看当前网络状态、通知和问题历史、日志文件等等,此组件为可选[/align]
[align=left]Nagios相关的配置文件:[/align]
[align=left]nagios.cfg为其主配置文件其中可以定义nagios的一些基本工作状态可监控机的配置文件; [/align]
[align=left]command.cfg其为nagios的监控命令配置文件,在其中可定义nagios在监控过程中针对某项服务所使用到得命令; [/align]
[align=left]contact.cfg其为nagios报警途径配置文件,它用来定义一旦监控到某台主机状态异常或某服务状态为离线通知运维人员的方法; [/align]
[align=left]timeperiods.cfg用于定义nagios向运维人员发送报警的周期时间频率等; resource.cfg用于定义nagios监控服务所使用到脚本所在路径; [/align]
[align=left]templates.cfg中定义的是nagios监控各项主机或服务属性状态所需的模板。[/align]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: