您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關linux中Nagios怎么安裝,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
一、Nagios服務端安裝
1、安裝所需依賴關系包
2、添加Nagios所需用戶及組
3、編譯安裝Nagios及創建登陸Nagios WEB程序用戶
4、Nagios-plugin(插件)
5、配置服務自啟動
二、基于NRPE配置Nagios監控Win主機
1、被監控端
安裝:NSClient++-0.3.9-x64
2、監控端
1.測試與被監控端連通性
2.監控端定義命令、定義主機、定義服務
3.將定義好的模板加入到nagios.cfg文件中
4.重啟服務
三、基于NRPE監控Linux主機
1、被監控端:
1.添加用戶
2.安裝插件nagios-plugins-1.4.15
3.安裝NRPE
4.配置NRPE配置文件
#vi /usr/local/nagios/etc/nrpe.cfg
5.定義nrpe啟動腳本且增加權限
6.添加自啟動
7.啟動服務
2、配置監控端:
1.安裝NRPE
安裝完成后,生成check_nrpe,使用此插件進行測試被監控主機
2.定義命令
3.定義主機和服務
4.將定義好的linhost.cfg配置文件的路徑添加至/usr/localhost/etc/nagios.cfg中
5.測試配置文件 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
6.重啟服務
7.網頁檢查hosts監控狀況
******另關于基于NRPE監控windows主機,另行查詢網上資料******
一、安裝配置Nagios
1、解決安裝Nagios的依賴關系:
# yum -y install httpd gcc glibc glibc-common gd gd-devel php php-mysql mysql mysql-devel mysql-server
2、添加nagios運行所需要的用戶和組:
# groupadd nagcmd
# useradd -G nagcmd nagios
# passwd nagios
# usermod -a -G nagcmd apache
3、編譯安裝nagios:
# tar zxf nagios-3.3.1.tar.gz
# cd nagios-3.3.1
# ./configure --with-command-group=nagcmd --enable-event-broker
# make all
# make install
# make install-init
# make install-commandmode
# make install-config
# vi /usr/local/nagios/etc/objects/contacts.cfg
emailnagios@localhost #這個是默認設置
# make install-webconf
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
# service httpd restart
4、編譯、安裝nagios-plugins
# tar zxf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make install
5、配置并啟動Nagios
#vi /usr/local/nagios/etc/nagios.cfg
# chkconfig --add nagios
# chkconfig nagios on
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# service nagios start
6、配置selinux
#getenforce
#setenforce 0
7、通過web界面查看nagios:
http://your_nagios_IP/nagios
登錄時需要指定前面設定的web認證帳號和密碼。
二、配置文件
Nagios的主配置文件
/usr/local/nagios/etc/nagios.cfg
Nagios模板配置目錄
/usr/local/nagios/etc/objects
調用check命令目錄/usr/local/nagios/libexec
三、基于NSClinet++ 監控遠程Win主機
1、安裝配置被監控端
安裝NSClient++-0.3.9-x64
2、進行測試是否連通
#cd /usr/local/nagios/libexec
#./check_nt -H 192.168.1.119 -v UPTIME -p 12489
如有密碼則:#./check_nt -H 192.168.1.119 -v UPTIME -p 12489 -s luoxj,123
3、監控端進行配置
&&&定義commands.cfg-------------------定義命令
#cd /usr/local/nagios/etc/objects/
#vi commands.cfg
define command{
command_name check_nt
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
}
&&&定義主機及服務
#vi windows.cfg
define host{
use windows-server
host_name winhost
alias My Windows Host
address 192.168.1.119
}
define service{ use generic-service host_name winhost service_description NSClient++ Version check_command check_nt!CLIENTVERSION }定義服務可根據實際情況進行變更名稱可使用vim中替換進行:.,$s@winserver@winhost@g
&&&啟用定義的文件,增加定義文件路徑
#vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/windows.cfg
&&&進行測試,以確定配置文件沒有問題
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg -d
#service nagios restart
四、基于NRPE監控遠程Linux主機
1、安裝配置被監控端
1)先添加nagios用戶
# useradd -s /sbin/nologin nagios
2)NRPE依賴于nagios-plugins,因此,需要先安裝之
# tar zxf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make all
# make instal
3)安裝NRPE
# tar -zxvf nrpe-2.12.tar.gz
# cd nrpe-2.12.tar.gz
# ./configure --with-nrpe-user=nagios \
--with-nrpe-group=nagios \
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--enable-command-args \
--enable-ssl
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
4)配置NRPE
# vim /usr/local/nagios/etc/nrpe.conf
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_address=172.16.100.11
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=172.16.100.1
command_timeout=60
connection_timeout=300
debug=0
&&&&&&&&定義監控對象命令&&&&&&&&&
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
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
5)啟動NRPE
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
為了便于NRPE服務的啟動,可以將如下內容定義為/etc/init.d/nrped腳本:
#vi /etc/init.d/nrped
#!/bin/bash
# chkconfig: 2345 88 12
# description: NRPE DAEMON
NRPE=/usr/local/nagios/bin/nrpe
NRPECONF=/usr/local/nagios/etc/nrpe.cfg
case "$1" in
start)
echo -n "Starting NRPE daemon..."
$NRPE -c $NRPECONF -d
echo " done."
;;
stop)
echo -n "Stopping NRPE daemon..."
pkill -u nagios nrpe
echo " done."
;;
restart)
$0 stop
sleep 2
$0 start
;;
*)
echo "Usage: $0 start|stop|restart"
;;
esac
exit 0
#chmod +x /etc/init.d/nrped
#service nrped start
#netstat -tnlp ##檢查nrpe端口5666是否啟用
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 17282/nrpe
#service iptables stop
#setenforce 0
6)配置允許遠程主機監控的對象
在被監控端,可以通過NRPE監控的服務或資源需要通過nrpe.conf文件使用命令進行定義,定義命令的語法格式為:command[<command_name>]=<command_to_execute>。比如:
command[check_rootdisk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
command[check_swap]=/usr/local/nagios/libexec/check_disk -w 40% -c 20%
command[check_sensors]=/usr/local/nagios/libexec/check_sensors
command[check_users]=/usr/local/nagios/libexec/check_users -w 10 -c 20
command[check_load]=/usr/local/nagios/libexec/check_load -w 10,8,5 -c 20,18,15
command[check_zombies]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_all_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
2、配置監控端
1)安裝NRPE
# tar -zxvf nrpe-2.12.tar.gz
# cd nrpe-2.12.tar.gz
# ./configure --with-nrpe-user=nagios \
--with-nrpe-group=nagios \
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--enable-command-args \
--enable-ssl
# make all
# make install-plugin
安裝完成后,/usr/local/nagios/libexec/check_nrpe就會生成此插件,可測試客戶端工作正常于否
#cd /usr/local/nagios/libexec/
#./check_nrpe -H 192.168.1.124
NRPE v2.12
2)定義如何監控遠程主機及服務:
通過NRPE監控遠程Linux主機要使用chech_nrpe插件進行,其語法格式如下:
check_nrpe -H <host> [-n] [-u] [-p <port>] [-t <timeout>] [-c <command>] [-a <arglist...>]
定義監控遠程Linux主機的命令:
#vi /usr/local/nagios/etc/objects/commands.cfg 添加nrpe命令
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
************建立模板文件******************
#cd /usr/local/nagios/etc/objects/
#vim linhost.cfg 或是 #cp localhost.cfg linhost.cfg
***定義遠程Linux主機:
define host{
use linux-server
host_name linhost
alias my Linux Host
address 192.168.1.124
}
如主機組不需要則注釋,添加服務可參照被監控端/usr/local/nagios/etc/nrpe.cfg中的command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Zcommand[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200 進行詳細配置服務 ***定義遠程Linux服務:也可以在后加參數進行設定監控
define service{
use generic-service host_name linhost service_description check_users check_command check_nrpe!check_users }# Create a service for monitoring the uptime of the server
# Change the host_name to match the name of the host you defined abovedefine service{ use generic-service host_name linhost service_description load check_command check_nrpe!check_load }# Create a service for monitoring CPU load
# Change the host_name to match the name of the host you defined abovedefine service{ use generic-service host_name linhost service_description sda1 check_command check_nrpe!check_sda1 }# Create a service for monitoring memory usage
# Change the host_name to match the name of the host you defined abovedefine service{ use generic-service host_name linhost service_description Zombie check_command check_nrpe!check_zombie_procs }define service{ use generic-service host_name linhost service_description Total procs check_command check_nrpe!check_total_procs }3)將設定好的linhost.cfg文件添加至/usr/local/nagios/etc/nagios.cfg中#vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/linhost.cfg
4)進行測試配置文件 # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg5)重啟服務#service nagios restart
關于“linux中Nagios怎么安裝”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。