Setup Nagios 4x trên Centos 6.5


Setup Nagios 4x trên Centos 6.5
- Cài đặt các gói  packages cần thiết trước khi cài đặt nagios.

#yum install httpd php gcc glibc glibc-common gd gd-devel openssl-devel wget perl make

- Tạo user nagios/password

#useradd -m nagios
#passwd nagios    

- Tạo group nagcmd. Chuyển user nagios và apache vào groups nagcmd

#groupadd nagcmd
#usermod -a -G nagcmd nagios
#usermod -a -G nagcmd apache

- Taọ thư mục tạm để chứa gói cài đặt nagios

#mkdir nagiossource
#cd nagiossource

- Download gói cài đặt nagios và nagios plugins


- Giải nén gói cài đặt nagios

#tar zxvf nagios-4.0.2.tar.gz
#cd nagios-4.0.2

- Cài đặt nagios

#./configure --with-command-group=nagcmd
#make all
#make install
#make install-init
#make install-config
#make install-commandmode
#make install-webconf



- Tạo account nagiosadmin để login vào website

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

- Khởi động dịch vụ web

#service httpd start

- Cài đặt plugins nagios
#tar zxvf nagios-plugins-1.5.tar.gz
#cd nagios-plugins-1.5
#./configure --with-nagios-user=nagios --with-nagios-group=nagios
#make
#make install

- Cấu hình nagios autostart

#chkconfig --add nagios
#chkconfig nagios on

- Cấu hình Selinux cho nagios

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

- Cấu hình iptables cho phép truy xuất port 80

#vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT


Cấu hình Nagios

- Cấu hình file /usr/local/nagios/etc/nagios.cfg
+ comment các dòng sau:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg



+ Thêm vào các dòng cấu hình sau:
############# Hinh Duong Dan Den Cac File Define ######################
cfg_file=/usr/local/nagios/etc/contacts.cfg
cfg_file=/usr/local/nagios/etc/commands.cfg
cfg_file=/usr/local/nagios/etc/generic-host.cfg
cfg_file=/usr/local/nagios/etc/generic-service.cfg
cfg_file=/usr/local/nagios/etc/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/services.cfg
cfg_file=/usr/local/nagios/etc/timeperiods.cfg
cfg_dir=/usr/local/nagios/etc/servers

- Tạo các file: contacts.cfg, commands.cfg, generic-host.cfg, generic-service.cfg, hostgroups.cfg, services.cfg, timeperiods.cfg (các file nay có file mẫu trong /usr/local/nagios/etc/objects/ )

- Cấu hình server cần giám sát
+ Tạo file /usr/local/nagios/etc/servers/hcm.cfg
############## Server nagios #############
define host{
              use                     generic-host            
        host_name         Nagios-server
     alias                    Nagios Server
       address              IP server
        hostgroups         hcm-servers
}
define host{
              use                     generic-host            
        host_name         Server1-hcm
     alias                    Server1 HCM
       address              IP server
        hostgroups         hcm-servers
}
+ Tạo file /usr/local/nagios/etc/servers/danang.cfg
############## Server nagios #############
define host{
              use                     generic-host            
        host_name         server1-danang
     alias                    Server1 Da Nang
       address              IP server
        hostgroups         danang-servers
}


- Cấu hình file hostgroups.cfg
define hostgroup{
     hostgroup_name         hcm-servers
alias                    HCM Servers
       members                  Nagios-server, win-server
    }

- Cấu hình file servicegroups.cfg
define servicegroup{
     servicegroup_name    ping-services
   alias                    Ping Services
     members                  win-server,PING,Nagios-server,PING
        }


- Các service check trên windows được hỗ trợ bởi Nagios

define service{
use                  generic-service
host_name            remote-windows-host
service_description NSClient++ Version
check_command        check_nt!CLIENTVERSION
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description Uptime
check_command        check_nt!UPTIME
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description CPU Load
check_command        check_nt!CPULOAD!-l 5,80,90
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description Memory Usage
check_command        check_nt!MEMUSE!-w 80 -c 90
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description C:\ Drive Space
check_command        check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description W3SVC
check_command        check_nt!SERVICESTATE!-d SHOWALL -l W3SVC  # check The Internet Information Services (IIS) World Wide Web Publishing Service
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description Explorer
check_command        check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe  # có thể check các dịch vụ khác, thay explorer.exe bằng tên dịch vụ được hiển thị trong task manager
}

Post a Comment