x625802392 发表于 2019-1-16 08:35:09

centos5安装nagios

  关闭selinux
注意:(如没有,可跳过)
修改selinux配置:
getenforce
setenforce 0
  如果要使用selinux,需要修改如下
chcon -R -t https_sys_content_t /usr/local/nagios/sbin
chcon -R -t https_sys_content_t /usr/local/nagios/share
  1、安装必备软件:
yum -y install httpd php gcc glibc glibc-common gd gd-devel openssl-devel xinetd
  2、下载相关程序:
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
  创建Nagios用户及组:
/usr/sbin/useradd nagios -s /bin/bash
  创建一个名为nagcmd的用户组,用于从web接口执行外部命令。将Nagios用户和Apache用户加入组中:
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -G nagcmd nagios
/usr/sbin/usermod -G nagcmd apache
  注:上面的apache是Apache用户所属的组,如有不同请自行调整。
  编译安装nagios:
tar zxf nagios-3.2.3.tar.gz
cd nagios-3.2.3
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
  注:make install 用于安装主要的程序、CGI及HTML文件
    make install-init 用于生成init启动脚本
    make install-config 用于安装示例配置文件
    make install-commandmode 用于设置相应的目录权限
    make install-webconf 用于安装Apache配置文件
  配置Nagios Web界面登陆帐号及密码:
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
  安装nagios插件:
tar xzf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make && make install
  启动前先检查下配置文件是否正确:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  启动nagios服务:
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
  查看Nagios运行状态:
/usr/local/nagios/bin/nagiostats
  加入nagios到启动组:
chkconfig --add nagios
chkconfig nagios on
  注意:如果运行/etc/init.d/nagios restart 出现Starting nagios:This account is currently not available.
执行:
usermod -s /bin/bash nagios
给用户指定默认shell。
  登陆nagios:
重启apache服务:
/etc/init.d/httpd restart
http://localhost/nagios
  安装NRPE:
注意:由于NRPE是通过SSL方式在监控和被监控主机上进行数据传输的,所以必须先安装ssl相关的软件包。
  tar zxf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
  编辑:
vi /etc/xinetd.d/nrpe
only_from       = 127.0.0.1 #修改成nagios服务器的地址
  添加nrpe后台服务端口到/etc/services文件中:
vi /etc/services
nrpe 5666/tcp #NRPE
  重启xinetd服务:
service xinetd restart
  注意:
如果开启了防火墙,打开防火墙规则:
iptables -I RH-Firewall-1-INPUT -p tcp -m tcp --dport 5666 -j ACCEPT
保存新规则:
service iptabls save
  验证NRPE是否正确安装:
/usr/local/nagios/libexec/check_nrpe -H localhost
注:如果成功,会返回NRPE的版本号。
  监控主机上的操作:
安装nagios插件和nrpe,步骤同上。
  nagios服务器添加nrpe命令模板:
vi /usr/local/nagios/etc/objects/commands.cfg
define command{
    command_name    check_nrpe
    command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -t 60
}
  新建存放主机文件的目录:
vi /usr/local/nagios/etc/nagios.cfg
cfg_dir=/usr/local/nagios/etc/servers
  mkdir /usr/local/nagios/etc/servers
chown -R nagios.nagios /usr/local/nagios/etc/servers
  在模板里添加一个host主机模板包含pnp:
vi /usr/local/nagios/etc/objects/templates.cfg
define host{
      name                            linux-server    ; The name of this host template
      use                           generic-host,hosts-pnp; This template inherits other values from the generic-host template
      check_period                  24x7            ; By default, Linux hosts are checked round the clock
      check_interval                  5               ; Actively check the host every 5 minutes
      retry_interval                  1               ; Schedule host check retries at 1 minute intervals
      max_check_attempts            10            ; Check each Linux host 10 times (max)
      check_command                   check-host-alive ; Default command to check Linux hosts
      notification_period             workhours       ; Linux admins hate to be woken up, so we only notify during the day
                                                      ; Note that the notification_period variable is being overridden from
                                                      ; the value that is inherited from the generic-host template!
      notification_interval         120             ; Resend notifications every 2 hours
      notification_options            d,u,r         ; Only send notifications for specific host states
      contact_groups                  admins          ; Notifications get sent to the admins by default
      register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
      }
  在模板里添加一个pnp服务模板:
vi /usr/local/nagios/etc/objects/templates.cfg
define service{
      name                            pnp-service         ; The name of this service template
      use                           generic-service,services-pnp            ; Inherit default values from the generic-service definition
      max_check_attempts            4                     ; Re-check the service up to 4 times in order to determine its final (hard) state
      normal_check_interval         5                     ; Check the service every 5 minutes under normal conditions
      retry_check_interval            1                     ; Re-check the service every minute until a hard state can be determined
      register                        0                     ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
      }
      
创建一个主机配置文件:
vi /usr/local/nagios/etc/servers/192.168.56.151.cfg
  修改联系人信息:
vi /usr/local/nagios/etc/objects/contacts.cfg
define contact{
      contact_name                  backkom ; Short name of user
      use                           generic-contact   ; Inherit default values from generic-contact template (defined above)
      alias                           system Admin       ; Full name of user
      email                           backkom@mail.com ;
页: [1]
查看完整版本: centos5安装nagios