1、 解決nagios的依賴關係,和所需組件:
# yum -y install httpd gcc glibc glibc-common *gd* php php-mysql mysql mysql-server
2、 nagios所需組件:nagios nagios-plugins ndoutils(非必須) ,
linux客戶端:nrpe windows客戶端NSClient++
創建nagiso用戶和組:
# groupadd nagcmd
# useradd -m nagios
# usermod -a -G nagcmd nagios
# usermod -a -G nagcmd apache
編譯安裝nagios:
# tar zxf nagios-3.1.2.tar.gz
# cd nagios-3.1.2
# ./configure --with-command-group=nagcmd --enable-event-broker --prefix=/var/www/nagios
# make all
# make install
# make install-init
# make install-config
# make install-commandmode
爲email指定您想用來接收nagios警告信息的郵件地址,默認是本機的nagios用戶:
# vi /var/www/nagios/etc/objects/contacts.cfg
email nagios@localhost #這個是默認設置
在httpd的配置文件目錄(conf.d)中創建Nagios的Web程序配置文件:
# make install-webconf
創建一個登錄nagios web程序的用戶,這個用戶帳號在以後通過web登錄nagios認證時所用:
# htpasswd -c /var/www/nagios/htpasswd.users nagiosadmin
啓動服務: #service httpd restart
編譯安裝nagios-plusgins:
# tar zxf nagios-plugins-1.4.13.tar.gz
# cd nagios-plugins-1.4.13
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/var/www/nagios --with-mysql=/usr/lib/mysql
#make && make install
啓動服務:
檢測配置文件:# /var/www/nagios/bin/nagios -v /var/www/nagios/etc/nagios.cfg
#service nagios restart
#chkconfig nagios add
#chkconfig nagios on
#setenforce 0 這個只是臨時關閉selinux
當然,也可以通過以下方式將nagios的CGI程序運行於SELinux/targeted模式而不用關閉selinux:
# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin
# chcon -R -t httpd_sys_content_t /usr/local/nagios/share
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
windows客戶端安裝:NSClient++-0.3.8-Win32.msi安裝完後打開nagios.cfg文件將
註釋去掉cfg_file=/usr/local/nagios/etc/objects/windows.cfg
定義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.191 ; 你主機的IP
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
linux客戶端的安裝:
先添加nagios用戶
useradd nagios
爲了安裝nrpe,先安裝nagios-plugins-1.4.15.tar.gz 插件
# 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
tar -zxvf nrpe-2.12.tar.gz
cd nrpe-2.12.tar.gz
./configure (會自動加載SSL)
#如果後面make報錯,加如下參數
./configure --enable-ssl --with-ssl-lib=/usr/lib/(當然前提要有openssl)
make all
make install-plugin
make install-daemon
make install-daemon-config
4.配置nrpe信息
vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1 //允許監控的IP
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
服務端
3.安裝NRPE
cd nagios-nrpe_2.8.1
./configure #默認自動添加了openssl
#因爲傳送過程要加密,如果後面make報錯,加如下參數
rpm -qa| grep ssl
openssl-devel-0.9.7a-43.17.el4_6.1
rpm -ql openssl-devel-0.9.7a-43.17.el4_6.1 | more
./configure --enable-ssl --with-ssl-lib=/lib/(當然前提要有openssl)
make all
make install-plugin
添加步驟:
vi /usr/local/nagios/etc/objects/commands.cfg
在nagios.cfg啓用有以下行
cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg
4.commands.cfg定義外部構件nrpe
#添加
#check nrpe
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
定義 mylinux.cfg
define host{
use linux-server
host_name mylinux
alias mylinux
address 192.168.0.27(客戶端IP既被監控的IP)
}
define service{
use generic-service
host_name mylinux
service_description check-swap
check_command check_nrpe!check_swap
}
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-disk
check_command check_nrpe!check_had1
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
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
define service{
use generic-service
host_name mylinux
service_description httpd
check_command check_http! -H 192.168.0.27
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
nagios監控mysql服務器:
1、建立專用數據庫:
[root@svr3 ~]# /usr/local/webserver/mysql/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 51910
Server version: 5.5.3-m3-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database nagios;
Query OK, 1 row affected (0.00 sec)
mysql> grant select on nagios.* to nagios@'%' identified by '123qweasd';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select User,Password,Host from user;
+----------------+-------------------------------------------+------------------+
| User | Password | Host |
+----------------+-------------------------------------------+------------------+
| root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 | localhost |
| nagios | *A1F1CB851D62F002C09A0C9C4A76262473432F55 | % |
+----------------+-------------------------------------------+------------------+
14 rows in set (0.00 sec)
12 rows in set (0.00 sec)
[root@svr3 ~]# /usr/local/nagios/libexec/check_mysql -H 192.168.0.3 -u nagios -d nagios -p 123qweasd
Uptime: 970046 Threads: 1 Questions: 684583 Slow queries: 3 Opens: 672 Flush tables: 1 Open tables:
注意:check_mysql必須如果沒有則說明mysql-devel沒有安裝,需要安裝後在重新編譯安裝nagios-plugins這個包
369 Queries per second avg: 0.705
[root@svr4 nrpe_install]# /usr/local/nagios/libexec/check_mysql -H 192.168.0.3 -u nagios -d nagios -p 123qweasd
Uptime: 970348 Threads: 1 Questions: 684584 Slow queries: 3 Opens: 672 Flush tables: 1 Open tables: 369 Queries per second avg: 0.705
果斷開始設置:
#定義用戶
#定義組,及隸屬用戶
#用戶增加
在command.cfg裏增加插件命令:
#check mysql
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u nagios -d nagios -p 123qweasd
}
#定義服務:
define service {
host_name mysql
check_period 24x7
max_check_attempts 2
normal_check_interval 1
retry_check_interval 1
contact_groups admins
notification_interval 5
notification_period 24x7
notification_options w,u,c,r
check_command check_mysql
}
飛信報警
1.修改模板文件
修改concont.cfg
2.
修改
commands.cfg
define command{
command_name notify-service-by-fetion
command_line /usr/bin/fetion --mobile 15003880800 --pwd 123qweQWE --to 15003880800 --msg-tpye=0 --msg-utf8 $HOSTNAME