配置Nagios監(jiān)控服務(wù)器(圖)
部署Nagios監(jiān)控服務(wù)器:
(一)下載所需軟件包
1.nagios.3.2.0.tar.gz Nagios的主程序
- [root@UnixHot src]# wget http://prdownloads.sourceforge.n ... nagios.3.2.0.tar.gz
2.nagios-plugins-1.4.13.tar.gz Nagios 的插件
- [root@UnixHot src]# wget http://prdownloads.sourceforge.n ... ugins-1.4.13.tar.gz
3.nrpe-2.12.tar.gz 代理檢測(cè)程序
- [root@UnixHot src]# wget http://prdownloads.sourceforge.n ... os/nrpe-2.12.tar.gz
- [root@UnixHot src]# ls
- nagios-3.2.0.tar.gz nagios-plugins-1.4.13.tar.gz nrpe-2.12.tar.gz
(二)安裝Nagios
官方的安裝文檔:http://nagios.sourceforge.net/docs/3_0/quickstart-fedora.html
1.安裝前的依賴檢查
- [root@UnixHot ~]# rpm -q httpd php gcc glibc glibc-common gd gd-devel
2.創(chuàng)建Nagios賬戶和組
- [root@UnixHot src]# useradd -m nagios
- [root@UnixHot src]#groupadd nagcmd
- [root@UnixHot src]# usermod -a -G nagcmd nagios
- [root@UnixHot src]#usermod -a -G nagcmd apache
3.編譯安裝
- [root@UnixHot src]# tar xvf nagios-3.2.0.tar.gz
- [root@UnixHot src]# cd nagios-3.2.0
至于每一步的具體意思,我不再詳述,因?yàn)檫\(yùn)行完畢后,提示信息會(huì)明確的告訴你,它干了什么,是怎么干的。當(dāng)然,還有一個(gè)***的辦法,就是看Makefile文件,里面都會(huì)有注釋的。
參考Makefile文件
- [root@UnixHot nagios-3.2.0]# less Makefile
- [root@UnixHot nagios-3.2.0]# ./configure --with-command-group=nagcmd \
- --with-nagios-user=nagios \
- --with-nagios-group=nagios
- [root@UnixHot nagios-3.2.0]# make all
- [root@UnixHot nagios-3.2.0]# make install
- [root@UnixHot nagios-3.2.0]# make install-init (生成init啟動(dòng)腳本)
- [root@UnixHot nagios-3.2.0]# make install-config (生成一些模板配置文件)
- [root@UnixHot nagios-3.2.0]# make install-commandmode (設(shè)置相應(yīng)的權(quán)限)
- [root@UnixHot nagios-3.2.0]# make install-webconf (生成Apache配置文件nagios.conf)
4.為Nagios設(shè)置Web驗(yàn)證的密碼
(注意***次添加用戶用-c選項(xiàng),以后再添加千萬別在用這個(gè)選項(xiàng)了,會(huì)覆蓋以前的所有用戶的,這個(gè)在RHCE考前沖刺我已經(jīng)講了。)
- [root@UnixHot nagios-3.2.0]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
5.設(shè)置Nagios的開機(jī)啟動(dòng)
- [root@UnixHot ~]# chkconfig --add nagios
- [root@UnixHot ~]# chkconfig nagios on
6.修改SELinux
兩種方法:
***種最直接,關(guān)閉SELinux,對(duì)于SELinux不是很熟悉的用戶,請(qǐng)選擇此。
- [root@UnixHot nagios-3.2.0]# cat /etc/sysconfig/selinux
- SELINUX=disabled
第二種給打上正確的安全脈絡(luò)。
- chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
- chcon -R -t httpd_sys_content_t /usr/local/nagios/share/
(三)安裝Nagios的插件nagios-plugin
插件是Nagios擴(kuò)展功能的強(qiáng)大武器,一般好的軟件,都支持插件擴(kuò)展,你可以根據(jù)實(shí)際的應(yīng)用,自己開發(fā)插件。
- [root@UnixHot src]# tar xvf nagios-plugins-1.4.13.tar.gz
- [root@UnixHot src]# cd nagios-plugins-1.4.13
- [root@UnixHot nagios-plugins-1.4.13]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
- [root@UnixHot nagios-plugins-1.4.13]# make && make install
(四)配置檢測(cè)主機(jī)是否存活
1.配置文件概述
如果安裝上面的步驟,安裝完成后,配置文件在安裝時(shí)放在了/usr/local/nagios/etc/目錄下
- [root@UnixHot ~]# cd /usr/local/nagios/etc
- [root@UnixHot etc]# ls -l
- -rw-rw-r-- 1 nagios nagios 11408 08-30 11:55 cgi.cfg (CGI配置文件)
- -rw-r--r-- 1 root root 26 08-30 11:56 htpasswd.users (Apache的驗(yàn)證密碼文件)
- -rw-rw-r-- 1 nagios nagios 43776 08-30 11:55 nagios.cfg (主配置文件)
- drwxrwxr-x 2 nagios nagios 4096 08-30 11:55 objects (對(duì)象定義文件目錄)
- -rw-rw---- 1 nagios nagios 1340 08-30 11:55 resource.cfg (資源配置文件)
我們修要修改的的是nagios.cfg 和 objects 目錄下的文件,來檢測(cè)主機(jī)是否存活。
2.主配置文件nagios.cfg的配置
主配置文件的內(nèi)容很多,對(duì)于這個(gè)版本,我們需要修改和添加的主要是對(duì)象配置文件,即:cfg_file=
- cfg_file=/usr/local/nagios/etc/objects/commands.cfg (命令定義文件)
- cfg_file=/usr/local/nagios/etc/objects/contacts.cfg (聯(lián)系人信息定義文件)
- cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg (添加此行聯(lián)系人組定義文件)
- cfg_file=/usr/local/nagios/etc/objects/hosts.cfg (添加此行 主機(jī)定義文件)
- cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg (添加此行 主機(jī)組定義文件)
- cfg_file=/usr/local/nagios/etc/objects/services.cfg (添加此行 服務(wù)定義文件)
- cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg (時(shí)間周期定義文件)
- cfg_file=/usr/local/nagios/etc/objects/templates.cfg
- # Definitions for monitoring the local (Linux) host
- #cfg_file=/usr/local/nagios/etc/objects/localhost.cfg (注釋掉此行)
3.主機(jī)定義文件的配置
- [root@UnixHot etc]# vi objects/hosts.cfg
- define host{
- host_name Nagios-Server
- alias Nagios Server
- address 192.168.0.206
- check_command check-host-alive
- check_interval 5
- retry_interval 1
- max_check_attempts 5
- check_period 24x7
- process_perf_data 0
- retain_nonstatus_information 0
- contact_groups sagroup
- notification_interval 30
- notification_period 24x7
- notification_options d,u,r
- }
- define host{
- host_name Java-Server
- alias Java Server
- address 192.168.0.157
- check_command check-host-alive
- check_interval 5
- retry_interval 1
- max_check_attempts 5
- check_period 24x7
- process_perf_data 0
- retain_nonstatus_information 0
- contact_groups sagroup
- notification_interval 30
- notification_period 24x7
- notification_options d,u,r
- }
- define host{
- host_name Oracle-Server
- alias Oracle Server
- address 192.168.0.155
- check_command check-host-alive
- check_interval 5
- retry_interval 1
- max_check_attempts 5
- check_period 24x7
- process_perf_data 0
- retain_nonstatus_information 0
- contact_groups sagroup
- notification_interval 30
- notification_period 24x7
- notification_options d,u,r
- }
- define host{
- host_name MySQL-Server
- alias MySQL Server
- address 192.168.0.100
- check_command check-host-alive
- check_interval 5
- retry_interval 1
- max_check_attempts 5
- check_period 24x7
- process_perf_data 0
- retain_nonstatus_information 0
- contact_groups sagroup
- notification_interval 30
- notification_period 24x7
- notification_options d,u,r
- }
4.主機(jī)組定義文件的配置
- [root@UnixHot etc]# vi objects/hostgroups.cfg
- define hostgroup {
- hostgroup_name System-Admin
- alias system Admin
- members Nagios-Server,Oracle-Server,Java-Server,MySQL-Server
- }
5.服務(wù)定義文件的配置
- [root@UnixHot etc]# vi objects/services.cfg
- define service {
- host_name Nagios-Server
- service_description check-host-alive
- check_period 24x7
- max_check_attempts 4
- normal_check_interval 3
- retry_check_interval 2
- contact_groups sagroup
- notification_interval 10
- notification_period 24x7
- notification_options w,u,c,r
- check_command check-host-alive
- }
- define service {
- host_name Oracle-Server
- service_description check-host-alive
- check_period 24x7
- max_check_attempts 4
- normal_check_interval 3
- retry_check_interval 2
- contact_groups sagroup
- notification_interval 10
- notification_period 24x7
- notification_options w,u,c,r
- check_command check-host-alive
- }
- define service {
- host_name Java-Server
- service_description check-host-alive
- check_period 24x7
- max_check_attempts 4
- normal_check_interval 3
- retry_check_interval 2
- contact_groups sagroup
- notification_interval 10
- notification_period 24x7
- notification_options w,u,c,r
- check_command check-host-alive
- }
- define service {
- host_name MySQL-Server
- service_description check-host-alive
- check_period 24x7
- max_check_attempts 4
- normal_check_interval 3
- retry_check_interval 2
- contact_groups sagroup
- notification_interval 10
- notification_period 24x7
- notification_options w,u,c,r
- check_command check-host-alive
- }
6.聯(lián)系組定義文件配置
- [root@UnixHot etc]# vi objects/contactgroups.cfg
- define contactgroup {
- contactgroup_name sagroup
- alias system administrator group
- members nagiosadmin
- }
7.修改目錄的所有者
- [root@UnixHot etc]# chown -R nagios:nagios objects/
8.檢測(cè)配置文件是否正確
- [root@UnixHot etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
- Total Warnings: 0
- Total Errors: 0
如果都是0說明配置成功了,如果有錯(cuò)誤,好好檢查一下。
9.啟動(dòng)Nagios服務(wù)
- [root@UnixHot etc]# /etc/init.d/httpd restart
- [root@UnixHot etc]# /etc/init.d/nagios start
(五)***部分功能測(cè)試
在瀏覽器輸入網(wǎng)址:http://192.168.0.206/nagios/

***部分的功能已經(jīng)實(shí)現(xiàn)了,就是簡單的監(jiān)控四臺(tái)服務(wù)器是否存活,當(dāng)然,對(duì)于系統(tǒng)監(jiān)控來說,這是遠(yuǎn)遠(yuǎn)不夠的。配置Nagios監(jiān)控服務(wù)器OK
【編輯推薦】