Nagios是一款企業(yè)級開源免費的監(jiān)控工具,其關(guān)注點在于保證服務(wù)的正常運行,并且在服務(wù)發(fā)生問題時提供報警機制。
成都創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供昌吉網(wǎng)站建設(shè)、昌吉做網(wǎng)站、昌吉網(wǎng)站設(shè)計、昌吉網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、昌吉企業(yè)網(wǎng)站模板建站服務(wù),十載昌吉做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
Nagios服務(wù)端:10.20.2.233
Nagios監(jiān)控端: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) 創(chuàng)建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 #安裝與配置目錄權(quán)限 make install-config #安裝配置文件模板 # 由于nagios最終將以web的形式進行管理與監(jiān)控,安裝過程中使用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并關(guān)閉防火墻
setenforce 0 service iptables stop
7) 創(chuàng)建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配置項加載其他配置文件,為了方便管理,將兩臺監(jiān)控主機創(chuàng)建不同的配置文件,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 #下面兩個配置文件需要手動創(chuàng)建出來,用于監(jiān)控兩臺web服務(wù)器 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),該文件定義具體的命令實現(xiàn)方式,如發(fā)送報警郵件具體使用什么工具、郵件內(nèi)容格式定義。
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 } …… #以下內(nèi)容需要手動添加,用于進行遠程主機監(jiān)控,需要安裝nrpe軟件包 define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }
修改nrpe配置文件(nrpe.cfg),用于監(jiān)控遠程主機所需要的命令
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% ……
修改監(jiān)控主機配置文件(localhost.cfg),該文件用于設(shè)置如何監(jiān)控本機服務(wù)器資源。
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 } ……
創(chuàng)建遠程監(jiān)控配置文件web1.cfg與web2.cfg,用于監(jiān)控遠程服務(wù)器系統(tǒng)資源與服務(wù),可以使用localhost.cfg作為參考模板。下面列出web1.cfg的所有內(nèi)容,web2.cfg 只需要參考web1.cfg的內(nèi)容修改主機名稱、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) 創(chuàng)建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并關(guān)閉防火墻
setenforce 0 service iptables stop
7) 啟動nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
1) 驗證監(jiān)控端的nrpe
管理員在Nagios服務(wù)端通過check_nrpe檢測被監(jiān)控端相關(guān)的性能參數(shù),單獨使用check_nrpe可以檢測被監(jiān)控端的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頁面進行監(jiān)控
以上信息已經(jīng)能夠檢測到被監(jiān)控端的nrpe,此時可以通過瀏覽器進行訪問:
http://10.20.2.233/nagios
標題名稱:Nagios監(jiān)控系統(tǒng)安裝和配置
地址分享:http://bm7419.com/article4/pscoie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、App開發(fā)、商城網(wǎng)站、全網(wǎng)營銷推廣、品牌網(wǎng)站建設(shè)、App設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)