TRƯỜNG CAO ĐẲNG CÔNG NGHỆ THỦ ĐỨC
KHOA CÔNG NGHỆ THÔNG TIN
BÁO CÁO LINUX 3
Cài đặt và cấu hình Nagios
Nhóm :
Mai Phạm Quang Hiếu
Phan Ngọc Duy
Nguyễn Hoàng Long
Nguyễn Ngọc Quang
Huỳnh Thanh Trung
Tp. HCM, Ngày 29 tháng 5 năm 2021
Mục Lục
Phần I: Sơ đồ thực hiện......................................................................................3
Phần II: Cài đặt và cấu hình Nagios.................................................................3
1. Cài đặt Nagios............................................................................................3
a. Nagios Server..........................................................................................3
b. Nagios Client...........................................................................................6
2. Cài đặt các dịch vụ....................................................................................9
a. Nagios Server:.........................................................................................9
b. Nagios Client:........................................................................................11
3. Cấu hình Nagios......................................................................................13
a. Khai báo file chứa thông tin của host:...............................................13
b. Khai báo lệnh NRPE:...........................................................................13
c. Thêm thông tin của host:.....................................................................14
d. Thêm thông tin của service:................................................................15
Phần III: Thử Nghiệm......................................................................................18
1. Truy cập vào Nagios................................................................................18
2. Quan sát hệ thống của client:.................................................................19
2
Phần I: Sơ đồ thực hiện
IP LAN
NAT
Dịch vụ
Nagios Server
192.168.10.1
Có
DNS:lab.vn
DNS
Nagios Client
192.168.10.2
Có
Web(nginx)
FTP
SSH
192.168.10.1
Win 7
192.168.10.3
Khơng
192.168.10.1
Phần II: Cài đặt và cấu hình Nagios
1. Cài đặt Nagios
a. Nagios Server
- Các bạn cài đặt các gói sau:
yum install httpd php php-cli gcc glibc glibc-common gd gd-devel
net-snmp openssl-devel unzip -y
- Tắt Selinux:
3
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g'
/etc/sysconfig/selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g'
/etc/selinux/config
- Tắt Firewall:
systemctl disable firewalld
systemctl stop firewalld
- Cập nhập phiên bản centos mới nhất:
yum update
- Tạo ra một user để tiến trình của nagios có thể chạy trên user này:
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache
- Dùng wget để download và cài đặt nagios:
(link này để
tra cứu phiên bản nagios)
curl -L -O
/>tar xvf nagios-4.4.6.tar.gz
cd nagios-4.4.6
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
4
make install-webconf
cd
*Bấm từng lệnh nha*
- Tạo ra một user để truy cập website nagios:
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
*Lưu ý bạn đang đặt mật khẩu cho nagiosadmin để đăng nhập vào
nagios*
- Tải và cài đặt nagios plugins:
(link này để tra
cứu phiên bản nagios plugins)
curl -L -O />tar xvf nagios-plugins-2.3.3.tar.gz
cd nagios-plugins-2.3.3
./configure --with-nagios-user=nagios --with-nagios-group=nagios
--with-openssl
make all
make install
cd
*Bấm từng lệnh nha*
- Bắt đầu dịch vụ nagios và httpd:
service httpd start
service nagios start
- Truy cập vào website vào đăng nhập với tài khoản mật khẩu
“nagiosadmin” đã tạo ở trên:
(IP máy nagios)/nagios
5
- Cài đặt NRPE:
(link check phiên bản
nrpe)
curl -L -O />tar xvf nrpe-4.0.3.tar.gz
cd nrpe-4.0.3
./configure
make check_nrpe
make install-plugin
cd
*Bấm từng lệnh nha*
b. Nagios Client
Cài đặt các gói cần thiết:
yum install -y gcc glibc glibc-common gd gd-devel make net-snmp
xinetd openssl-devel epel-release
- Cập nhập phiên bản centos mới nhất:
yum update
-
Tạo user để NRPE dùng nó để xử lý tiến trình:
useradd nagios
passwd nagios
-
Download file plugins:
curl -L -O />6
tar xvf nagios-plugins-2.3.3.tar.gz
cd nagios-plugins-2.3.3
./configure
make
make install
cd
*Bấm từng lệnh nha*
Sau đó thêm user vào group và cấp quyền sử dụng tập
lưu NRPE cho user nagios và group nagios:
usermod -a -G nagios nagios
chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec
-
Tải và cài đặt NRPE:
curl -L -O />tar xvf nrpe-4.0.3.tar.gz
cd nrpe-4.0.3
./configure
make all
make install
make install-plugin
make install-config
7
make install-init
make install-inetd
cd
*Bấm từng lệnh nha*
Sửa file /usr/local/nagios/etc/nrpe.cfg để có thể nghe thấy
nagios server:
vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,(địa chỉ IP của nagios server)
Sửa file /etc/services sử dụng port 5666 cho NRPE:
vi /etc/services
Thêm dòng dưới vào bất cứ chỗ nào trong file:
nrpe
5666/tcp
#NRPE
-
Chạy các dịch vụ:
service xinetd restart
systemctl start nrpe
systemctl enable nrpe
-
Chạy lệnh kiểm tra:
/usr/local/nagios/libexec/check_nrpe -H <địa chỉ IP máy Nagios
Client> (Máy Nagios Server)
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 (máy Nagios Client)
8
2. Cài đặt các dịch vụ
a. Nagios Server:
Cài đặt dịch vụ DNS:
yum install bind bind-utils –y
-
Cấu hình file vi /etc/named.conf:
Tiến hành tạo file thuận nghịch:
vi /var/named/fw.vn
9
vi /var/named/rv.vn
-
Chạy từng dòng lệnh theo thứ tự :
chgrp named -R /var/named
chown -v root:named /etc/named.conf
restorecon -rv /var/named
restorecon /etc/named.conf
10
-
Khởi động dịch vụ DNS:
systemctl enable named
systemctl start named
*Sau khi các bạn cài đặt thành cơng thì nhớ tắt card NAT nha*
b. Nagios Client:
Cài đặt Web Server (Nginx)
Các bạn tham khảo link này để cài nha, tại vì phần này đã làm trong
lớp rồi.
/>-
Cài đặt FTP Server:
yum install vsftpd –y
Cấu hình vsftpd :
Edit file cấu hình vsftpd tại thư mục /etc/vsftpd/vsftpd.conf :
vi /etc/vsftpd/vsftpd.conf
## Disable anonymous login ##
anonymous_enable=NO
## Bỏ comment những dòng này##
ascii_upload_enable=YES
11
ascii_download_enable=YES
## Bỏ comment – Nhập vào Welcome message – Chỉ là option##
ftpd_banner=Welcome to Lab Linux 3.
## Thêm dòng này vào cuối file ##
use_localtime=YES
Khởi chạy service và set cho nó tự động chạy bằng dòng lệnh :
sudo systemctl start vsftpd
sudo systemctl enable vsftpd
-
Dịch vu SSH:
Khởi chạy service SSH vì do đã cài ở trên rồi:
systemctl start sshd.service
3. Cấu hình Nagios
a. Khai báo file chứa thông tin của host:
- Thêm vào file /usr/local/nagios/etc/nagios.cfg
vi /usr/local/nagios/etc/nagios.cfg
Thêm vào 2 dòng dưới này vào file:
cfg_file=/usr/local/nagios/etc/hosts.cfg
cfg_file=/usr/local/nagios/etc/services.cfg
12
b. Khai báo lệnh NRPE:
vi /usr/local/nagios/etc/objects/commands.cfg
-
Khai báo vào cuối file dòng này:
###########################################################
####################
# NRPE CHECK COMMAND
#
# Command to use NRPE to check remote host systems
###########################################################
####################
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c
$ARG1$
}
13
c. Thêm thông tin của host:
- Vào file /usr/local/nagios/etc/hosts.cfg
vi /usr/local/nagios/etc/hosts.cfg
- Copy vào file những dòng này:
define host{
name
use
linux-box
generic-host
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
register
admins
0
14
}
define host{
use
host_name
alias
address
linux-box
client
CentOS 7
192.168.10.2
}
d. Thêm thông tin của service:
- Vào file /usr/local/nagios/etc/services.cfg
vi /usr/local/nagios/etc/services.cfg
- Copy vào file những dòng này:
define service{
name
service-test
use
generic-service
check_period
24x7
check_interval
3
retry_interval
1
max_check_attempts
3
notifications_enabled
1
contact_groups
admins
active_checks_enabled
1
passive_checks_enabled
1
register
0
notification_interval
5
notification_options
r,c,w
}
define service{
use
service-test
host_name
client
service_description CPU Load1
check_command
check_nrpe!check_load
15
}
define service{
use
generic-service
host_name
client
service_description disk load1
check_command
check_nrpe!check_sda1
contact_groups
admins
}
define service{
use
generic-service
host_name
client
service_description HTTP
check_command
check_http
notifications_enabled
0
}
define service{
use
generic-service
host_name
client
service_description FTP
check_command
check_ftp
notifications_enabled
0
}
define service{
use
generic-service
host_name
client
service_description SSH
check_command
check_ssh
notifications_enabled
0
}
Vào file này sửa cấu hình tại máy Nagios Client
vi /usr/local/nagios/etc/nrpe.cfg
Thêm vào /dev/sda1
16
Bỏ hết # mấy dòng này
-
Dùng lệnh để kiểm tra file cấu hình của bạn:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
-
Chạy lệnh để cài đặt thời gian:
timedatectl set-timezone Asia/Ho_Chi_Minh
timedatectl
Phần III: Thử Nghiệm
1. Truy cập vào Nagios
17
2. Quan sát hệ thống của client:
18
19