Nagios Server Setup and use

Source: Internet
Author: User
Tags configuration settings

The CENTOS7 system used here, nagios-4.2.1.tar.gz,nagios-plugins-2.1.2.tar.gz,nrpe-3.2.1.tar.gz

Download the installation package

Nagios Server-side installation package under the Guan Network
or Baidu Network disk
https://pan.baidu.com/s/1sALFDRt3n24LRheqA6Hp4g
t72q
Suggest to the official website

Installing the Ali Yum Source

Wget-o/etc/yum.repos.d/centos-base.repo Http://mirrors.aliyun.com/repo/Centos-7.repo
Yum Clean all && yum Makecache fast
#安装epel源
Yum Install-y epel-release
Yum Makecache Fast

Server-side

#安装httpd和php
Yum Install-y httpd
Yum install-y php php-cli Php-common
#下载
Cd/opt
wget http://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
wget https://github.com/NagiosEnterprises/nrpe/archive/nrpe-3.0.tar.gz
[email protected] opt]# LL
Total dosage 14052
-rw-r--r--1 root root 11155576 March 7 17:04 nagios-4.2.1.tar.gz
-rw-r--r--1 root root 2695301 March 7 17:04 nagios-plugins-2.1.2.tar.gz
-rw-r--r--1 root root 518015 March 7 17:04 nrpe-3.2.1.tar.gz

#解压
Tar axf nagios-4.2.1.tar.gz
Tar axf nagios-plugins-2.1.2.tar.gz
Tar axf nrpe-3.2.1.tar.gz

Install dependent packages

#服务器端
Yum install-y gcc glibc gcc-c++ make cmake unzip Glibc-common gd gd-devel php perl-devel mysql-server openssl-devel
#客户端依赖
Yum install-y gcc glibc make cmake glibc-common gd gd-devel php perl-devel mysql-server openssl-devel

Compiling and installing Nagios

Mkdir/usr/local/nagios
CD nagios-4.2.1
./configure--prefix=/usr/local/nagios
Make all && make install && echo $?

Make Install-config?? Copy the configuration file sample to the Nagios installation directory
Make Install-commandmode #? permission to access Nagios configuration files for external commands
Make Install-init?? #? make Nagios a running script to enable Nagios to boot with the system

Compiling and installing Nagios-plugins

cd/opt/nagios-plugins-2.1.2
./configure--prefix=/usr/local/nagios
Do && make install && echo $?

Compiling and installing Nrpe

cd/opt/nrpe-3.2.1
./configure--prefix=/usr/local/nagios--enable-command-args
Compile
Make all
Installation
Add Nagios Users
Make Install-groups-users
Installation
Make install
Adding a master configuration file
Make Install-config
Configure XINETD
Make install-inetd
Set Nrpe management commands
Make Install-init
Compiling plugins
Make Check_nrpe
Installing plugins
Make Install-plugin

Configuration Modification Nrpe Settings

#先备份
Cp/usr/local/nagios/etc/nrpe.cfg{,.bak}
#将hda1改为sda
Command[check_hda1]=/usr/local/nagios/libexec/check_disk-w 20%-C 10%-P/DEV/SDA
#启动nrpe
/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe.cfg-d

Modify HTTPD Settings

#先备份
Cp/etc/httpd/conf/httpd.conf{,.bak}
Vim/etc/httpd/conf/httpd.conf
#在文件最后添加

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"<Directory "/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</Directory>Alias /nagios "/usr/local/nagios/share"<Directory "/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</Directory>

#启动httpd
Systemctl Restart httpd

Modify Nagios configuration Settings user password

!!!! Note that not applicable nagiosadmin users will error, the solution in the "Error" column
Htpasswd-c/USR/LOCAL/NAGIOS/ETC/HTPASSWD Admin

Set up a mailbox

#安装发送邮件服务 (SendMail not required)
Yum install-y sendmail Mailx
#设置smtp
Vim/etc/mail.rc

set from=发送者信息set smtp=smtp.263.net #smtp,这里是263邮箱的set smtp-auth-user=发送者邮箱set smtp-auth-password=发送者邮箱认证set smtp-auth=login

#测试发送邮件
echo "Testmail" |mail-s "title" Recipient mailbox

#修改邮箱配置文件
Vim/usr/local/nagios/etc/objects/commands.cfg (mail send, MAILX can not be set)
#指定接收者邮箱, multiple separated by ""
Vim/usr/local/nagios/etc/objects/contacts.cfg

     email                           14******[email protected] 15******[email protected]       ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

#添加监控主机配置文件目录
Vim/usr/local/nagios/etc/nagios.cfg

#cfg_file=/usr/local/nagios/etc/objects/localhost.cfgcfg_dir=/usr/local/nagios/etc/servers/

#创建目录
mkdir-pv/usr/local/nagios/etc/servers/

#添加对nrpe的支持
Vim/usr/local/nagios/etc/objects/commands.cfg

#nrpedefine command{command_name check_nrpecommand_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$}
Start Nagios

Systemctl Restart Nagios
#重新导入配置文件
Systemctl Reload Nagios

Error
It appears as though you do not have permission to view information for any of the hosts you requested...

This is because the Web usage user is not nagiosadmin and needs to be modified CGI.CFG

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

Add a custom administrator name after nagiosadmin, such as
Nagiosadmin,admin

Nagios Server Setup and use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.