Hướng dẫn cài đặt nagios plugin kiểm tra root login năm 2024

Trước khi cấu hình giám sát VMware ESXi, chúng ta có thể tham khảo cách cài đặt Nagios Core 4x trên CentOS 7 tại đây

1. Cấu hình trên VMware ESXi

Start CIM server để cho phép Nagios thu thập các thông tin về: server vendors, storage hardware vendors và independent hardware vendors

Hướng dẫn cài đặt nagios plugin kiểm tra root login năm 2024

Nếu vmware esxi đang bật firewall sẽ cấu hình để cho phép nagios giao tiếp với port CIM (port 5989)

2. Cấu hình Nagios server

Step1: Cài đặt python và pywbem (python extension )

yum install python python-setuptools -y

Step2: Download plugin check esxi

cd /usr/local/nagios/libexec/ wget  chmod +x check_esxi_hardware.py chown nagios:nagios check_esxi_hardware.py

Step3: Define command check_esxi_hardware

Thêm nội dung sau vào tệp /usr/local/nagios/etc/objects/commands.cfg

define command{ command_name check_esxi_hardware command_line $USER1$/check_esxi_hardware.py -H $HOSTADDRESS$ -U file:$ARG1$ -P file:$ARG2$ -V $ARG3$ --perfdata

Step4: Tạo tệp tin chứa user/password có thể truy cập VMWare ESXi

Để truy vấn thông tin của VMWare, chúng ta cần tài khoản có thể truy cập VMWare server (Giả sử root/Password)

Nhằm hạn chế show thông tin user/password ở dạng cleartext, để an toàn hơn chúng ta chỉ thông tin login VMWare vào tệp tin ẩn

Tạo tệp ​​/home/nagios/.esxi01 với thông tin sau:

root P@ssw0rd

Step5: Định nghĩa VMWare ESXi muốn giám sát

Chúng ta thực hiện giám sát phần cứng cho host VMware với thông tin như sau:

  • IP: 192.168.10.101
  • u/p: root/P@ssw0rd
  • hostname: EXSi01

Host Definitions

define host{

use linux-server
host_name ESXi01_192.168.10.101
alias ESXi01_192.168.10.101
address 192.168.10.101
contact_groups  linuxadmins
notifications_enabled 1
}

Service Definitions

define service{

use local-service
host_name ESXi01_192.168.10.101
service_description PING
check_command check_ping!100.0,20%!500.0,60%

Check Hardware#

define service{

use generic-service
host_name ESXi01_192.168.10.101
service_description ESXi Hardware - IBM x3650M4
check_command  check_esxi_hardware!**​**/home/nagios/.esxi01!/home/nagios/.esxi01!ibm
contact_groups  linuxadmins
notifications_enabled 1
}

Step6: Kiểm tra hoạt động

/usr/local/nagios/libexec/check_esxi_hardware.py -H 192.168.10.101 -U root -P P@ssw0rd

OK – Server: IBM System x3650 M4 : -[7915D2A]- s/n: 06TGYYY System BIOS: -[VVE128EUS-1.40]- 2013-05-31

Tôi sử dụng CentOS 6.4 mininal (dung lượng CD cài đặt 350MB) chỉ với những package cần thiết, core của Centos để tối ưu hệ thống. Quá trình cài đặt CentOS thì tôi không đề cập đến nữa.

Trong khuôn khổ bài viết này, tôi chỉ viết về Nagios.

Phần 1: Cài đặt Nagios Core

Bước 1: Tạo user và group để cho Nagios

[[email protected] ~]# useradd nagios [[email protected] ~]# groupadd nagcmd [[email protected] ~]# usermod -a -G nagcmd nagios

Bước 2: Cài đặt các gói cần thiết

[[email protected] ~]# yum install httpd gcc glibc glibc-common gd gd-devel php

Bước 3: Download gói core của Nagios và plugins

[[email protected] ~]# cd /tmp

[[email protected] tmp]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.5.0.tar.gz

[[email protected] tmp]# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz

Bước 4: Cài đặt Nagios core:

[[email protected] tmp]# tar xvzf nagios-3.5.0.tar.gz

[[email protected] tmp]

cd nagios

[[email protected] nagios]#./configure --with-command-group=nagcmd
[[email protected] nagios]

make all

[[email protected] nagios]

make install-init

[[email protected] nagios]

make install-config

[[email protected] nagios]

make install-commandmode

[[email protected] nagios]

make install-webconf

[[email protected] nagios]

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

[[email protected] nagios]

service httpd start

[[email protected] nagios]

chkconfig httpd on

Bước 5: Cài đặt Nagios plugin

[[email protected] nagios]

cd /tmp

[[email protected] tmp]

tar xvzf nagios-plugins-1.4.16.tar.gz

[[email protected] tmp]

cd nagios-plugins-1.4.16

[[email protected] nagios-plugins-1.4.16]#./configure --with-nagios-user=nagios --with-nagios-group=nagios [[email protected] nagios-plugins-1.4.16]

make

[[email protected] nagios-plugins-1.4.16]

make install

Bước 6: Kiểm tra cấu hình sau khi đã config xong

[email protected] ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Total Warnings: 0

Total Errors: 0

Bước 7: Start các dịch vụ Nagios

[[email protected] ~]

chkconfig –add nagios

[[email protected] ~]

chkconfig nagios on

[[email protected] ~]

service nagios start

Vậy là hoàn tất việc cài đặt Nagios core. Giờ bạn có thể login và giám sát các host thông qua trang quản lý tại: http://ip-addess/nagios/