nagios安裝配置

2021-09-22 13:44:58 字數 4216 閱讀 4881

上線的伺服器有時會被人攻擊,導致服務不可用,今天安裝配置了nagios對上線伺服器進行監控,簡單記錄一下

#安裝必要的軟體包

yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel

#建立nagios使用者及授予目錄許可權

useradd -s /sbin/nologin nagios

mkdir /usr/local/nagios

chown -r nagios.nagios /usr/local/nagios

#安裝nagios tar xf nagios-4.0.7.tar.gz cd nagios-4.0.7 ./configure --prefix=/usr/local/nagios make all make install && make install-init && make install-commandmode && make install-config chkconfig --add nagios && chkconfig --level 35 nagios on && chkconfig --list nagios #安裝nagios-plugins tar xf nagios-plugins-2.0.2.tar.gz cd nagios-plugins-2.0.2 ./configure --prefix=/usr/local/nagios make && make install #安裝apache tar xf httpd-2.2.23.tar.gz cd httpd-2.2.23 ./configure --prefix=/usr/local/apache2 make && make install #安裝php tar xf php-5.5.13.tar.gz cd php-5.5.13 ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs make && make install

接下來配置apache

#生成nagios密碼檔案

scriptalias /nagios/cgi-bin "/usr/local/nagios/sbin" "/usr/local/nagios/sbin"> authtype basic options execcgi allowoverride none order allow,deny allow from all authname "nagios access" authuserfile /usr/local/nagios/etc/htpasswd //用於此目錄訪問身份驗證的檔案 require valid-user alias /nagios "/usr/local/nagios/share" "/usr/local/nagios/share"> authtype basic options none allowoverride none order allow,deny allow from all authname "nagios access" authuserfile /usr/local/nagios/etc/htpasswd require valid-user

#啟動apache vim /etc/init.d/httpd #!/bin/sh # # startup script for the apache web server # # chkconfig: 345 85 15 # description: apache is a world wide web server. it is used to serve \ # html files and cgi. # processname: httpd # pidfile: /usr/local/apache2/logs/httpd.pid # config: /usr/local/apache2/conf/httpd.conf # source function library. . /etc/rc.d/init.d/functions # see how we were called. case "$1" in start) echo -n "starting httpd: " daemon /usr/local/apache2/bin/httpd -dssl echo touch /var/lock/subsys/httpd ;; stop) echo -n "shutting down http: " killproc httpd echo rm -f /var/lock/subsys/httpd rm -f /usr/local/apache2/logs/httpd.pid ;; status) status httpd ;; restart) $0 stop $0 start ;; reload) echo -n "reloading httpd: " killproc httpd -hup echo ;; *) echo "usage: $0 " exit 1 esac exit 0 chmod +x /etc/init.d/httpd chkconfig httpd on /etc/init.d/httpd start

接下來配置nagios

#確保admin使用者登入後有許可權檢視資訊

vim /usr/local/nagios/etc/cgi.cfg

...default_user_name=admin

authorized_for_system_information=nagiosadmin,admin

authorized_for_configuration_information=nagiosadmin,admin

authorized_for_system_commands=admin

authorized_for_all_services=nagiosadmin,admin authorized_for_all_hosts=nagiosadmin,admin authorized_for_all_service_commands=nagiosadmin,admin authorized_for_all_host_commands=nagiosadmin,admin ... #修改nagios主配置檔案,將主機的定義都放在/usr/local/nagios/etc/hosts目錄中 mkdir /usr/local/nagios/etc/hosts vim /usr/local/nagios/etc/nagios.cfg ... cfg_dir=/usr/local/nagios/etc/hosts ... #新增乙個自定義命令 vim /usr/local/nagios/etc/objects/command.cfg ... # 'check_custom_http' command definition define command # 'check_dns' command definition define command ... #定義主機組 vim /usr/local/nagios/etc/hosts/group.cfg define hostgroup #定義主機server1 vim /usr/local/nagios/etc/hosts/server1.cfg define host define service ;需要做好本機使用的dns設定,在/etc/resolv.conf檔案中定義 define service define service define service #配置監控出現問題時要通知的聯絡人 vim /usr/local/nagios/etc/objects/contacts.cfg define contact define contact define contactgroup 重啟nagios /etc/init.d/nagios restart

剛才發現nagios監控到伺服器異常也沒有發郵件通知,查了一下,還需要配置mail命令可傳送郵件

yum install mail

vim /etc/mail.rc

...set [email protected]

set smtp=smtp.abc.com set [email protected] set smtp-auth-password=somepwd set smtp-auth=login ...

nagios安裝配置

nagios官網上2013 10 15更新了最新版nagios 4.0.1 install init 需root make install commandmode make install config make install webconf 需root 安裝nagios 外掛程式 tar zxv...

Nagios太陽(pnp)安裝配置

一 安裝rrdtool rrdtool將nagios採集的資料繪製成圖表。with perl options usr bin perl 指定perl路徑 make make install 二 安裝pnp with rrdtool usr local rrdtool bin rrdtool 指定rr...

nagios 外掛程式ndoutils 安裝配置

nagios 外掛程式ndoutils 安裝配置 nagios install ndoutils 安裝ndoutils外掛程式 root cagios ndoutils 2.0.0 chown nagios.nagcmd usr local nagios etc ndo root cagios nd...