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

Centos 下面安装nagios安装和配置笔记

2012-01-04 16:37 736 查看
很好的blog:http://blog.csdn.net/cnbird2008/article/details/3680085
http://nagios-cn.sourceforge.net/
http://sourceforge.net/project/platformdownload.php?group_id=204892

CentOS 5.2安装nagios实现短信告警笔记

http://linux.chinaunix.net/bbs/viewthread.php?tid=1051835

Nagios飞信linux系统免费短信报警配置

http://bbs.chinaunix.net/viewthread.php?tid=1326927

Nagios是一款用于系统和网络监控的应用程序。它可以在你设定的条件下对主机和服务进行监控,在状态变差和变好的时候给出告警信息。

Nagios最初被设计为在Linux 系统之上运行,然而它同样可以在类Unix的系统之上运行。

Nagios更进一步的特征包括:

监控网络服务(SMTP、POP3、HTTP、NNTP、PING等);
监控主机资源(处理器负荷、磁盘利用率等);
简单地插件设计使得用户可以方便地扩展自己服务的检测方法;
并行服务检查机制;
具备定义网络分层结构的能力,用"parent"主机定义来表达网络主机间的关系,这种关系可被用来发现和明晰主机宕机或不可达状态;
当服务或主机问题产生与解决时将告警发送给联系人(通过EMail、短信、用户定义方式);
具备定义事件句柄功能,它可以在主机或服务的事件发生时获取更多问题定位;
自动的日志回滚;
可以支持并实现对主机的冗余监控;
可选的WEB界面用于查看当前的网络状态、通知和故障历史、日志文件等;

一.安装
1.准备软件包
yum install httpd

yum install gcc

yum install glibc glibc-common

yum install gd gd-devel
yum install mysql mysql-server mysql-devel
yum install gnutls

2.建立用户
切换到root用户
/usr/sbin/useradd nagios
passwd nagios
创建一个用户组名为nagcmd 用于从Web接口执行外部命令。将nagios用户和apache用户都加到这个组中。
/usr/sbin/groupadd nagcmd

/usr/sbin/usermod -G nagcmd nagios

/usr/sbin/usermod -G nagcmd apache
3.下载Nagios和插件程序包
下载Nagios和Nagios插件的软件包(访问http://www.nagios.org/download/ 站点以获得最新版本),在写本文档时,最新的Nagios的软件版本是3.0rc1,Nagios插件的版本是1.4.11。

我们自己下载最新的
wget http://nchc.dl.sourceforge.net/sourceforge/nagios/nagios-3.0.6.tar.gz
wget http://jaist.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz
4.安装nagios
tar xzf nagios-3.0.6.tar.gz

cd nagios-3.0.6.tar.gz

运行Nagios配置脚本并使用先前开设的用户及用户组:
./configure --with-command-group=nagcmd
编译Nagios程序包源码
make all
安装二进制运行程序、初始化脚本、配置文件样本并设置运行目录权限
make install

make install-init

make install-config

make install-commandmode
现在还不能启动Nagios-还有一些要做的...
5.客户化配置
样例配置文件 默认安装在这个目录下/usr/local/nagios/etc ,这些样例文件可以配置Nagios使之正常运行,只需要做一个简单的修改...

用你擅长的编辑器软件来编辑这个/usr/local/nagios/etc/objects/contacts.cfg 配置文件,更改email地址nagiosadmin 的联系人定义信息中的EMail信息为你的EMail信息以接收报警内容。

vi /usr/local/nagios/etc/objects/contacts.cfg6.配置web接口

安装Nagios的WEB配置文件到Apache的conf.d目录下

make install-webconf创建一个nagiosadmin 的用户用于Nagios的WEB接口登录。记下你所设置的登录口令,一会儿你会用到它。

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin重启Apache服务以使设置生效。

service httpd restart7)编译并安装Nagios插件

展开Nagios插件的源程序包

./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-mysql=/usr --enable-perl-modules --with-gnutls=路径 --enable-perl-modules --enable-extra-opts如果不能开启mysql的话看这里http://www.shinguz.ch/MySQL/mysql_monitoring.html

make

make install

门户网站运维Nagios监控文章推荐强烈推荐

http://bbs.chinaunix.net/thread-1356538-1-1.html

http://nagios.sourceforge.net/docs/3_0/monitoring-linux.html



http://nagios.sourceforge.net/docs/3_0/quickstart-fedora.html



http://library.nagios.com/library/products/nagioscore/manuals/



Introduction

This guide is intended to provide you with simple instructions on how to install Nagios from source (code) on Fedora and have it monitoring your local machine inside of 20 minutes. No advanced installation options are discussed here - just the basics that
will work for 95% of users who want to get started.

These instructions were written based on a standard Fedora Core 6 Linux distribution.

What You'll End Up With

If you follow these instructions, here's what you'll end up with:

Nagios and the plugins will be installed underneath /usr/local/nagios
Nagios will be configured to monitor a few aspects of your local system (CPU load, disk usage, etc.)
The Nagios web interface will be accessible at http://localhost/nagios/
Prerequisites

During portions of the installation you'll need to have root access to your machine.

Make sure you've installed the following packages on your Fedora installation before continuing.

Apache
PHP
GCC compiler
GD development libraries

You can use yum to install these packages by running the following commands (as root):

yum install httpd php

yum install gcc glibc glibc-common

yum install gd gd-devel

1) Create Account Information

Become the root user.

su -l

Create a new nagios user account and give it a password.

/usr/sbin/useradd -m nagios

passwd nagios

Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.

/usr/sbin/groupadd nagcmd

/usr/sbin/usermod -a -G nagcmd nagios

/usr/sbin/usermod -a -G nagcmd apache

2) Download Nagios and the Plugins

Create a directory for storing the downloads.

mkdir ~/downloads

cd ~/downloads

Download the source code tarballs of both Nagios and the Nagios plugins (visit http://www.nagios.org/download/ for links to the latest versions). These directions were tested with Nagios 3.1.1 and Nagios Plugins
1.4.11.

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz 
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz

3) Compile and Install Nagios

Extract the Nagios source code tarball.

cd ~/downloads

tar xzf nagios-3.2.3.tar.gz

cd nagios-3.2.3

Run the Nagios configure script, passing the name of the group you created earlier like so:

./configure --with-command-group=nagcmd

Compile the Nagios source code.

make all

Install binaries, init script, sample config files and set permissions on the external command directory.

make install

make install-init

make install-config

make install-commandmode

Don't start Nagios yet - there's still more that needs to be done...

4) Customize Configuration

Sample configuration files have now been installed in the /usr/local/nagios/etc directory. These sample files should work fine for getting started with Nagios. You'll need to make
just one change before you proceed...

Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you'd like to use for receiving alerts.

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

5) Configure the Web Interface

Install the Nagios web config file in the Apache conf.d directory.

make install-webconf

Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account - you'll need it later.

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

Restart Apache to make the new settings take effect.

service httpd restart



Note: Consider implementing the ehanced CGI security measures described here to
ensure that your web authentication credentials are not compromised.

6) Compile and Install the Nagios Plugins

Extract the Nagios plugins source code tarball.

cd ~/downloads

tar xzf nagios-plugins-1.4.11.tar.gz

cd nagios-plugins-1.4.11

Compile and install the plugins.

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

make

make install

7) Start Nagios

Add Nagios to the list of system services and have it automatically start when the system boots.

chkconfig --add nagios

chkconfig nagios on

Verify the sample Nagios configuration files.

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

If there are no errors, start Nagios.

service nagios start

8) Modify SELinux Settings

Fedora ships with SELinux (Security Enhanced Linux) installed and in Enforcing mode by default. This can result in "Internal Server Error" messages when you attempt to access the Nagios CGIs.

See if SELinux is in Enforcing mode.

getenforce

Put SELinux into Permissive mode.

setenforce 0

To make this change permanent, you'll have to modify the settings in /etc/selinux/config and reboot.

Instead of disabling SELinux or setting it to permissive mode, you can use the following command to run the CGIs under SELinux enforcing/targeted mode:

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

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

For information on running the Nagios CGIs under Enforcing mode with a targeted policy, visit the Nagios Support Portal or Nagios Community Wiki.

9) Login to the Web Interface

You should now be able to access the Nagios web interface at the URL below. You'll be prompted for the username (nagiosadmin) and password you specified earlier.

http://localhost/nagios/

Click on the "Service Detail" navbar link to see details of what's being monitored on your local machine. It will take a few minutes for Nagios to check all the services associated with your machine, as the checks are spread out over time.

10) Other Modifications

Make sure your machine's firewall rules are configured to allow access to the web server if you want to access the Nagios interface remotely.

Configuring email notifications is out of the scope of this documentation. While Nagios is currently configured to send you email notifications, your system may not yet have a mail program properly installed or configured. Refer to your system documentation,
search the web, or look to the Nagios Support Portal or Nagios Community Wiki for specific instructions on configuring your system to send email
messages to external addresses. More information on notifications can be foundhere.

11) You're Done

Congratulations! You sucessfully installed Nagios. Your journey into monitoring is just beginning. You'll no doubt want to monitor more than just your local machine, so check out the following docs...

Nagios是一款用于系统和网络监控的应用程序。它可以在你设定的条件下对主机和服务进行监控,在状态变差和变好的时候给出告警信息。

Nagios最初被设计为在Linux 系统之上运行,然而它同样可以在类Unix的系统之上运行。

Nagios更进一步的特征包括:

监控网络服务(SMTP、POP3、HTTP、NNTP、PING等);
监控主机资源(处理器负荷、磁盘利用率等);
简单地插件设计使得用户可以方便地扩展自己服务的检测方法;
并行服务检查机制;
具备定义网络分层结构的能力,用"parent"主机定义来表达网络主机间的关系,这种关系可被用来发现和明晰主机宕机或不可达状态;
当服务或主机问题产生与解决时将告警发送给联系人(通过EMail、短信、用户定义方式);
具备定义事件句柄功能,它可以在主机或服务的事件发生时获取更多问题定位;
自动的日志回滚;
可以支持并实现对主机的冗余监控;
可选的WEB界面用于查看当前的网络状态、通知和故障历史、日志文件等;

一.安装
1.准备软件包
yum install httpd

yum install gcc

yum install glibc glibc-common

yum install gd gd-devel
yum install mysql mysql-server mysql-devel
yum install gnutls

2.建立用户
切换到root用户
/usr/sbin/useradd nagios
passwd nagios
创建一个用户组名为nagcmd 用于从Web接口执行外部命令。将nagios用户和apache用户都加到这个组中。
/usr/sbin/groupadd nagcmd

/usr/sbin/usermod -G nagcmd nagios

/usr/sbin/usermod -G nagcmd apache
3.下载Nagios和插件程序包
下载Nagios和Nagios插件的软件包(访问http://www.nagios.org/download/ 站点以获得最新版本),在写本文档时,最新的Nagios的软件版本是3.0rc1,Nagios插件的版本是1.4.11。

我们自己下载最新的
wget http://nchc.dl.sourceforge.net/sourceforge/nagios/nagios-3.0.6.tar.gz
wget http://jaist.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz
4.安装nagios
tar xzf nagios-3.0.6.tar.gz

cd nagios-3.0.6.tar.gz

运行Nagios配置脚本并使用先前开设的用户及用户组:
./configure --with-command-group=nagcmd
编译Nagios程序包源码
make all
安装二进制运行程序、初始化脚本、配置文件样本并设置运行目录权限
make install

make install-init

make install-config

make install-commandmode
现在还不能启动Nagios-还有一些要做的...
5.客户化配置
样例配置文件 默认安装在这个目录下/usr/local/nagios/etc ,这些样例文件可以配置Nagios使之正常运行,只需要做一个简单的修改...

用你擅长的编辑器软件来编辑这个/usr/local/nagios/etc/objects/contacts.cfg 配置文件,更改email地址nagiosadmin 的联系人定义信息中的EMail信息为你的EMail信息以接收报警内容。

vi /usr/local/nagios/etc/objects/contacts.cfg6.配置web接口

安装Nagios的WEB配置文件到Apache的conf.d目录下

make install-webconf创建一个nagiosadmin 的用户用于Nagios的WEB接口登录。记下你所设置的登录口令,一会儿你会用到它。

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin重启Apache服务以使设置生效。

service httpd restart7)编译并安装Nagios插件

展开Nagios插件的源程序包

tar xzf nagios-plugins-1.4.11.tar.gz

cd nagios-plugins-1.4.11


Compile and install the plugins.

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

make

make install

7) Start Nagios

Add Nagios to the list of system services and have it automatically start when the system boots.

chkconfig --add nagios

chkconfig nagios on

Verify the sample Nagios configuration files.

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

If there are no errors, start Nagios.

service nagios start

8) Modify SELinux Settings

Fedora ships with SELinux (Security Enhanced Linux) installed and in Enforcing mode by default. This can result in "Internal Server Error" messages when you attempt to access the Nagios CGIs.

See if SELinux is in Enforcing mode.

getenforce

Put SELinux into Permissive mode.

setenforce 0

To make this change permanent, you'll have to modify the settings in /etc/selinux/config and reboot.

Instead of disabling SELinux or setting it to permissive mode, you can use the following command to run the CGIs under SELinux enforcing/targeted mode:

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

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

For information on running the Nagios CGIs under Enforcing mode with a targeted policy, visit the Nagios Support Portal or Nagios Community Wiki.

9) Login to the Web Interface

You should now be able to access the Nagios web interface at the URL below. You'll be prompted for the username (nagiosadmin) and password you specified earlier.

http://localhost/nagios/

8)配置和启动nagios

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
#如果提示“Whoops! Error: Could not read object configuration data! ”,这是因为没有启动nagios后台进程,执行以下命令

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

9)Nagios Web上进行操作时提示 "Error: Could not stat() command file '.../rw/nagios.cmd'!

当在Nagios Web页面上对某个服务执行"Re-schedule the next check of this service", 提示如下错误:

Error: Could not stat() command file '/usr/local/nagios/var/rw/nagios.cmd'!

The external command file may be missing, Nagios may not be running, and/or Nagios may not be checking external commands.

意思是apache的运行用户要有对文件写的权限. 权限应该设置在目录/usr/local/nagios/var/rw/上,因为每次文件的内容被处理后文件就会被删掉. 处理方法如下:

#ls -ld /usr/local/nagios/var/rw

drwxrwxr-x 2 nagios nagcmd 4096 Apr 2 10:18 /usr/local/nagios/var/rw

# chmod -R 777 /usr/local/nagios/var/rw (权限为775都不行)

#service nagios restart

如果还不行, 就apache用户登陆, 确认是否可进入该目录, 并测试是否可以在该目录写文件.

如果执行"su - apache"时出现"This account is currently not available"提示, 解决办法:

#cat /etc/passwd | grep apache

apache:x:48:48:Apache:/var/www:/sbin/nologin

发现它的shell是"/sbin/nologin",改成"/bin/bash"即可

#vipw /etc/passwd
http://hi.baidu.com/edeed/blog/item/014a7bec41468ac42f2e219f.html
nagios.cmd的权限处理方法

报错处理:

1、Could not open command file '/usr/local/nagios/var/rw/nagios.cmd' for update!

The permissions on the external command file and/or directory may be incorrect. Read the FAQs on how to setup proper permissions.

An error occurred while attempting to commit your command for processing.

2、Error: Could not stat() command file '/usr/local/nagios/var/rw/nagios.cmd'!

设置过nagios.cmd的权限,发现仍然不要

最终解决方法:

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

将nagios_group=nagios改成

nagios_group=nagcmd

为了验证错误,我又将nagios_group=nagcmd改成nagios_group=nagios,发现又可以了,真是一个奇怪的问题啊

email nagios@localhost ;

改为自己所要的邮箱
http://nagios-cn.sourceforge.net/ http://nagios.sourceforge.net/docs/3_0/quickstart-fedora.html
http://sourceforge.net/project/platformdownload.php?group_id=204892

CentOS 5.2安装nagios实现短信告警笔记

http://linux.chinaunix.net/bbs/viewthread.php?tid=1051835

Nagios飞信linux系统免费短信报警配置

http://bbs.chinaunix.net/viewthread.php?tid=1326927

门户网站运维Nagios监控文章推荐强烈推荐

http://bbs.chinaunix.net/thread-1356538-1-1.html

参考URL:http://blog.csdn.net/cnbird2008/article/details/3680085
http://kerry.blog.51cto.com/172631/107831
nagios安装配置pnp4nagios-0.6.6

原创作品,允许转载,转载时请务必以超链接形式标明文章
原始出处 、作者信息和本声明。否则将追究法律责任。/article/4226981.html

nagios 安装完了,只有数字输出监控内容是不是不炫丽呢?是不是想像CACTI 一样出炫丽的图呢?那你可以选择PNP,他可以满足你的需求,只要你的脚本符合perfdata规则,那么rrdtool就可以出数据,PNP就可以用图给你画出来。

1.下载安装 pnp4nagios-0.6.6.tar.gz

nagios $> wget http://cdnetworks-kr-1.dl.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.6.tar.gz

nagios $> apt-get install rrdtool librrds-perl
nagios $> tar zxvf  pnp4nagios-0.6.6.tar.gz
nagios $> cd pnp4nagios-0.6.6
nagios $> ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd
nagios $> make all
nagios $> make install
nagios $> make install-webconf
nagios $> make install-config
nagios $> make install-init

2.创建配置文件

nagios $> cd /usr/local/pnp4nagios/etc
nagios $> mv misccommands.cfg-sample  misccommands.cfg
nagios $> mv nagios.cfg-sample  nagios.cfg
nagios $> mv npcd.cfg-sample npcd.cfg
nagios $> mv process_perfdata.cfg-sample  process_perfdata.cfg
nagios $> mv rra.cfg-sample rra.cfg

nagios $>  cd pages
nagios $> mv web_traffic.cfg-sample web_traffic.cfg

nagios $> cd ../check_commands
nagios $> mv check_all_local_disks.cfg-sample  check_all_local_disks.cfg
nagios $> mv check_nrpe.cfg-sample  check_nrpe.cfg
nagios $> mv check_nwstat.cfg-sample  check_nwstat.cfg

3. 重启服务

nagios $> /etc/init.d/npcd restart

4.修改 nagios 的配置文件.打开performance_data

nagios $> cd /usr/local/nagios/etc
nagios $> vim nagios.cfg
#打开注视项:
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata

5.修改 commands.cfg

nagios $> cd /usr/local/nagios/etc/objects
nagios $> vim commands.cfg
##添加
# 'process-host-perfdata' command definition
define command{
command_name    process-host-perfdata
command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl
}
# 'process-service-perfdata' command definition
define command{
command_name    process-service-perfdata
command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl
}

6. 添加小太阳模版,镶嵌在nagios页面上。

nagios $> vim templates.cfg
## 在最后添加
define host {
name       host-pnp
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_
register   0
}
define service {
name       srv-pnp
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register   0
}

7,修改 hosts.cfg 和 色services.cfg

nagios $> cd /usr/local/nagios/etc/eric.com
#修改hosts.cfg
nagios $> vim hosts.cfg
define host{
use                     linux-server,host-pnp
host_name         eric.com
alias                     eric.com
address                 192.168.6.101
}

# 修改 services.cfg
define service{
use                                     local-service,srv-pnp
host_name                       eric.com
service_description        PING
check_command            check_ping!100.0,20%!500.0,60%
}

8.重启 nagios 服务

nagios $> /etc/init.d/nagios restart

效果图:





本文出自 “linuxer” 博客,请务必保留此出处/article/4226981.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: