4、nagios服務端配置與啓動
1)、文件說明
nagios.cfg #nagios主配置文件
cgi.cfg #cgi配置文件
commands.cfg #命令配置文件
contacts.cfg #聯繫人配置文件
resource.cfg #定義插件路徑文件
templates.cfg、timeperiods.cfg 組,監控時間段等配置文件
linux.cfg #用戶自定義文件,監控linux主機,定義主機配置文件
windows.cfg #用戶自定義文件,監控windows主機,定義主機配置文件
l-services.cfg #用戶自定義文件,定義linux主機服務配置文件
w-services.cfg #用戶自定義文件,定義windows主機服務配置文件
2)、cgi.cfg文件配置
root@nagios#cd /usr/local/nagios/etc
vi cgi.cfg #如下是須要修改的地方
authorized_for_system_information=nagiosadmin,test
authorized_for_configuration_information=nagiosadmin,test
authorized_for_system_commands=nagiosadmin,test
authorized_for_all_services=nagiosadmin,test
authorized_for_all_hosts=nagiosadmin,test authorized_for_all_service_commands=nagiosadmin,test authorized_for_all_host_commands=nagiosadmin,test
use_authentication=0
#修改成0,否則監控訪問的時候會出現如下提示
It appears as though you do not have permission to view information for any of the hosts you requested...
If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI
and check the authorization options in your CGI configuration file.
3)、配置nagios.cfg文件
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
# wb config
cfg_dir=/usr/local/nagios/etc/linux
#配置linux主機加載自定義文件的目錄(下面包括linux.cfg、l-services.cfg文件)
cfg_dir=/usr/local/nagios/etc/windows #配置win主機加載自定義文件的 目錄(包括windows.cfg、w-services.cfg)
4)、配置commands.cfg命令配置文件
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
define command{
command_name check_mysql_health #定義mysql監控命令 command_line $USER1$/check_mysql_health --hostname $ARG1$ --port $ARG2$ --username $ARG3$ --password $ARG4$ --mode $ARG5$
}
define command{
command_name notify-service-by-sms #定義飛信監控命令 command_line /usr/local/tools/install/fetion --mobile=159230***** --pwd=2255*** --to=$CONTACTPAGER$ --msg-gb="$HOSTNAME$ $SERVICEDESC$ is $SERVICESTATE$ on $TIME$ result is $SERVICEOUTPUT$" $CONTACTPAGER$
}
notify-host-by-email、notify-service-by-email這二項是定義mail報警的命令,默認文件有這二項
5)、配置contacts.cfg聯繫人配置文件
define contact{
contact_name nagiosadmin
use generic-contact
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-email,notify-service-by-sms
host_notification_commands notify-host-by-email
email
[email]test@test.com[/email],[email]test@163.com[/email]
pager 1592304****
}
#email 定義聯繫人報警mail地址
#pager 定義聯繫人報警手機號碼
#notify-service-by-email、notify-service-by-sms、notify-host-by-email、要與commands.cfg命令配置文件裏的相對應
6)、linux.cfg主機配置文件
#====================linux server=====================
define host{
use generic-host
host_name cvs-1.11
alias cvs-server
address 192.168.1.11
check_command check-host-alive
max_check_attempts 10
check_period 24x7
notification_interval 20
notification_period 24x7
notification_options d,r
contact_groups admins
name cvs-1.11 #定義名字
}
define host{
use generic-host
host_name web-1.72
alias web-server
address 192.168.1.72
use cvs-1.11 #調用cvs-1.11的配置
}
7)、windows.cfg配置文件
##############windows host################
define host{
use generic-host
host_name windows-1.8
alias win-server
address 192.168.1.8
check_command check-host-alive
max_check_attempts 10
check_period 24x7
notification_interval 20
notification_period 24x7
notification_options d,r
contact_groups admins
name windows-1.8 #定義名字
}
define host{
use generic-host
host_name windows-1.71
alias web-server
address 192.168.1.71
use windows-1.8 #調用windows-1.8配置文件
}
8)、l-services.cfg定義服務配置文件
define service{
use generic-service
host_name cvs-1.11 #與l-linux.cfg主機服務的名字相對應
service_description HTTP status
is_volatile 0 #相似聲音警告功能關閉
check_period 24x7
#監控期限爲24X7
max_check_attempts 3
#最大檢測3次
normal_check_interval 1
#每一分鐘檢測一次
retry_check_interval 1 #間隔1分鐘檢測
contact_groups admins #監控組
notification_options w,u,c,r
# w,u,c,r 發生這四種狀況時,進行通告
notification_interval 5 # 通告間隔
notification_period 24x7 #檢測時間段
check_command check_http
}
check_command監控命令有
check-host-alive、check_nrpe!check_disk一、check_nrpe!check_load、check_nrpe!check_total_procs、check_nrpe!check_swap等
9)、w-services.cfg配置文件
define service{
use generic-service
host_name windows-1.8
service_description NSClient++ Version
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 1
retry_check_interval 1
contact_groups admins
notification_options w,u,c,r
notification_interval 5
notification_period 24x7
check_command check_nt!CLIENTVERSION
}
define service{
use generic-service
host_name windows-1.8
service_description E:\ Drive Space
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 1
retry_check_interval 1
contact_groups admins
notification_options w,u,c,r
notification_interval 5
notification_period 24x7
check_command
check_nt!USEDDISKSPACE!-l e -w 80 -c 90
}
# 若是要監控c 盤,check_nt!USEDDISKSPACE!-l c -w 80 -c 90
這裏的c表示是c盤
check_command命令有
check_nt!UPTIME、check_nt!MEMUSE!-w 80 -c 90、(-w 80 -c 90)爲當內存使用到80%爲warning警告,內存使用到90%爲critical緊急,check_nt!USEDDISKSPACE!-l c -w 80 -c 90、check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe等。
10)、linux 客戶端的安裝配置與啓動
tar zxvf nrpe-2.8.1.tar.gz
cd nrpe-2.8.1
./configure –prefix=/usr/local/nrpe
make
make install
10.1)、添加nagios用戶組,並設置權限
root@client#useradd nagios -s /sbin/nologin
chown -R nagios.nagios /usr/local/nrpe
10.2)、須要把nagios監控服務器裏的/usr/local/nagios/libexec下面的5個文件cp到 /usr/local/nrpe/libexec目錄下
cp /usr/local/nrpe/libexec/check_nrpe /usr/local/nagios/libexec
cp /usr/local/nagios/libexec/check_disk /usr/local/nrpe/libexec
cp /usr/local/nagios/libexec/check_load /usr/local/nrpe/libexec
cp /usr/local/nagios/libexec/check_ping /usr/local/nrpe/libexec
cp /usr/local/nagios/libexec/check_procs /usr/local/nrpe/libexec
10.3)、配置nrpe.cfg文件
mkdir /usr/local/nrpe/etc 建立目錄
複製nrpe解壓目錄下的nrpe.cfg文件以 /usr/local/nrpe/etc目錄下
cp /root/nrpe/nrpe.cfg /usr/local/nrpe/etc
修改nrpe.cfg文件
server_port=5666 #端口
server_address=192.168.1.56
#服務器IP
allowed_hosts=127.0.0.1,192.168.1.56 #充許nagios服務器IP訪問
10.4)啓動nrpe服務
10.4.1)、以獨立守護進程啓動nrpe服務
/usr/local/nrpe/bin/nrpe –c /usr/local/nrpe/etc/nrpe.cfg -d
10.4.2)、檢測nrpe服務是否正常啓動
[root@nagios nrpe]# netstat -nltp | grep nrpe
tcp 0 0 192.168.1.56:5666 0.0.0.0:* LISTEN 2233/nrpe
能查看到5666這端口,說明nrpe啓動正常
11)、配置windows主機的nrpe服務
修改c:\Program Files\NSClient++\NSC.ini文件
FileLogger.dll
CheckSystem.dll
CheckDisk.dll
NSClientListener.dll
NRPEListener.dll
SysTray.dll
CheckEventLog.dll
CheckHelpers.dll
CheckWMI.dll
#把前面的;分給去掉
allowed_hosts=127.0.0.1/32,192.168.1.56 #添加nagios監控服務器的IP,充許nagios服務器訪問
打開nsclient++ 服務,選擇屬性---登錄---本地系統帳戶---(選擇)充許服務與桌面交互,重啓nsclient++服務
net stop nsclient
net start nsclient
5、啓動nagios監控服務器
1)、檢查配置
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Checking misc settings...
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
2)、啓動nagios服務
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios restart #從新啓動nagios服務
-----------------------------------------------------------------------------------------------------------------------