发表于 2019-1-14 07:57:25

nagios安装配置记录

  一、创建nagios用户和用户组。
#useradd -s /sbin/nologin nagios
#mkdir /usr/local/nagios
#chown -R nagios:nagios /usr/local/nagios  二、编译安装nagios
# tar -zxvf nagios-3.5.0.tar.gz
# cd nagios
#./configure --prefix=/usr/local/nagios
# tar -zxvf nagios-3.5.0.tar.gz
# cd nagios
#./configure --prefix=/usr/local/nagios
#make all
#make install
# make install-init #在/etc/rc.d/init.d目录下创建nagios启动脚本
# make install-config #安装示例配置文件
# make install-commandmode #配置目录权限  三、nagios目录对应功能说明:
  bin:可执行程序所在目录
  etc:配置文件所在目录
  sbin:cgi文件所在目录,也就是执行外部命令所需文件所在目录
  share:网页文件所在目录
  libexec:外部插件所在目录
  var:日志文件,lock等文件所在目录。修改日志文件时间格式,修改拷贝的文件(perl -i -pe '($t) = ($_ =~ m/^\[(\d+)\]/); $nice=scalar localtime $t; s/^\[(\d+)\]/[$nice]/'nagios.log)
  var/archives:日志自动归档目录
  var/rw:用来存放外部命令文件的目录
  四、安装nagios插件。
# tar -zxvf nagios-plugins-1.4.16.tar.gz
# yum -y install openssl*
# cd nagios-plugins-1.4.16
# ./configure --prefix=/usr/local/nagios
# make
# make install  五、安装并配置httpd和php
# yum -y install php httpd
# vim /etc/httpd/conf/httpd.conf
User nagios
Group nagios
DirectoryIndex index.html index.html.var index.php
AddType application/x-httpd-php .php
ScriptAlias /nagios/cgi-bin "/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"

AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user

# htpasswd -cm /usr/local/nagios /etc/htpasswd USER
# service httpd restart
# service nagios restart
#访问http://ip/nagios 输入用户/密码就可以看到nagios管理界面  六、安装插件NRPE
# tar -zxvf nrpe-2.14.tar.gz
# cd nrpe-2.14
# ./configure
# make all
# make install-plugin
# cd /usr/local/nagios/etc
# mkdir monitor
# cp -R objects/* monitor/
# vim monitor/commands.cfg
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
# ./check_nrpe -H 192.168.1.1 #检查与被监控对象的连通性  七、定义被监控主机和服务。

# vim /usr/local/nagios/etc/cgi.cfg #将用户名修改为nagios界面登录的用户名
default_user_name=USER
# vim /usr/local/nagios/etc/nagios.cfg
cfg_dir=/usr/local/nagios/etc/monitor#注释掉cfg_file开头的行
# vim /usr/local/nagios/etc/monitor/contacts.cfg#需要指定联系人才能实现监控
define contact{
contact_name                  USER   #必须改为http验证用户
use                           generic-contact
alias                           Nagios Admin   
email                           admin@domain.com
}
define contactgroup{
contactgroup_name       admins
alias                   Nagios Administrators
members               USER
}
# service postfix restart #重启邮件服务
# vim /usr/local/nagios/etc/monitor/hosts.cfg #定义主机
define host{
use       windows-server   #引用模板windows-server的属性信息
host_name test-server      #主机命名
alias   test             #别名
address   ip_address       #ip地址
}
define hostgroup{                  #必须定义组
hostgroup_namewindows-servers
alias         windows Servers
members         test-server
}
# vim /usr/local/nagios/etc/monitor/services.cfg #定义服务
define service{
use                      local-service
host_name                test-server
service_description      EXAMPLE
check_command            check-host-alive
}
# cd /sbin
# ln -s /usr/local/nagios/bin/nagios nagios
# nagios -v /usr/local/nagios/etc/nagios.cfg #检查主配置文件  八、客户端安装nrpe和nagios-plugin。

# useradd nagios
# yum -y install openssl
# tar -zxvf nagios-plugins-1.4.16.tar.gz
# cd nagios-plugins-1.4.16
# ./configure --prefix=/usr/local/nagios
# make&make install
check_http.c: In function ‘process_arguments’:
check_http.c:312: error: ‘ssl_version’ undeclared (first use in this function)
check_http.c:312: error: (Each undeclared identifier is reported only once
check_http.c:312: error: for each function it appears in.)
# make clean#清除掉之前make的残余信息
# ./configure--prefix=/usr/local/nagios
# make&make install
# chown nagios:nagios /usr/local/nagios
# chown -R nagios:nagios /usr/local/nagios/libexec/
# tar -zxvf nrpe-2.14.tar.gz
# cd nrpe-2.14
# ./configure
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
# make install-xinetd
# vim /etc/xinetd.d/nrpe
service nrpe
{
flags         = REUSE
socket_type   = stream
port            = 5666
wait            = no
user            = nagios
group         = nagios
server          = /usr/local/nagios/bin/nrpe
server_args   = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure+= USERID
disable         = no
only_from       = 127.0.0.1 192.168.1.10 #指定监控主机的IP
}
# vim /etc/services
nrpe            5666/tcp                # nrpe
# service xinetd restart
# /usr/local/nagios/libexec/check_nrpe -H localhost #测试本地nrpe daemon是否正常
# vim /usr/local/nagios/etc/nrpe.cfg #添加监控服务
command=/usr/local/nagios/libexec/check_http -I 127.0.0.1 -w 5 -c 10
#以下在服务端添加
# vim /usr/local/nagios/etc/monitor/services.cfg
define service{
use                      local-service
host_name                test-linux
service_description      linux
check_command            check_nrpe!check_http
}  九、配置Fetion短信报警。
# tar -zxvf fetion20101113.tar.gz
# cd fetion20101113
# mv fetion /bin   #剪切主程序到/bin
# mkdir /usr/local/fetion
# mv fetion20101113/* /usr/local/fetion/
# vim /etc/ld.so.conf.d/fetion.conf
/usr/local/fetion   #指向Fetion的库文件目录
# ldconfig#重新读取库文件
# fetion --help   #测试命令是否可执行
# yum -y install libgcc_s.so.1 #安装缺失的库文件
# fetion --mobile=10086 --pwd=123456 --to=10010 --msg-utf8=Test --debug#发送测试短信,接收人必须是飞信好友,首次发送需填写验证码:/bin/10086.jpg
# vim /usr/local/nagios/etc/monitor/commands.cfg#修改commands配置文件
# 'notify-host-by-fetion' command definition
define command{
command_name    notify-host-by-fetion
command_line    /bin/fetion --mobile=10086 --pwd=123456 --to=$CONTACTPAGER$ --msg-utf8="***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n"
}
# 'notify-service-by-fetion' command definition
define command{
command_name    notify-service-by-fetion
command_line    /bin/fetion --mobile=10086 --pwd=123456 --to=$CONTACTPAGER$ --msg-utf8="***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n"
}
# vim /usr/local/nagios/etc/monitor/contacts.cfg   #修改联系人配置文件
define contact{
contact_name                  Tom
use                           generic-contact
alias                           Monitor user
email                           Tom@gmail.com
service_notification_commands   notify-service-by-fetion
host_notification_commands      notify-host-by-fetion
pager                           10086   #手机号码
}
define contact{
contact_name                  Tony
use                           generic-contact
alias                           Monitor user
email                           Tony@gmail.com
service_notification_commands   notify-service-by-fetion
host_notification_commands      notify-host-by-fetion
pager                           10010
}
define contactgroup{
contactgroup_name       admins
alias                   Nagios Administrators
members               Tom,Tony
}
#  




页: [1]
查看完整版本: nagios安装配置记录