您好,登錄后才能下訂單哦!
Nagios是一款企業級開源免費的監控工具,其關注點在于保證服務的正常運行,并且在服務發生問題時提供報警機制。
Nagios服務端:10.20.2.233
Nagios監控端:web1(10.20.2.2.235) 、 web2(10.20.2.236)
1) 安裝nagios依賴軟件包
通過yum方式快速安裝Nagios所需的依賴軟件包
yum -y install gd gd-devel openssl openssl-devel httpd php gcc glibc glibc-common make net-snmp wget
2) 創建nagios賬戶與組
配置時使用--with-nagios-user和--with-nagios-group指定以該賬號的身份運行Nagios。
useradd nagios
3) ×××地址
Nagios:
http://superb-sea2.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.2.1/nagios-4.2.1.tar.gz
Nagios-plugin:
https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz
Nrpe:
http://pilotfiber.dl.sourceforge.net/project/nagios/nrpe-3.x/nrpe-3.0.1.tar.gz
4) Nagios的安裝
tar -zxf nagios-4.2.1.tar.gz -C /usr/local cd /usr/local cd nagios-4.2.1/ ./configure --with-nagios-user=nagios --with-nagios-group=nagios make all make install #安裝主程序,CGI以及HTML文件 make install-init #安裝啟動腳本/etc/init.d/nagios make install-commandmode #安裝與配置目錄權限 make install-config #安裝配置文件模板 # 由于nagios最終將以web的形式進行管理與監控,安裝過程中使用make install-webconf命令將生成Apache附加配置文件/etc/httpd/conf.d/nagios.conf make install-webconf
5) Nagios插件安裝
tar -zxf nagios-plugins-2.1.2.tar.gz -C /usr/local cd /usr/local/nagios-plugins-2.1.2/ ./configure --prefix=/usr/local/nagios make make install tar -zxf nrpe-3.0.1.tar.gz -C /usr/local/ cd /usr/local cd nrpe-3.0.1/ ./configure --prefix=/usr/local/nagios make all make install-plugin make install-daemon make install-daemon-config chown nagios:nagios -R /usr/local/nagios
6) 禁用selinux并關閉防火墻
setenforce 0 service iptables stop
7) 創建web訪問賬戶
htpasswd -c /usr/local/etc/htpasswd.users tomcat
8) 啟動nagios
/etc/init.d/httpd start /etc/init.d/nagios start
9) 修改nagios配置文件
主配置文件:nagios.cfg
主配置文件中使用cfg_file配置項加載其他配置文件,為了方便管理,將兩臺監控主機創建不同的配置文件,10.20.2.235配置文件名為web1.cfg,10.20.2.236配置文件名為web2.cfg
vi /usr/local/nagios/etc/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 # Definitions for monitoring the local (Linux) host cfg_file=/usr/local/nagios/etc/objects/localhost.cfg #下面兩個配置文件需要手動創建出來,用于監控兩臺web服務器 cfg_file=/usr/local/nagios/etc/web1.cfg cfg_file=/usr/local/nagios/etc/web2.cfg ……
修改CGI配置文件(cgi.cfg),需要將訪問web頁面的賬號加入進來
vi /usr/local/nagios/etc/cgi.cfg use_authentication=1 authorized_for_system_information=nagiosadmin,tomcat authorized_for_configuration_information=nagiosadmin,tomcat authorized_for_system_commands=nagiosadmin,tomcat authorized_for_all_services=nagiosadmin,tomcat authorized_for_all_hosts=nagiosadmin,tomcat authorized_for_all_service_commands=nagiosadmin,tomcat authorized_for_all_host_commands=nagiosadmin,tomcat ……
修改命令配置文件(commands.cfg),該文件定義具體的命令實現方式,如發送報警郵件具體使用什么工具、郵件內容格式定義。
vi /usr/local/nagios/etc/objects/commands.cfg …… define command{ command_name check-host-alive command_line $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5 } …… #以下內容需要手動添加,用于進行遠程主機監控,需要安裝nrpe軟件包 define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }
修改nrpe配置文件(nrpe.cfg),用于監控遠程主機所需要的命令
vi /usr/local/nagios/etc/nrpe.cfg 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_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1 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 #下面一行為手動添加 command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% ……
修改監控主機配置文件(localhost.cfg),該文件用于設置如何監控本機服務器資源。
vi /usr/local/nagios/etc/objects/localhost.cfg …… define host{ use linux-server ; Name of host template to use ; This host definition will inherit all variables that are defined ; in (or inherited by) the linux-server host template definition. host_name localhost alias localhost address 127.0.0.1 } …… define hostgroup{ hostgroup_name linux-servers ; The name of the hostgroup alias Linux Servers ; Long name of the group members localhost ; Comma separated list of hosts that belong to this group } ……
創建遠程監控配置文件web1.cfg與web2.cfg,用于監控遠程服務器系統資源與服務,可以使用localhost.cfg作為參考模板。下面列出web1.cfg的所有內容,web2.cfg 只需要參考web1.cfg的內容修改主機名稱、IP地址以及主機名稱即可。
define host{ use linux-server ; Name of host template to use ; This host definition will inherit all variables that are defined ; in (or inherited by) the linux-server host template definition. host_name web1 alias test.com address 10.20.2.235 } define hostgroup{ hostgroup_name webs ; The name of the hostgroup alias Linux Servers ; Long name of the group members web1 ; Comma separated list of hosts that belong to this group } define service{ use generic-service ; Name of service template to use host_name web1 service_description PING check_command check_ping!100.0,20%!500.0,60% notifications_enabled 1 } define service{ use generic-service ; Name of service template to use host_name web1 service_description Sys_Load check_command check_nrpe!check_load notifications_enabled 1 } define service{ use generic-service ; Name of service template to use host_name web1 service_description Current Users check_command check_nrpe!check_users notifications_enabled 1 } define service{ use generic-service ; Name of service template to use host_name web1 service_description Total Processes check_command check_nrpe!check_total_procs notifications_enabled 1 } define service{ use generic-service ; Name of service template to use host_name web1 service_description SSH check_command check_ssh notifications_enabled 1 } define service{ use generic-service ; Name of service template to use host_name web1 service_description HTTP check_command check_http notifications_enabled 1 }
10) 重新加載nagios配置
其他配置文件不需修改,可以直接使用,重啟nagios,重新加載所有的配置
/etc/init.d/nagios restart
下面以web1為例,web2與web1操作一致
1) yum安裝nagios插件需依賴的軟件包
yum -y install openssl openssl-devel
2) 創建nagios用戶和組
useradd -s /sbin/nologin nagios
3) 安裝Nagios-plugin
tar -zxf nagios-plugins-2.1.2.tar.gz -C /usr/local cd /usr/local/ cd nagios-plugins-2.1.2/ ./configure make make install
4) 安裝Nrpe
tar -zxf nrpe-3.0.1.tar.gz -C /usr/local cd /usr/local/nrpe-3.0.1/ ./configure make all make install-plugin make install-daemon make isntall-daemon-config chown -R nagios:nagios /usr/local/nagios
5) 修改nrpe配置文件
cp /usr/local/nrpe-3.0.1/sample-config/nrpe.cfg /usr/local/nagios/etc/ vi /usr/local/nagios/etc/nrpe.cfg …… allowed_hosts=127.0.0.1,10.20.2.233 …… 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_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1 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 #下面一行為手動添加 command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10%
6) 禁用selinux并關閉防火墻
setenforce 0 service iptables stop
7) 啟動nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
1) 驗證監控端的nrpe
管理員在Nagios服務端通過check_nrpe檢測被監控端相關的性能參數,單獨使用check_nrpe可以檢測被監控端的nrpe版本號
[root@test etc]# /usr/local/nagios/libexec/check_nrpe -H 10.20.2.235 NRPE v3.0.1 [root@test etc]# /usr/local/nagios/libexec/check_nrpe -H 10.20.2.236 NRPE v3.0.1 [root@test etc]# /usr/local/nagios/libexec/check_nrpe -H 10.20.2.237 connect to address 10.20.2.237 port 5666: Connection refused connect to host 10.20.2.237 port 5666: Connection refused
2) 訪問web頁面進行監控
以上信息已經能夠檢測到被監控端的nrpe,此時可以通過瀏覽器進行訪問:
http://10.20.2.233/nagios
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。