1. Trang chủ
  2. » Hóa học

Tim Hieu Nagios

19 15 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 19
Dung lượng 363,08 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Cài đặt cấu hình để NRPE nhận thư viện ssl và biên dịch NRPE addon. ./configure --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/i386-linux-gnu make all[r]

Trang 1

I CÀI ĐẶT NAGIOS VÀ NAGIOS PLUGINS TRÊN

MONITOR COMPUTER(SERVER)

CÀI ĐẶT PACKAGE CẦN THIẾT: Cài đặt Apache2, PHP, MySQL Server,

PHPMyAdmin, GCC compiler and development libraries, GD2 library:

sudo apt-get install apache2 php5 libapache2-mod-php5 mysql-server

libapache2-mod-auth-mysql php5-mysql phpmyadmin build-essential libgd2-xpm-dev

Thêm phpmyadmin vào file cầu hình của apache server, mở file:

sudo nano /etc/apache2/apache2.conf

Thêm vào dòng sau, cuối file:

Include /etc/phpmyadmin/apache.conf

Khởi động lại apache server:

sudo service apache2 restart

1 TẠO THÔNG TIN NGƯỜI DÙNG

Tạo tài khoản người dùng để cài đặt nagios:

Truy cập dưới quyền root:

sudo –s

Tạo người dùng mới:

/usr/sbin/useradd -m -s /bin/bash nagios

Đặt password cho người dùng vừa tạo(password: nagios):

passwd nagios

Thêm nhóm mới:

/usr/sbin/groupadd nagcmd

Thêm người dùng nagios và apache vào nhóm vừa tạo:

/usr/sbin/usermod -a -G nagcmd nagios

/usr/sbin/usermod -a -G nagcmd www-data

2 DOWNLOAD NAGIOS VÀ PLUGINS

Tạo thư mục chứa file download về:

Trang 2

mkdir ~/downloads

cd ~/downloads

Command download nagios 3.5.0:

wget

http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.5.0.tar.gz

Command download nagios-plugins 1.4.16:

wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz

3 BIÊN DỊCH VÀ CÀI ĐẶT NAGIOS

Giải nén Nagios source code tarball

cd ~/downloads

tar xzf nagios-3.5.0.tar.gz

cd nagios

Chạy Nagios configure script, dưới quyền nhóm nagcmd

./configure with-command-group=nagcmd

Biên dịch Nagios source code

make all

Install binaries, init script, sample config files and set permissions on the

external command directory

make install

make install-init

make install-config

make install-commandmode

4 TÙY CHỈNH CẤU HÌNH

Các file cấu hình được lưu tại thư mục: /usr/local/nagios/etc/objects/

Có thể chỉnh sửa email của tài khoản nagiosadmin, email này sẽ nhận được các

cảnh báo từ nagios, chỉnh sửa địa chỉ email trong file:

/usr/local/nagios/etc/objects/contacts.cfg

5 CẤU HÌNH GIAO DIỆN WEB TRUY CẬP NAGIOS

Trang 3

Cài đặt cấu hình web Nagios trong thư mục Apache conf.d, thông qua lệnh sau:

make install-webconf

Create a nagiosadmin account for logging into the Nagios web interface

Remember the password you assign to this account - you’ll need it later

Tạo tài khoản người dùng nagiosadmin dùng đăng nhập vào giao diện web của Nagios(password: nagiosadmin):

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

Restart Apache để các cấu hình mới có hiệu lực

/etc/init.d/apache2 reload

6 BIÊN DỊCH VÀ CÀI ĐẶT NAGIOS PLUGINS

Giải nén Nagios plugins source code tarball

cd ~/downloads

tar xzf nagios-plugins-1.4.16.tar.gz

cd nagios-plugins-1.4.16

Chạy Nagios Plugin configure script, dưới quyền người dùng nagios, nhóm nagios

./configure with-nagios-user=nagios with-nagios-group=nagios

Biên dịch và cài đặt

make

make install

7 START NAGIOS

Cấu hình để Nagios tự chạy lúc khởi động:

ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

Kiểm tra lại file cấu hình Nagios thông qua lệnh:

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nếu không có lỗi, start Nagios :

/etc/init.d/nagios start

8 ĐĂNG NHẬP GIAO DIỆN WEB

Trang 4

username: nagiosadmin

password: nagiosadmin

II CÀI ĐẶT NRPE ADDON TRÊN REMOTE

COMPUTER(CLIENT)

1 TẠO THÔNG TIN NGƯỜI DÙNG

Truy cập dưới quyền root:

sudo –s

Tạo người dùng mới:

/usr/sbin/useradd nagios

Đặt password cho người dùng vừa tạo(password: nagios):

passwd nagios

2 DOWNLOAD VÀ CÀI ĐẶT NAGIOS PLUGINS

Tạo thư mục chứa file download về:

mkdir ~/downloads

cd ~/downloads

Command download nagios-plugins 1.4.16:

wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz

Giải nén Nagios plugins source code tarball

tar xzf nagios-plugins-1.4.16.tar.gz

cd nagios-plugins-1.4.16

Chạy Nagios Plugin configure script, dưới quyền người dùng nagios, nhóm nagios

./configure with-nagios-user=nagios with-nagios-group=nagios

Biên dịch và cài đặt

make

make install

Trang 5

Chuyển quyền sở hữu của thư mục nagios-plugins về cho người dùng nagios chown nagios.nagios /usr/local/nagios

chown -R nagios.nagios /usr/local/nagios/libexec

3 CÀI ĐẶT XINETD

Dùng để điều khiển truy cập

apt-get install xinetd

4 CÀI ĐẶT NRPE DAEMON

cd ~/downloads

Command download NRPE addon:

wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz

Giải nén Nagios plugins source code tarball

tar xzf nrpe-2.14.tar.gz

cd nrpe-2.14

Cài đăt thư viện libssl-dev:

apt-get install libssl-dev

Cài đặt cấu hình để NRPE nhận thư viện ssl và biên dịch NRPE addon

./configure with-ssl=/usr/bin/openssl with-ssl-lib=/usr/lib/i386-linux-gnu make all

Cài đăt thư viện NRPE plugin(for testing), daemon, and sample daemon config file:

make install-plugin

make install-daemon

make install-daemon-config

Cài đặt NRPE daemon như một dịch vụ quản lý bởi xinetd

make install-xinetd

Mở file: nano /etc/xinetd.d/nrpe và thêm IP address của monitoring

server, tìm đến dòng sau và thêm vào:

Trang 6

only_from = 127.0.0.1[space]<monitoring_nagios_ip_address(ip server)>

Mở file: nano /usr/local/nagios/etc/nrpe.cfg và thêm IP address của

monitoring server, tìm đến dòng sau và thêm vào:

allowed_hosts=127.0.0.1, <monitoring_nagios_ip_address(ip server)>

Nếu muốn chỉnh sửa ngưỡng cảnh báo, thêm command cần check cũng

chỉnh sửa trong file nrpe.cf này:

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10

command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1 command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

#add by QuocViet(định nghĩa câu lệnh check mới)

command[check_memory]=/usr/local/nagios/libexec/check_memory.sh -w 80 -c 90

Thêm entry cho NRPE daemon vào file: nano /etc/services

nrpe 5666/tcp # NRPE

Restart the xinetd service

service xinetd restart

5 KIỂM TRA HOẠT ĐỘNG NRPE DAEMON

Make sure the nrpe daemon is running under xinetd

netstat -at | grep nrpe

The output out this command should show something like this:

check_nrpe xem có hoạt động hay không?

/usr/local/nagios/libexec/check_nrpe -H localhost

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_users

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_load

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_hda1

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_total_procs

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_zombie_procs

Trang 7

Sẽ nhận được kết quả là version của NRPE: NRPE v2.14, users, load, hda1, total_process, zombie_process

6 MỞ FIREWALL

iptables -A INPUT -p tcp -d 0/0 -s 0/0 dport 5666 -j ACCEPT

iptables-save

iptables -L

III CÀI ĐẶT NRPE ADDON TRÊN MONITOR

COMPUTER(SERVER)

Truy cập dưới quyền root:

sudo -s

cd ~/downloads

Command download NRPE addon:

wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz

Giải nén Nagios plugins source code tarball

tar xzf nrpe-2.14.tar.gz

cd nrpe-2.14

Cài đăt thư viện libssl-dev:

sudo apt-get install libssl-dev

Cài đặt cấu hình để NRPE nhận thư viện ssl và biên dịch NRPE addon

./configure with-ssl=/usr/bin/openssl with-ssl-lib=/usr/lib/i386-linux-gnu make all

Cài đăt thư viện NRPE plugin:

make install-plugin

/usr/local/nagios/libexec/check_nrpe -H <ip_remote_computer(client)>

Trang 8

You should get a string back that tells you what version of NRPE is installed on the remote host, like this: NRPE v2.14

Mở file : nano /usr/local/nagios/etc/objects/commands.cfg thêm vào các dòng sau để định nghĩa command cho nrpe :

define command{

command_name check_nrpe

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }

Mở file : nano /usr/local/nagios/etc/objects/localhost.cfg thêm vào các dòng sau để định nghĩa host sẽ theo dõi cho nrpe :

Định nghĩa host :

define host{

name linux-box ;Name of this template

use generic-host ; Inherit default values

check_period 24x7

check_interval 5

retry_interval 1

max_check_attempts 10

check_command check-host-alive

notification_period 24x7

notification_interval 30

notification_options d,r

contact_groups admins

register 0 ; DONT REGISTER THIS - ITS A TEMPLATE }

define host{

use linux-box ; Inherit default values from a template

Trang 9

host_name <host_name> ; The name we're giving to this server alias <long_host_name> ; A longer name for the server

address <ip> ; IP address of the remote host

}

Định nghĩa services CPU_Load cho tất cả các host:

define service{

use generic-service

host_name * ;all host

service_description CPU Load

check_command check_nrpe!check_load

}

Định nghĩa services Current_Users cho tất cả các host:

define service{

use generic-service

host_name * ;all host

service_description Current Users

check_command check_nrpe!check_users

}

Định nghĩa services Total Process cho tất cả các host:

define service{

use generic-service

host_name * ;all host

service_description Total Process

check_command check_nrpe!check_total_procs

}

Định nghĩa services Zombie Process cho tất cả các host:

Trang 10

define service{

use generic-service

host_name * ;all host

service_description Zombie Process

check_command check_nrpe!check_zombie_procs

}

Kiểm tra Nagios configuration files.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nếu không có lỗi, restart Nagios.

service nagios restart

IV ĐỊNH NGHĨA MỘT DỊCH VỤ TRÊN

REMOTE VÀ ĐUỢC QUẢN LÝ TRÊN

MONITOR

Lấy ví dụ như thêm dịch vụ theo dõi % RAM sử dụng trên máy remote, tiến hành các bước sau :

Trên REMOTE host :

1 VIẾT SCRIPT/SỬ DỤNG SRIPT DOWNLOAD VỀ CHO DỊCH VỤ(các file đính kèm : check_ram.sh, check_linux_stats.pl,

check_mysql_connection.sh)

Các Sript đính kèm theo tài liệu này gồm :

+check_ram.sh : kiểm tra dung lượng RAM đang sử dụng

+check_linux_stats.pl(Download trên trang plugin của nagios): kiểm tra %CPU đang sủ dụng Vơi script này cần cài đặt gói sau: libsys-statistics-linux-perl

sudo apt-get install libsys-statistics-linux-perl

+check_mysql_connection.sh : đếm số kết nối hiên tại tới MySQL Server

2 COPY CÁC SCRIPT VÀO THƯ MỤC CHỨA SCRIPT CỦA NRPE, GRANT PRIVILEGES

sudo -s

Trang 11

cp script_location/SCRIPT_NAME /usr/local/nagios/libexec

cd /usr/local/nagios/libexec

chown nagios SCRIPT_NAME

chmod 755 SCRIPT_NAME

3 THÊM COMMAND CHECK VÀO FILE nrpe.cfg

Mở file : nano /usr/local/nagios/etc/nrpe.cfg

Thêm vào dòng sau, với ý nghĩa kiểm tra CPU sử dụng, mức cảnh báo-warning(-w 80) là 80%, mức nguy cấp-critical(-c 90) là 90%:

command[check_cpu_use]=/usr/local/nagios/libexec/check_linux_stats.pl –cpu -w

80 -c 90

Thêm vào dòng sau, với ý nghĩa kiểm tra RAM sử dụng, mức cảnh báo-warning(-w 80) là 80%, mức nguy cấp-critical(-c 90) là 90%:

command[check_ram_use]=/usr/local/nagios/libexec/check_ram.sh -w 80 -c 90

Thêm vào dòng sau, với ý nghĩa kiểm tra số nối kết đến MySQL sử dụng, mức cảnh báo-warning(-w 80) là 80 nối kết, mức nguy cấp-critical(-c 100) là 90 nối kết:

command[check_num_mysql_connection]=/usr/local/nagios/libexec/check_mysql_c

onnection.sh -w 80 -c 100

4 KIỂM TRA HOẠT ĐỘNG TRÊN MÁY CỤC BỘ

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_cpu_use /usr/local/nagios/libexec/check_nrpe -H localhost -c check_ram_use /usr/local/nagios/libexec/check_nrpe -H localhost -c

check_num_mysql_connection

Trên MONITOR host(Không cần cấu hình nếu tạo Web-Interface riêng, không dùng Web-interface của

nagios) :

Mở file : nano /usr/local/nagios/etc/objects/localhost.cfg thêm vào các dòng sau để định nghĩa service vừa tạo sẽ theo dõi cho nrpe :

Định nghĩa services Memory Usage CPU cho tất cả các host:

define service {

Trang 12

use generic-service

host_name * ;all host

service_description Memory Usage RAM

check_command check_nrpe! check_cpu_use !80!90

}

Định nghĩa services Memory Usage RAM cho tất cả các host:

define service {

use generic-service

host_name * ;all host

service_description Memory Usage CPU

check_command check_nrpe! check_ram_use !80!90

}

Định nghĩa services Memory Usage RAM cho tất cả các host:

define service {

use generic-service

host_name * ;all host

service_description Memory Usage CPU

check_command check_nrpe! check_ram_use !80!90

}

Kiểm tra Nagios configuration files.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nếu không có lỗi, restart Nagios.

service nagios restart

V TẠO SCRIPT TRUY CẬP MySQL

DATABASE VÀ TẠO WEB INTERFACE TRÊN MONITOR HOST

Trang 13

1. CẤU HÌNH CRONTAB VÀ TẠO SCRIPT TRUY CẬP

DATABASE(file đính kèm check.sh: insert các kết quả check

từ check_nrpe)

Cấu hình crontab trong ubuntu để gọi shell script check_nrpe(check.sh)« đinh kỳ » (trong trường hợp này là 1 phút 1 lần) thực thi chèn kết quả vào database trong MySQL Server :

Mở crontab :

sudo crontab –e

Chọn trình soạn thảo nano(số 2) Chèn các cấu hình sau vào cuối file :

#cấu hình shell, path_shell, user_run_shell, path_root SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root

HOME=/

#mỗi phút gọi thục thi script check.sh một lần

* * * * * /home/nqviet733/Desktop/check.sh

2. TẠO DATABASE(dùng file : database(check_nrpe).sql)

Database : check_nrpe Table :check_detail

Web interface được tạo bằng PHP dựa trên mô hình MVC, yêu cầu bật mod rewrite trên apache server

sudo a2enmod rewrite

Xem mod rewrite có trong danh sách được bật hay chưa

sudo apache2ctl -M

Trang 14

KÍCH HOẠT CẤU HÌNH TRONG htaccess FILE

sudo nano /etc/apache2/upload.123doc.net-available/default

Chỉnh sửa AllowOverride từ None thành All(nếu tạo website: thư mục

của website ở đây là: nrpe) đặt trong thư mục /var/www/)

<Directory /var/www/>

Options Indexes FollowSymLinks MultiViews

AllowOverride All #None => All

Order allow,deny

allow from all

</Directory>

Hoặc thêm mới các dòng sau, khi đặt website(<site_name>) trong thư

mục của nagios: /usr/local/nagios/share/

#add by quoc viet

<Directory /usr/local/nagios/share/>

Options Indexes FollowSymLinks MultiViews

AllowOverride None

Order allow,deny

allow from all

</Directory>

#add by quoc viet

Restart apache2 server

sudo service apache2 restart

Truy cập web site theo địa chỉ, http://localhost/nrpe/detail , nhận được giao diện như sau:

Trang 15

Khi truy cập hoặc refresh trang sẽ load tất cả, theo thứ tự từ mới đến cũ thông tin hiển thị về %CPU, %RAM đang sử dụng, số nối kết đến hiện tại của MySQL Server, trạng thái RAM, CPU, MYSQL Các ngưỡng của trạng thái được thiết lập trong file check.sh(Ở phần V.1)

Trang sẽ tự động load những dòng trạng thái mới được thêm vào lên phía trên cùng(chỉ những dòng mới được thêm), 1 phút load 1 lần mà không cần refresh lại

Ngày đăng: 21/01/2021, 16:50

TỪ KHÓA LIÊN QUAN

w