标签:nagios
这里使用的centos7系统,nagios-4.2.1.tar.gz,nagios-plugins-2.1.2.tar.gz,nrpe-3.2.1.tar.gznagios服务器端安装包上官网下
或百度网盘
https://pan.baidu.com/s/1sALFDRt3n24LRheqA6Hp4g
t72q
建议去官网
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
#安装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
[root@localhost opt]# ll
总用量 14052
-rw-r--r-- 1 root root 11155576 3月 7 17:04 nagios-4.2.1.tar.gz
-rw-r--r-- 1 root root 2695301 3月 7 17:04 nagios-plugins-2.1.2.tar.gz
-rw-r--r-- 1 root root 518015 3月 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
#服务器端
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
mkdir /usr/local/nagios
cd nagios-4.2.1
./configure --prefix=/usr/local/nagios
make all && make install && echo $?
make install-config??#?把配置文件样例复制到nagios的安装目录
make install-commandmode #?给外部命令访问nagios配置文件的权限
make install-init??#?把nagios做成一个运行脚本,使nagios随系统开机启动
cd /opt/nagios-plugins-2.1.2
./configure --prefix=/usr/local/nagios
make && make install && echo $?
cd /opt/nrpe-3.2.1
./configure --prefix=/usr/local/nagios --enable-command-args
编译
make all
安装
添加nagios用户
make install-groups-users
安装
make install
添加主配置文件
make install-config
配置xinetd
make install-inetd
设置nrpe管理命令
make install-init
编译插件
make check_nrpe
安装插件
make install-plugin
#先备份
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
#先备份
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
!!!!注意,不适用nagiosadmin用户会报错,解决方法在"报错"栏中
htpasswd -c /usr/local/nagios/etc/htpasswd admin
#安装发送邮件服务(sendmail不是必须)
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" 接收者邮箱
#修改邮箱配置文件
vim /usr/local/nagios/etc/objects/commands.cfg(邮件发送,mailx可以不设置)
#指定接收者邮箱,多个用" "分隔
vim /usr/local/nagios/etc/objects/contacts.cfg
email 14******951@qq.com 15******951@qq.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
#添加监控主机配置文件目录
vim /usr/local/nagios/etc/nagios.cfg
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_dir=/usr/local/nagios/etc/servers/
#创建目录
mkdir -pv /usr/local/nagios/etc/servers/
#添加对nrpe的支持
vim /usr/local/nagios/etc/objects/commands.cfg
#nrpe
define command{
command_name check_nrpe
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
systemctl restart nagios
#重新导入配置文件
systemctl reload nagios
It appears as though you do not have permission to view information for any of the hosts you requested...
这是由于web使用用户不是nagiosadmin,需要修改cgi.cfg
vim /usr/local/nagios/etc/cgi.cfg
在nagiosadmin后添加自定义的管理员名称,如
nagiosadmin,admin
标签:nagios
原文地址:http://blog.51cto.com/13323775/2085624