Nagios+PNP安裝部署
下載所需要的相關軟體包,本文使用的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 .......... }
外掛自定義結束
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31541436/viewspace-2158433/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Zabbix安裝部署
- canal安裝部署
- Doris安裝部署
- greenplum安裝部署
- SQLT 安裝部署SQL
- ZooKeeper 安裝部署
- Dubbo安裝部署
- Zookeeper安裝部署
- ELK安裝部署
- chromedriver安裝部署Chrome
- Centos7安裝安裝部署dockerCentOSDocker
- SQOOP安裝部署OOP
- Oozie--安裝部署
- Apache Ranger安裝部署ApacheRanger
- Hive 3.1.2安裝部署Hive
- Saltstack基本安裝部署
- RocketMQ安裝及部署MQ
- flume的安裝部署
- Linux安裝部署Linux
- Hive的安裝部署Hive
- Redis之安裝部署Redis
- cloudstack +xenserver 安裝部署CloudServer
- 安裝部署VMware VCenter
- 安裝go 1.5 & 部署Go
- Hadoop 安裝部署Hadoop
- openssl安裝與部署
- mysql proxy 安裝部署MySql
- Hive(八)安裝部署Hive
- docke安裝與部署
- Hadoop安裝部署Hadoop
- CDH - [02] 安裝部署
- DataX - [02] 安裝部署
- keepalived 安裝部署
- zookeeper安裝部署步驟
- ElasticSearch + Kibana 安裝部署Elasticsearch
- Tomcat 8安裝部署Tomcat
- 本地安裝部署禪道
- Hbase的安裝與部署