您好,登錄后才能下訂單哦!
下載所需要的相關軟件包,本文使用的nagios版本是3.4.3,nagios-plugins版本是2.2.1,nrpe版本是2.15。配置好yum源后即可開始下面的安裝。
一、安裝相關軟件包
#yum -y install gd fontconfig-devel libjpeg-devel libpng-devel gd-devel perl-GD openssl-devel php mailx postfix cpp gcc* libstdc++ glib2-devel libtoul-ltdl-devel httpd php*
二、創建nagios用戶和組
#groupadd -g 6000 nagios #groupadd -g 6001 nagcmd #useradd -u 6000 -g nagios -G nagcmd nagios
三、編譯安裝nagios
#tar zxvf nagios-3.4.3.tar.gz #cd nagios #./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-user=nagios --with-command-group=nagcmd --enable-event-broker --enable-nanosleep --enable-embedded-perl --with-perlcache #make all #make install #make install-init #make install-commandmode #make install-webconf #make install-config
四、配置apache
1.配置apache
在配置文件/etc/httpd/conf/httpd.conf中找到
DirectoryIndex index.html index.html.var
將其修改為:
DirectoryIndex index.html index.php
再在apache配置文件下增加如下內容:
AddType application/x-httpd-php .php
2.設置用戶訪問控制
#htpasswd -cm /usr/local/nagios/etc/htpasswd.users nagiosadmin
五、權限設定與啟動服務
#chown nagios:nagcmd /usr/local/nagios/etc/htpasswd.users #usermod -a -G nagios,nagcmd apache #service httpd restart
六、Nagios插件安裝
#tar zxvf nagios-plugins-2.2.1.tar.gz #cd nagios-plugins-2.2.1 #./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios #make all #make install #chmod 755 /usr/local/nagios #chkconfig httpd on;chkconfig nagios on #/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
七、禁用selinux和iptables
#setenforce 0 #service iptables status
八、安裝rrdtool工具
#yum -y install cairo-devel libxml2-devel pango-devel pango libpng-devel freetype freetype-devel libart_lgpl-devel zlib* cgilib* #tar zxvf rrdtool-1.4.5.tar.gz #cd rrdtool-1.4.5 #./configure --prefix=/usr/local/rrdtool #make && make install #/usr/local/rrdtool/bin/rrdtool -v
九、安裝PNP
1.安裝PNP
#tar zxvf pnp4nagios-0.6.14.tar.gz #cd pnp4nagios-0.6.14 #./configure --prefix=/usr/local/pnpnagios --with-nagios-user=nagios --with-nagios-group=nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool #make all #make install #make install-webconf #make install-config #make install-init
2.配置PNP
1)修改/usr/local/pnpnagios/etc下的配置文件
#cp misccommands.cfg-sample misccommands.cfg #cp nagios.cfg-sample nagios.cfg #cp rra.cfg-sample rra.cfg
2)修改/usr/local/pnpnagios/etc/pages下的配置文件
#cd /usr/local/pnpnagios/etc/pages #cp web_traffic.cfg-sample web_traffic.cfg
3)修改/usr /local/pnpnagios/etc/check_commands下的配置文件
#cd /etc/local/pnpnagios/etc/check_commands #cp check_all_local_disks.cfg-sample check_all_local_disks.cfg #cp check_nrpe.cfg-sample check_nrpe.cfg #cp check_nwstat.cfg-sample check_nwstat.cfg
然后service npcd start如果正確啟動說明安裝成功
3.nagios的配置
修改/usr/local/nagios/etc/objects/commands.cfg配置文件,修改如下:
修改/usr/local/nagios/etc/objects/templates.cfg,修改如下:
若需要開啟日志調試功能,則修改/usr/local/pnpnagios/etc/process_perfdata.cfg配置文件
LOG_LEVEL = 0
將數字變更為2。這就開啟了日志的調試功能
增加nagios數據輸出設置,修改nagios主配置文件/usr/local/nagios/etc/nagios.cfg:
.................... process_performance_data=1 host_perdata_command=process-host-perfdata service_perfdata_command=process-service-perfdata ....................
修改/usr/local/nagios/etc/objects/localhost.cfg配置文件,修改如下:
.................... define host{ ................ use linux-server,hosts-pnp ................ } .................... define service{ use local-service,services-pnp host_name localhost service_description PING check_command check_ping!100.0,20%!500.0,60% } ....................
十、驗證性能分析圖標功能
重啟ncpd,nagios,httpd服務,在瀏覽器輸入http://192.168.111.105/nagios/。出現登錄界面,用戶名:nagiosadmin;密碼:nagiosadmin。出現如下界面:
點擊拆線小圖標,出現如下界面:
監控遠程主機,需要在被監控主機(192.168.111.114)上安裝nrpe,安裝過程如下:
#tar zxvf nrpe-2.15.tar.gz #cd nrpe-2.15 #./configure --prefix=/usr/local/nagios --enable-command-args #make all #make install-plugin #make install-daemon #make install-daemon-config #make install-xinetd
修改/etc/hosts配置文件,在文件內容最后加入以下兩行:
nrpe 5666/tcp nrpe 5666/udp
修改/etc/xinetd.d/nrpe配置文件,原內容如下:
修改only_from后面的IP,改為監控主機的地址:
only_from = 192.168.111.105
啟動xinetd服務,查看5666端口是否處于監聽狀態:
#netstat -anp|grep 5666
將被監控主機上的check_nrpe腳本傳到監控主機上:
#scp /usr/local/nagios/libexec/check_nrpe root@192.168.111.105:/usr/local/nagios/libexec
監控主機操作如下:
#/usr/local/nagios/libexec/check_nrpe -H 192.168.111.114(測試被監控主機nrpe是否正常工作)
修改commands.cfg文件,增加如下內容:
定義新的被監控主機,修改localhost.cfg文件,增加如下內容:
檢查nagios主配置文件是否配置正確,無問題后重啟nagios服務:
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #service nagios restart
十一、擴展(自定義插件,如mysql)
1.在被監控主機安裝mysql-server
#yum -y install mysql-server #service mysqld restart
2.在被監控主機建立一個可遠程連接的用戶
mysql>create user 'nagios'@192.168.111.114 identified by '123'; mysql>flush privileges;
3.監控主機安裝mysql客戶端程序
#yum -y install mysql
4.編寫插件check_mysql
#!/bin/bash mysql_user=nagios mysql_password=123 mysql_host=192.168.111.114 if mysql -h $mysql_host -u $mysql_user -p$mysql_password -e "show databases" &>/dev/null then echo "mysql:OK" exit 0 else echo "mysql:DOWN" exit 2 fi
5.修改腳本權限
chmod 755 check_mysql
6.修改/usr/local/nagios/etc/objects/command.cfg
define command{ command_name check_mysql command_line $USER1$/check_mysql }
7.修改/usr/local/nagios/etc/objects/localhost.cfg
define service{ .......... service_description mysql .......... check_command check_mysql .......... }
插件自定義結束
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。