Tải bản đầy đủ (.docx) (13 trang)

Hướng dẫn sử dụng và cài đặt Nagios trên Linux

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (47.3 KB, 13 trang )

Hướng dẫn cài đặt Nagios 4.4.5 ở CenOS 7 và 8

Nagios là một công cụ giám sát mã nguồn mở tuyệt vời, nó cung cấp cho bạn mơi trường giám
sát tồn diện hơn để ln theo dõi tất cả các máy / mạng của bạn cho dù bạn đang ở trong trung
tâm dữ liệu hay chỉ trong phịng thí nghiệm nhỏ của bạn.

Với Nagios, bạn có thể giám sát các máy chủ từ xa của mình và các dịch vụ của chúng từ xa trên
một cửa sổ duy nhất. Nó hiển thị cảnh báo và cho biết nếu có sự cố xảy ra trong máy chủ của
bạn, điều này cuối cùng giúp chúng tôi phát hiện một số sự cố trước khi chúng xảy ra. Nó giúp
chúng tơi giảm thời gian down-time và tổn thất kinh doanh.

Gần đây, Nagios đã phát hành phiên bản mới nhất Nagios Core 4.4.5 và bản phát hành ổn định
mới nhất của plugin Nagios 2.2.1

Bài viết này nhằm hướng dẫn bạn những hướng dẫn dễ dàng về cách cài đặt Nagios Core 4.4.5
mới nhất từ nguồn (tarball) trên các bản phân phối CentOS 6/7/8

Trong vòng 30 phút, bạn sẽ giám sát máy cục bộ của mình, khơng có quy trình cài đặt nâng cao
chỉ cài đặt cơ bản sẽ hoạt động 100% trên hầu hết các máy chủ Linux ngày nay.

Xin lưu ý: Các hướng dẫn cài đặt được hiển thị trong đây được viết dựa trên bản phân phối
CentOS 8 Linux.

Cài đặt Nagios 4.4.5 và Plugin Nagios 2.2.1

Nếu bạn làm theo các hướng dẫn này một cách chính xác, bạn sẽ kết thúc với thơng tin sau.

Nagios và các plugin của nó sẽ được cài đặt trong thư mục / usr / local / nagios.
Nagios sẽ được định cấu hình để giám sát một số dịch vụ trên máy cục bộ của bạn (Sử dụng đĩa,
Tải CPU, Người dùng hiện tại, Tổng số quá trình, v.v.)
Giao diện web Nagios sẽ có tại http: // localhost / nagios




Bước 1: Cài đặt phần phụ thuộc bắt buộc

Chúng ta cần cài đặt Apache, PHP và một số thư viện như gcc, glibc, glibc-common và thư viện
GD và các thư viện phát triển của nó trước khi cài đặt Nagios 4.4.5 với nguồn. Và để làm như vậy,
chúng ta có thể sử dụng trình cài đặt gói mặc định của yum.

[root@leoodz]# yum install -y httpd httpd-tools php gcc glibc glibc-common gd gd-devel make
net-snmp

Bước 2: Tạo người dùng và nhóm Nagios

Tạo người dùng nagios mới bằng lệnh useradd và tài khoản nhóm nagcmd và đặt mật khẩu.

[root@leoodz]# useradd nagios
[root@leoodz]# groupadd nagcmd

Tiếp theo, thêm cả người dùng nagios và người dùng apache vào nhóm nagcmd bằng lệnh
usermod.

[root@leoodz]# usermod -G nagcmd nagios
[root@leoodz]# usermod -G nagcmd apache

Bước 3: Tải xuống Nagios Core 4.4.5 và Plugin Nagios 2.2.1

Tạo một thư mục để cài đặt Nagios của bạn và tất cả các bản tải xuống trong tương lai.

[root@leoodz]# mkdir /root/nagios
[root@leoodz]# cd /root/nagios



Bây giờ hãy tải xuống các gói Nagios Core 4.4.5 và plugin Nagios 2.2.1 mới nhất bằng lệnh wget.

[root@leoodz nagios~]# wget
/>[root@leoodz nagios~]# wget />
Bước 4: Giải nén Nagios Core và các plugin của nó

[root@leoodz nagios~]# tar -xvf nagios-4.4.5.tar.gz
[root@leoodz nagios~]# tar -xvf nagios-plugins-2.2.1.tar.gz

Khi bạn giải nén các tarball này bằng lệnh tar, hai thư mục mới sẽ xuất hiện trong thư mục đó.

[root@leoodz nagios ~]# ls -l
total 13520
drwxrwxr-x 18 root root

4096 Aug 20 17:43 nagios-4.4.5

-rw-r--r-- 1 root root 11101966 Aug 20 17:48 nagios-4.4.5.tar.gz
drwxr-xr-x 15 root root

4096 Apr 19 12:04 nagios-plugins-2.2.1

-rw-r--r-- 1 root root 2728818 Apr 19 12:04 nagios-plugins-2.2.1.tar.gz

Cài đặt cấu hình Nagios Core

Bây giờ, đầu tiên chúng ta sẽ cấu hình Nagios Core và để làm như vậy chúng ta cần vào thư mục
Nagios và chạy tệp cấu hình và nếu mọi thứ diễn ra tốt đẹp, cuối cùng nó sẽ hiển thị đầu ra dưới

dạng sau. Vui lòng xem bên dưới.

[root@leoodz nagios~]# cd nagios-4.4.5/


[root@leoodz nagios-4.4.5 ]# ./configure --with-command-group=nagcmd

Nếu bạn làm chính xác thì đây sẽ là kết quả của lệnh sau

Creating sample config files in sample-config/ ...

*** Configuration summary for nagios 4.4.5 2019-08-20 ***:

General Options:
------------------------Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagcmd
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Install ${includedir}: /usr/local/nagios/include/nagios
Lock file: /run/nagios.lock
Check result directory: /usr/local/nagios/var/spool/checkresults
Init directory: /lib/systemd/system
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /usr/bin/mail
Host OS: linux-gnu
IOBroker Method: epoll

Web Interface Options:
------------------------



HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /usr/bin/traceroute

Review the options above for accuracy. If they look okay,
type 'make all' to compile the main program and CGIs.

Sau khi cấu hình, chúng ta cần biên dịch và cài đặt tất cả các tệp nhị phân bằng lệnh make all and
make install, nó sẽ cài đặt tất cả các thư viện cần thiết trong máy của bạn và chúng ta có thể tiến
hành thêm.

[root@leoodz nagios-4.4.5 ]# make all
[root@leoodz nagios-4.4.5 ]# make install

Kết quả:

*** Compile finished ***

If the main program and CGIs compiled without any errors, you
can continue with testing or installing Nagios as follows (type
'make' without any arguments for a list of all possible options):

make test
- This runs the test suite

make install
- This installs the main program, CGIs, and HTML files



make install-init
- This installs the init script in /lib/systemd/system

make install-daemoninit
- This will initialize the init script
in /lib/systemd/system

make install-groups-users
- This adds the users and groups if they do not exist

make install-commandmode
- This installs and configures permissions on the
directory for holding the external command file

make install-config
- This installs *SAMPLE* config files in /usr/local/nagios/etc
You'll have to modify these sample files before you can
use Nagios. Read the HTML documentation for more info
on doing this. Pay particular attention to the docs on
object configuration files, as they determine what/how
things get monitored!

make install-webconf
- This installs the Apache config file for the Nagios
web interface


make install-exfoliation
- This installs the Exfoliation theme for the Nagios

web interface

make install-classicui
- This installs the classic theme for the Nagios
web interface

Lệnh sau sẽ cài đặt các tập lệnh init cho Nagios.

[root@leoodz nagios-4.4.5 ]# make install-init

Để làm cho Nagios hoạt động từ dòng lệnh, chúng ta cần cài đặt chế độ lệnh.

[root@leoodz nagios-4.4.5 ]# make install-commandmode

Tiếp theo, cài đặt các tệp Nagios mẫu, vui lòng chạy lệnh sau.

[root@leoodz nagios-4.4.5 ]# make install-config

Kết quả:

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg
/usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg
/usr/local/nagios/etc/cgi.cfg


/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg
/usr/local/nagios/etc/resource.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg
/usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg
/usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg
/usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/templateobject/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg
/usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg
/usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg
/usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg
/usr/local/nagios/etc/objects/switch.cfg

*** Config files installed ***

Remember, these are *SAMPLE* config files. You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.

Bước 5: Tùy chỉnh cấu hình Nagios

Mở tệp “contact.cfg” và sửa phần email contact

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


Kết quả:


##############################################################################
#
##############################################################################
#
#
# CONTACTS
#
##############################################################################
#
##############################################################################
#

# Just one contact defined by default - the Nagios admin (that's you)
# This contact definition inherits a lot of default values from the 'generic-contact'
# template which is defined elsewhere.

define contact{
contact_name

nagiosadmin

use
generic-contact
template (defined above)
alias

email
ADDRESS ****


Nagios Admin

; Short name of user
; Inherit default values from generic-contact
; Full name of user

NHẬP EMAIL CỦA BẠN Ở ĐÂY

}

Bước 6: Cài đặt và cấu hình giao diện web cho Nagios

; *** CHANGE THIS TO YOUR EMAIL


Chúng ta đã hồn tất mọi cấu hình trong phần backend, bây giờ chúng ta sẽ cấu hình Web
Interface cho Nagios bằng lệnh sau. Lệnh dưới đây sẽ cài đặt cấu hình giao diện Web cho Nagios
và một người dùng quản trị web sẽ được tạo “nagiosadmin”.

[root@leoodz nagios-4.4.5 ]# make install-webconf

Trong bước này, chúng tôi sẽ tạo mật khẩu cho “nagiosadmin”. Sau khi thực hiện lệnh này, vui
lòng cung cấp mật khẩu hai lần và ghi nhớ mật khẩu này vì mật khẩu này sẽ được sử dụng khi
bạn đăng nhập vào giao diện Web Nagios.

[root@leoodz nagios-4.4.5]# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin


Khởi động lại Apache để cài đặt mới có hiệu lực.

[root@leoodz nagios-4.4.5]# systemctl start httpd.service

Bước 7: Biên dịch và cài đặt plugin Nagios

Chúng ta đã tải xuống các plugin Nagios trong / root / nagios, Hãy truy cập vào đó và cấu hình và
cài đặt nó theo hướng dẫn bên dưới.

[root@leoodz nagios-4.4.5]# cd /root/nagios
[root@leoodz nagios]# cd nagios-plugins-2.2.1/
[root@leoodz nagios-plugins-2.2.1]# ./configure --with-nagios-user=nagios --with-nagiosgroup=nagios
[root@leoodz nagios-plugins-2.2.1]# make
[root@leoodz nagios-plugins-2.2.1]# make install


Bước 8: Xác minh tệp cấu hình Nagios (kiểm tra ta đã làm chính xác hết chưa)

Bây giờ tất cả chúng ta đã hồn tất với cấu hình Nagios và đã đến lúc xác minh nó và để làm như
vậy, vui lịng nhập lệnh sau. Nếu mọi thứ sn sẻ, nó sẽ hiển thị tương tự như đầu ra bên dưới.

[root@leoodz nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Kết quả:

Nagios Core 4.4.5
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2019-08-20
License: GPL


Website:
Reading configuration data...
Read main config file okay...
Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
Checked 8 services.
Checked 1 hosts.
Checked 1 host groups.
Checked 0 service groups.


Checked 1 contacts.
Checked 1 contact groups.
Checked 24 commands.
Checked 5 time periods.
Checked 0 host escalations.
Checked 0 service escalations.
Checking for circular paths...
Checked 1 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...


Total Warnings: 0
Total Errors: 0

Things look okay - No serious problems were detected during the pre-flight check

Bước 9: Làm Nagios khởi động cùng CentOS

Để làm cho Nagios hoạt động khi khởi động lại, chúng ta cần thêm nagios và httpd bằng lệnh
chkconfig và systemctl.

CentOS 6

[root@leoodz ]# chkconfig --add nagios


[root@leoodz ]# chkconfig --level 35 nagios on
[root@leoodz ]# chkconfig --add httpd
[root@leoodz ]# chkconfig --level 35 httpd on

CentOS 7/8

[root@leoodz ]# systemctl enable nagios
[root@leoodz ]# systemctl enable httpd

Khởi động lại Nagios để cài đặt mới có hiệu lực.

[root@leoodz ]# service nagios start

[CentOS 6]


[root@leoodz ]# systemctl start nagios.service [CentOS 7/8]

Bước 10: Đăng nhập vào giao diện web Nagios

Nagios của bạn đã sẵn sàng hoạt động, vui lịng mở nó trong trình duyệt của bạn bằng “http: //
IP của bạn / nagios” hoặc “http: // FQDN / nagios” và cung cấp tên người dùng “nagiosadmin” và
mật khẩu.



×