CentOS下Nagios的安裝與配置
成都創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站制作、做網(wǎng)站、外貿營銷網(wǎng)站建設與策劃設計,平山網(wǎng)站建設哪家好?成都創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設十多年,網(wǎng)設計領域的專業(yè)建站公司;建站業(yè)務涵蓋:平山等地區(qū)。平山做網(wǎng)站價格咨詢:028-86922220
Nagios是一款開源的電腦系統(tǒng)和網(wǎng)絡監(jiān)視工具,能有效監(jiān)控Windows、Linux和Unix的主機狀態(tài),交換機路由器等網(wǎng)絡設置,打印機等。
Nagios可以識別4種狀態(tài)返回信息,即 0(OK)表示狀態(tài)正常/綠色、1(WARNING)表示出現(xiàn)警告/***、2(CRITICAL)表示出現(xiàn)非常嚴重的錯誤/紅色、3(UNKNOWN)表示未知錯誤/深***。
一、環(huán)境
Host NameOSIPSoftware
Nagios-ServerCentOS release 6.3 (Final)192.168.1.108Apache、Php、Nagios、nagios-plugins
Nagios-LinuxCentOS release 5.8 (Final)192.168.1.111nagios-plugins、nrpe
Nagios-WindowsWindows XP192.168.1.113 NSClient++
防火墻已關閉/iptables: Firewall is not running.
SELINUX=disabled
二、Nagios服務端安裝
基礎支持套件:gcc glibc glibc-common gd gd-devel xinetd openssl-devel
2.1創(chuàng)建nagios用戶和用戶組
useradd -s /sbin/nologin nagios
mkdir /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios
2.2編譯安裝Nagios
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.3.tar.gz
tar zxvf nagios-3.4.3.tar.gz
cd nagios
./configure --prefix=/usr/local/nagios
make all
make install
make install-init
make install-commandmode
make install-config
cd
chkconfig --add nagios
chkconfig --level 35 nagios on
chkconfig --list nagios
2.3安裝Nagios 插件
wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
or
wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
tar xzvf nagios-plugins-1.5.tar.gz
cd nagios-plugins-1.5
./configure --prefix=/usr/local/nagios
make && make install
2.4安裝配置Apache、PHP
yum -y install httpd php //如果已經(jīng)安裝此步驟略過;
2.4.1配置apache主配置文件
vim /etc/httpd/conf/httpd.conf
找到
User apache
Group apache
更改為
User nagios
Group nagios
找到
DirectoryIndex index.html
更改為
DirectoryIndex index.html index.php
在下一行新增如下內容:
AddType application/x-httpd-php .php
為了安全起見,一般情況下要讓nagios 的web 監(jiān)控頁面必須經(jīng)過授權才能訪問,這需要增加驗證配置,即在httpd.conf 文件最后添加如下信息:
#setting for nagios
ScriptAlias /nagios/cgi-bin "/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
Alias /nagios "/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
保存退出;
2.4.2創(chuàng)建apache目錄驗證文件及啟動apache服務
htpasswd -c /usr/local/nagios/etc/htpasswd david
cat /usr/local/nagios/etc/htpasswd
service httpd restart
到這里 Nagios 安裝及基本配置已經(jīng)完成了;測試訪問一下:
http://ip地址/nagios
用戶名
密碼
2.5配置Nagios
2.5.1配置聯(lián)系人信息
cp /usr/local/nagios/etc/objects/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg.bak
vim /usr/local/nagios/etc/objects/contacts.cfg
更改
contact_name david
email 744120325@qq.com
contactgroup_name ts
members david
2.5.2配置主機信息
touch /usr/local/nagios/etc/objects/hosts.cfg
vim /usr/local/nagios/etc/objects/hosts.cfg
新增如下內容:
define host{
use linux-server
host_name hostname01
alias hostname01
address 192.168.1.111
}
define host{
use linux-server
host_name hostname02
alias hostname02
address 192.168.1.112
}
define hostgroup{
hostgroup_name bsmart-servers
alias bsmart servers
members hostname01,hostname02
}
--------------------------------------
vim /etc/hosts
新增
ip地址 hostname //192.168.122.128 localhost
--------------------------------------
由于本實驗也測試監(jiān)控安裝Nagios服務端的這臺 define command{ command_name check_mysql command_line $USER1$/check_mysql -H $HOSTADDRESS$ $ARG1$ } 2.5.6配置模板配置信息 nagios主要用于監(jiān)控主機資源以及服務,在nagios配置中稱為對象,為了不必重復定義一些監(jiān)控對象,Nagios引入了一個模板配置文件,將一些共性的屬性定義成模板,以便于多次引用。這就是templates.cfg的作用。 更改 contact_groups ts 2.5.7配置CGI信息 想通過web監(jiān)控界面執(zhí)行cgi腳本,例如重啟nagios進程、關閉nagios通知、停止nagios主機檢測等;需要配置,否則默認即可; cp /usr/local/nagios/etc/cgi.cfg /usr/local/nagios/etc/cgi.cfg.bak vim /usr/local/nagios/etc/cgi.cfg 更改 default_user_name=david authorized_for_system_information=nagiosadmin,david authorized_for_configuration_information=nagiosadmin,david authorized_for_system_commands=david authorized_for_all_services=nagiosadmin,david authorized_for_all_hosts=nagiosadmin,david authorized_for_all_service_commands=nagiosadmin,david authorized_for_all_host_commands=nagiosadmin,david 2.5.8配置Nagios主配置文件信息 cp /usr/local/nagios/etc/nagios.cfg /usr/local/nagios/etc/nagios.cfg.bak vim /usr/local/nagios/etc/nagios.cfg 新增如下內容: cfg_file=/usr/local/nagios/etc/objects/services.cfg 保存退出即可; 2.5.9驗證Nagios配置文件的正確性 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 如果最后顯示出來如下信息,即表是沒問題: Total Warnings: 0 Total Errors: 0 --------------------------------------- 2.6安裝NRPE cd wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz make all make install-plugin ------------------------- #/usr/local/nagios/libexec/check_nrpe -H 192.168.1.235 //測試一下監(jiān)控機使用check_nrpe 與被監(jiān)控機運行的nrpe daemon之間的通信; ------------------------- vim //usr/local/nagios/etc/objects/commands.cfg 新增如下內容: # 'check_nrpe' command definition 2.7重啟各相關的服務 service nagios restart service postfix restart 三、客戶端(被監(jiān)控機)安裝配置(Linux) 基礎支持套件:gcc glibc glibc-common gd gd-devel xinetd openssl-devel 3.1新建用戶 useradd nagios 3.2安裝Nagios插件 cd wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz or wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz tar xzvf nagios-plugins-1.5.tar.gz cd nagios-plugins-1.5 ./configure --prefix=/usr/local/nagios make && make install chown nagios.nagios /usr/local/nagios 3.3安裝NRPE cd wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz make all make install-plugin make install-daemon make install-daemon-config make install-xinetd vim /etc/xinetd.d/nrpe 在only_from 后增加監(jiān)控主機的IP地址; vim /etc/services 增加NRPE服務:nrpe 5666/tcp service xinetd restart netstat -an | grep 5666 //查看NRPE 是否已經(jīng)啟動; /usr/local/nagios/libexec/check_nrpe -H localhost //測試NRPE 是否工作正常; 注:為了后面工作的順利進行,注意本地防火墻要打開5666能讓外部的監(jiān)控機訪問。 3.4定義對Nagios-Linux 主機的監(jiān)控 下面就可以在services.cfg(服務器上的配置文件)中定義對Nagios-Linux 主機的監(jiān)控了: define service{ --------------------------------------------------------- 如果還需要監(jiān)控其它服務的,請在上面的文件增加相應的服務項以及在被監(jiān)控機上相應增加,如: 例:增加HTTP監(jiān)控: 監(jiān)控機: vim /usr/local/nagios/etc/objects/services.cfg 新增如下內容: define service{ 被監(jiān)控機: vim /usr/local/nagios/etc/nrpe.cfg 新增如下內容: command[check_http]=/usr/local/nagios/libexec/check_http -I 127.0.0.1 注:更改過配置的都要重啟一下相應服務才能生效; 參考 http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html
tar zxvf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure
define command{
command_name check_nrpe # 定義命令名稱為check_nrpe,在services.cfg中要使用這個名稱.
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ #這是定義實際運行的插件程序.
# 這個命令行的書寫要完全按照check_nrpe這個命令的用法,不知道用法的就用check_nrpe –h查看.
}
service httpd restart
chown -R nagios.nagios /usr/local/nagios/libexec
tar zxvf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure
use local-service
host_name Nagios-Linux
service_description Current Load
check_command check_nrpe!check_load
}
define service{
use local-service
host_name Nagios-Linux
service_description Check Disk
check_command check_nrpe!check_disk
}
define service{
use local-service
host_name Nagios-Linux
service_description Total Processes
check_command check_nrpe!check_total_procs
}
define service{
use local-service
host_name Nagios-Linux
service_description Current Users
check_command check_nrpe!check_users
}
define service{
use local-service
host_name Nagios-Linux
service_description Check Zombie Procs
check_command check_nrpe!check_zombie_procs
}
use local-service
host_name Nagios-Linux
service_description HTTP
check_command check_nrpe!check_http
}
新聞名稱:CentOS下Nagios的安裝與配置
當前地址:http://weahome.cn/article/jpiihi.html