Cài đặt và giám sát các dịch vụ trên Centos bằng Negios
1. Install Nagios on Centos 5
By Fabio Milano
Installing Nagios server and network monitoring on Centos 5 server
The official documentation can be found at
http://support.nagios.com/knowledge-...-documentation
Install necessary packages
|
Mã:
|
yum install httpd gcc glibc glibc-common gd gd-devel php |
Create Nagios User account and group
Create
nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user
|
Mã:
|
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache |
Create Directory to store Nagios installation files
Download Nagios and Plugins
Save file to directory /opt/Nagios
http://www.nagios.org/download/download.php
As of this writing Nagios 3.0.6 (Stable) and Nagios Plugins 1.4.13 (Stable)
Extract Files:
|
Mã:
|
cd /opt/Nagios
tar xzf nagios-3.0.6.tar.gz
cd nagios-3.0.6 |
Compile and Configure Nagios
|
Mã:
|
./configure --with-command-group=nagcmd |
Compile Nagios:
Compile binaries, init script, sample config files:
|
Mã:
|
make install
make install-init
make install-config
make install-commandmode |
** Do Not Start Nagios **
Nagios has now been installed to the directory
/usr/local/nagios/
Install Nagios Web Interface:
Nagios Web Interface installed to /usr/local/nagios/share ( http conf file added to /etc/httpd/conf.d/nagios.conf )
Create Web Interface Login User:
** This is not the most secure method **
We will create user “nagiosadmin” ( remember the password you assign !)
|
Mã:
|
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Restart Apache:
service httpd restart |
Install Nagios Plugins
Extract Files:
|
Mã:
|
cd /opt/Nagios
tar xzf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins1.4.13 |
Compile and Configure Nagios Plugins
|
Mã:
|
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install |
Configure nagiosadmin email address for alerts
|
Mã:
|
vi /usr/local/nagios/etc/objects/contacts.cfg
email nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** |
Verify the sample Nagios configuration files
|
Mã:
|
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors: 0 |
Start Nagios
|
Mã:
|
Enable Nagios to start at system startup / boot
chkconfig --add nagios
chkconfig nagios on
chkconfig httpd on Start Nagios
service nagios start |
Log into Web Interface
|
Mã:
|
http://ip-address/nagios/ |
2. Nagios NRPE add Services to Monitor
Scenario / Question:
I followed the Tutorial on installing and configuring NRPE, but now I want to monitor more services on the remote server.
Solution / Answer:
You can add services by configuring nrpe.cfg on the remote host and adding a new service definition on the Nagios monitoring server.
Download Service Plugin on Remote Host Server
1. Download the plugin to folder /usr/local/nagios/libexec/
2. Change permissions on plugin to nagios
|
Mã:
|
# cd /usr/local/nagios/libexec/
# chown nagios.nagios check_something
# chmod 775 check_something 3. Test the plugin works
# /usr/local/nagios/libexec/check_something |
Edit nrpe.cfg File on Remote Host Server
Add a new command definition to the nrpe.cfg file on the remote host
|
Mã:
|
# vi /usr/local/nagios/etc/nrpe.cfg |
Add a new check_something command definition. (replace “check_something” with the actual plugin file name). Also you must define any arguments. Do a “check_something -h” for a plugins arguments.
|
Mã:
|
command[check_something]=/usr/local/nagios/libexec/check_something -t 20 -c 30 |
Because we are running xinetd we do not need to restart the NRPE daemon. Otherwise you would have to restart the NRPE daemon for the changes to take effect.
Add Service Definition to Nagios Monitoring Server
On the monitoring host, you need to define a new service for check_something on the remote host. Add
the following entry to one of your object configuration files (linux-server-remote.cfg)
define service{
use generic-service
host_name remotehost
service_description Check Something
check_command check_nrpe!check_something
}
Next, verify your Nagios configuration files and restart Nagios.
|
Mã:
|
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# service nagios restart |
Bonus 1: Tôi muốn cài đặt 1 server Nagios để giám xác các dịch vụ (HTTP, SSH, SMTP, POP3,IMAP...Server Windows or Linux từ xa) thì tôi làm như sau:
1. Trên Server cần giám xác(Do nothing)
2. Trên Server Nagios tôi cài đặt Nagios, Nagios_Pluins, NRPE (3 thành phần này phải được cài trên server Nagios)
3. Và làm theo hướng dẫn theo tài liệu của Nagios
Bonus 2: Tôi muốn cài đặt 1 server Nagios để giám xác (RAM, CPU load, HDD trên ....Server Windows or Linux từ xa) thì tôi làm như sau:
Bài viết được tổng hợp từ nhiều nguồn: nagios, kernalhardware.
Các links liên quan:
http://www.kernelhardware.org/nagios...es-to-monitor/
Chúc các bạn thành công
