Nagios 安裝配置
Nagios 介紹
Nagios 是一款Linux 上成熟的監視系統運行狀態和網絡信息的開源軟件,可以對對主機或服務進行檢測的自動化工具;Nagios 能監控所指定的本地或遠程主機及服務,同時提供異常通知、事件處理等功能。與商業IT管理系統相比,Nagios 具有成本低廉、結構簡單、可維護性強等諸多優點。
Nagios 安裝配置:
*安裝環境 centos 6.3
*新版本改進
5 |
3.4.4 - 01/12/2013 |
6 |
------------------ |
7 |
* Reenabled check for newer versions of Nagios Core (Mike Guthrie) |
8 |
* Fixed bug #408: service checks get duplicated on reload (Eric Stanley) |
9 |
* Fixed bug #401: segmentation fault on Solaris when parsing unknown timeperiod directives. (Eric Stanley) |
10 |
* Added NULL pointer checks to CGI code. (Eric Stanley) |
11 |
* Fixed buffer overflow vulnerability in CGI code. Thanks to Neohapsis (http://archives.neohapsis.com/archives/fulldisclosure/2012-12/0108.html) for finding this. (Eric Stanley) |
一、創建用戶和組
[root@localhost ~]# useradd -s /sbin/nologin nagios
[root@localhost ~]# mkdir /usr/local/nagios
[root@localhost ~]# chown -R nagios:nagios /usr/local/nagios/
二、安裝apache、php、sendmail、gd_devel
[root@localhost ~]# yum install gd-devel httpd httpd-devel php sendmail -y
三、編譯安裝Nagios
[root@localhost ~]# wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.4.4/nagios-3.4.4.tar.gz
[root@localhost ~]# tar zxvf nagios-3.4.4.tar.gz
[root@localhost ~]# cd nagios #跟老版本有點區別
[root@localhost nagios]# ./configure --prefix=/usr/local/nagios/ #指定安裝目錄
[root@localhost nagios]# make all
[root@localhost nagios]# make install #安裝Nagios主程序的CGI和HTML文件
[root@localhost nagios]# make install-init #創建Nagios啟動腳本
[root@localhost nagios]# make install-commandmode #配置目錄權限
[root@localhost nagios]# make install-config #安裝Nagios示例配置文件
* nagios安裝完成后,目錄對應的功能說明如下:
bin:可執行程序所在目錄
etc:配置文件所在目錄
sbin:cgi文件所在目錄,也就是執行外部命令所需文件所在目錄
share:網頁文件所在目錄
libexec:外部插件所在目錄
var:日志文件,lock等文件所在目錄
var/archives:日志自動歸檔目錄
var/rw:用來存放外部命令文件的目錄
四、編譯安裝nagios-plugins
[root@localhost ~]# wget http://sourceforge.net/projects/nagiosplug/files/latest/download?source=directory
[root@localhost ~]# tar zxvf nagios-plugins-1.4.16.tar.gz
[root@localhost ~]# cd nagios-plugins-1.4.16
[root@localhost nagios-plugins-1.4.16]# ./configure --prefix=/usr/local/nagios/
[root@localhost nagios-plugins-1.4.16]# make && make install
五、配置Apache
[root@localhost ~]# vi /etc/httpd/conf/httpd.conf
#紅色部分為修改添加部分
User nagios
Group nagios
DirectoryIndex index.html index.html.var index.php
AddType application/x-httpd-php .php
#在配置文件末尾添加如下信息:
#setting for nagios
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
#添加Apache認證用戶:
[root@localhost ~]# /usr/bin/htpasswd -c /usr/local/nagios/etc/htpasswd user
New password:
Re-type new password:
Adding password for user user
六、配置本機監控
1.新建monitor 文件,拷貝示例文件到該目錄下
[root@localhost etc]# pwd
/usr/local/nagios/etc
[root@localhost etc]# mv objects/ monitor
2.修改聯系人配置文件
[root@localhost monitor]# cat contacts.cfg |grep -v "#"|grep " "
define contact{
contact_name user ; Short name of user
use generic-contact ; 引用generic-contact屬性信息
alias Nagios Admin ; Full name of user
email user@163.com ; 告警接收郵箱
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members user ;添加上面定義的聯系人,逗號分隔
}
3.修改cgi.cfg
default_user_name=user ;將用戶名修改為nagios界面登錄的用戶名
4.修改nagios.cfg 將所有cfg_file=都注釋掉添加如下一行
cfg_dir=/usr/local/nagios/etc/monitor
#這樣配置非常方便以后維護
5.使用命令:/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg檢查配置是否有誤
6.重啟apache、nagios 并加到開啟啟動項
[root@localhost ~]# service httpd restart
停止 httpd:[確定]
正在啟動 httpd:[確定]
[root@localhost ~]# service nagios restart
Running configuration check...done.
Stopping nagios: .done.
Starting nagios: done.
[root@localhost ~]# chkconfig httpd on
[root@localhost ~]# chkconfig nagios on
7.下圖為了看的更直觀,沒有刪除其他的配置,目前還沒有這個版本的漢化包,3.2版本有漢化包,漢化過的軟件比較別扭,英文版的多使用幾次就熟悉了。