Nagios監控安裝之二

來源:互聯網
上載者:User

標籤:Linux   Nagios   

監控80連接埠 3306連接埠 passwd檔案變化
實驗說明 :環境就是一台主機Linux CentOS release 6.5 (Final) 192.168.0.22 開啟httpd 80連接埠 3306連接埠
一,開始安裝前準備:
1,安裝nagios服務端軟體
a,nagios-3.5.1.tar.gz
b,nagios-plugins-1.4.16.tar.gz
c,nrpe-2.12.tar.gz
2,配置環境變數:
[[email protected] ]# echo ‘export LC_ALL=C‘>>/etc/profile
[[email protected] ]# tail -1 /etc/profile
export LC_ALL=C
[[email protected] ]# source /etc/profile
3,關閉防火牆和selinux
[[email protected] ]# /etc/init.d/iptables stop
[[email protected] ]# /etc/init.d/iptables status
iptables: Firewall is not running.
[[email protected] ]# chkconfig iptables off
[[email protected] ]# chkconfig --list iptables
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[[email protected]]#sed –i ‘s/SELINUX=enforce/SELINUX=disabled/g’ /etc/sysconfig/selinux
4,解決系統時間同步問題
[[email protected] ~]# yum -y install ntpdate
[[email protected] ~]# crontab -e
#time sync by tony at 2018-01-29
/5 * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1
二、正式安裝Ngios
需要一個LAMP環境
[[email protected] ~]# yum -y install gcc glibc glibc-common
[[email protected] ~]# yum -y install gd gd-devel
[[email protected] ~]# yum -y install mysql-server
[[email protected] ~]# yum -y install httpd php php-gd
建立Nagios伺服器端需要的使用者及組
[[email protected] ~]# /usr/sbin/useradd nagios
[[email protected] ~]# /usr/sbin/useradd apache -M -s /sbin/nologin
[[email protected] ~]# /usr/sbin/groupadd nagcmd
[[email protected] ~]# /usr/sbin/usermod -a -G nagcmd nagios
[[email protected] ~]# /usr/sbin/usermod -a -G nagcmd apache
檢查使用者建立是否成功
[[email protected] ~]# id -n -G nagios
[[email protected] ~]# id -n -G apache
[[email protected] ~]# groups nagios
[[email protected] ~]# groups apache
啟動服務查看通訊連接埠
[[email protected] ~]# /etc/init.d/httpd start
[[email protected] ~]# lsof -i:80
[[email protected] ~]# /etc/init.d/mysqld start
[[email protected] ~]# lsof -i:3306
配置hosts檔案解析 :
[[email protected] ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.22 Nagios-Server
三、安裝Nagios-Server服務端
[[email protected] ~]# cd /soft/nagios
[[email protected] nagios]# tar xf nagios-3.5.1.tar.gz
[[email protected] nagios]# cd nagios
[[email protected] nagios]# ./configure --with-command-group=nagcmd
[[email protected] nagios]# make all
[[email protected] nagios]# make install
[[email protected] nagios]# make install-init
[[email protected] nagios]# make install-commandmode
建立NagiosWeb監控介面後,登入時會需要輸入使用者名稱及密碼,這裡分別為tony和hwg123
[[email protected] nagios]# htpasswd -bc /usr/local/nagios/etc/htpasswd.users tony hwg123
[[email protected] nagios]# cat /usr/local/nagios/etc/htpasswd.users
tony:fr58UrsZgK.Tc
查看一下授權檔案
[[email protected] nagios]# grep AuthUserFile /etc/httpd/conf.d/nagios.conf
重載一下httpd服務
[[email protected] nagios]# /etc/init.d/httpd reload
修改連絡人郵箱:
[[email protected] ~]# cd /usr/local/nagios/etc/objects/
[[email protected] objects]# vim contacts.cfg
修改35行:
email [email protected]
[[email protected] objects]# /etc/init.d/postfix start
[[email protected] objects]# lsof -i:25
[[email protected] objects]# chkconfig postfix on
[[email protected] objects]# chkconfig --list postfix
在瀏覽器上輸入http://IP/nagios ,然後輸入tony,hwg123
進入web瀏覽器介面配置
安裝Nagios-server伺服器端外掛程式包:
[[email protected] objects]# yum -y install perl-devel openssl-devel
[[email protected] objects]# cd /soft/nagios/
[[email protected] nagios]# tar xf nagios-plugins-1.4.16.tar.gz
[[email protected] nagios]# cd nagios-plugins-1.4.16
[[email protected] nagios-plugins-1.4.16]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules --with-mysql
[[email protected] nagios-plugins-1.4.16]# make
[[email protected] nagios-plugins-1.4.16]# make install
[[email protected] nagios-plugins-1.4.16]# ls /usr/local/nagios/libexec/ |wc -l
安裝NRPE外掛程式:
[[email protected] ]# cd /soft/nagios/
[[email protected] ]# tar xf nrpe-2.12.tar.gz
[[email protected] ]# cd nrpe-2.12
[[email protected] nrpe-2.12]# ./configure
[[email protected] nrpe-2.12]# make all
[[email protected] nrpe-2.12]# make install-plugin
[[email protected] nrpe-2.12]# make install-daemon
[[email protected] nrpe-2.12]# make install-daemon-config
[[email protected] libexec]# ls /usr/local/nagios/libexec/ |wc -l
[[email protected] libexec]# chkconfig nagios on
[[email protected] libexec]# chkconfig --list nagios
[[email protected] libexec]# echo "/etc/init.d/nagios start">>/etc/rc.local
[[email protected] libexec]# tail -1 /etc/rc.local
[[email protected] libexec]# /etc/init.d/nagios checkconfig
[[email protected] libexec]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[[email protected] libexec]# /etc/init.d/nagios checkconfig
四、佈建服務(我此處就是本機監控自己)
[[email protected] etc]# vim nagios.cfg +32

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
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg

#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
添加cfg_file=/usr/local/nagios/etc/objects/hosts.cfg和cfg_file=/usr/local/nagios/etc/objects/services.cfg
注釋該行cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
[[email protected] Nagios-Server]# cat /usr/local/nagios/etc/objects/hosts.cfg
define host{
use linux-server
host_name 22-Nagios-Server
alias 22-Nagios
address 192.168.0.22
}

define hostgroup{
hostgroup_name linux-servers
alias Linux Servers
members 22-Nagios-Server
}
[[email protected] Nagios-Server]# cat /usr/local/nagios/etc/objects/services.cfg
define service{
use generic-service
host_name 22-Nagios-Server
service_description HTTP
check_command check_http
notifications_enabled 0
}

define service{
use generic-service
host_name 22-Nagios-Server
service_description bolg_port_80
check_command check_tcp!80
max_check_attempts 3
normal_check_interval 2
retry_check_interval 1
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
}

define service{
use generic-service
host_name 22-Nagios-Server
service_description bolg_port_3306
check_command check_tcp!3306
max_check_attempts 3
normal_check_interval 2
retry_check_interval 1
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
}

define service{
use generic-service
host_name 22-Nagios-Server
service_description Passwd
check_command check_passwd
notifications_enabled 0
}

[[email protected] Nagios-Server]# cat /usr/local/nagios/etc/objects/ commands.cfg

#‘check_passwd ‘command definintion
define command{
command_name check_passwd
command_line $USER1$/check_passwd -H $HOSTADDRESS$ -c $ARG1$
}
[[email protected] Nagios-Server]#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[[email protected] Nagios-Server]#/etc/init.d/nagios reload

具體操作是這樣先添加主機、再添加服務、然後添加命令;檢查配置最後重載Nagios服務。
備忘:可能會出現的故障(有些是關於NRPE錯誤)
1,登入web介面的時候提示錯誤:
解決:vim /usr/local/nagios/etc/cgi.cfg 把所有關於nagiosadmin改成你自己添加的使用者名稱,重啟服務即可。
2,command ‘check_Passwd‘ not define
解決:到 /usr/local/nagios/etc/objects/ commands.cfg 把它定義好就可以了。
3,Connction refurse host
解決:先cd /usr/local/nagios/libexec 下,使用 ./check_nrpe -H 192.168.0.150 -c check_ping 或者./check_nrpe -H 127.0.0.1 -c check_ping
如果還是提示Connction refurse host;接下來查看NRPE有沒有啟動:netstat -lntup |grep nrpe 如果沒有啟動執行
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d 然後再執行./check_nrpe -H 192.168.0.150 -c check_ping
4,NRPE command ‘check_disk‘ not define
解決:先ps -ef |grep nrpe
pkill nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
ps -ef |grep nrpe
然後再擷取./check_nrpe -H 192.168.0.150 -c check_disk
5,CHECK_NRPE: Error - Could not complete SSL handshake.
解決:vi /usr/local/nagios/etc/nrpe.cfg +79
allowed_hosts=127.0.0.1,192.168.0.22
ps -ef |grep nrpe
pkill nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
ps -ef |grep nrpe
6,NRPE: Unable to read output
解決:./check_nrpe -H 192.168.0.150 -c check_emm 如果還提示NRPE: Unable to read output然後
直接到裡面/usr/local/nagios/libexec/check_memory.pl -w 6% -c 3% 如果提示Permission denied
說明 /usr/local/nagios/libexec/check_memory.pl -w 6% -c 3% 沒有執行的許可權
chmod +x /usr/local/nagios/libexec/check_memory.pl -w 6% -c 3%

Nagios監控安裝之二

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.