nagios的安装配置

1、  解决nagios的依赖关系,和所需组件:
# yum -y install httpd gcc glibc glibc-common *gd* php php-mysql mysql mysql-server
2、  nagios所需组件:nagios nagios-plugins ndoutils(非必须)
linux客户端:nrpe   windows客户端NSClient++
创建nagiso用户和组:      
# groupadd nagcmd
# useradd -m nagios
# usermod -a -G nagcmd nagios
# usermod -a -G nagcmd apache
编译安装nagios:    
# tar zxf nagios-3.1.2.tar.gz
# cd nagios-3.1.2
# ./configure --with-command-group=nagcmd --enable-event-broker --prefix=/var/www/nagios
 
# make all
# make install
# make install-init
# make install-config
# make install-commandmode
email指定您想用来接收nagios警告信息的邮件地址,默认是本机的nagios用户:
# vi /var/www/nagios/etc/objects/contacts.cfg
email        nagios@localhost       #这个是默认设置
httpd的配置文件目录(conf.d)中创建NagiosWeb程序配置文件:
# make install-webconf
创建一个登录nagios web程序的用户,这个用户帐号在以后通过web登录nagios认证时所用:
# htpasswd -c /var/www/nagios/htpasswd.users nagiosadmin
   启动服务:       #service httpd restart
编译安装nagios-plusgins:
           # tar zxf nagios-plugins-1.4.13.tar.gz
# cd nagios-plugins-1.4.13
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/var/www/nagios --with-mysql=/usr/lib/mysql
           #make && make install
启动服务:  
检测配置文件:# /var/www/nagios/bin/nagios -v /var/www/nagios/etc/nagios.cfg
              #service nagios restart
              #chkconfig nagios add
              #chkconfig nagios on
              #setenforce 0  这个只是临时关闭selinux
当然,也可以通过以下方式将nagiosCGI程序运行于SELinux/targeted模式而不用关闭selinux
# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin
# chcon -R -t httpd_sys_content_t /usr/local/nagios/share
web中输入http://IP/nagios 并输入密码和账户
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
windows客户端安装:NSClient++-0.3.8-Win32.msi安装完后打开nagios.cfg文件将
注释去掉cfg_file=/usr/local/nagios/etc/objects/windows.cfg
定义windows.cfg
define host{
        use             windows-server  ; Inherit default values from a template
        host_name       winserver       ; The name we're giving to this host
        alias           My Windows Server       ; A longer name associated with the host
        address         192.168.0.191   ; 你主机的IP
        }
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
linux客户端的安装:
先添加nagios用户
useradd nagios
为了安装nrpe,先安装nagios-plugins-1.4.15.tar.gz 插件
# tar zxf 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
 
tar -zxvf nrpe-2.12.tar.gz
cd nrpe-2.12.tar.gz
./configure  (会自动加载SSL)
#如果后面make报错,加如下参数
./configure --enable-ssl --with-ssl-lib=/usr/lib/(当然前提要有openssl)
make all
make install-plugin
make install-daemon
make install-daemon-config
 
4.配置nrpe信息
vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1  //允许监控的IP
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
服务端
3.安装NRPE
cd nagios-nrpe_2.8.1
./configure   #默认自动添加了openssl
#因为传送过程要加密,如果后面make报错,加如下参数
rpm -qa| grep ssl
openssl-devel-0.9.7a-43.17.el4_6.1
rpm -ql openssl-devel-0.9.7a-43.17.el4_6.1 | more
./configure --enable-ssl --with-ssl-lib=/lib/(当然前提要有openssl)
make all
make install-plugin
添加步骤:
vi /usr/local/nagios/etc/objects/commands.cfg
      nagios.cfg启用有以下行
         cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg
4.commands.cfg定义外部构件nrpe
 
#添加
#check nrpe
define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }
定义 mylinux.cfg
define host{
           use             linux-server
          host_name     mylinux
          alias            mylinux
          address        192.168.0.27(客户端IP既被监控的IP)
        }
define service{
        use                      generic-service
        host_name             mylinux
        service_description     check-swap
        check_command        check_nrpe!check_swap
               }
define service{
        use                      generic-service
        host_name             mylinux
        service_description     check-load
       check_command         check_nrpe!check_load
               }
define service{
        use                      generic-service
        host_name             mylinux
       service_description     check-disk
       check_command        check_nrpe!check_had1
define service{
        use                      generic-service
        host_name             mylinux
       service_description     check-users
       check_command        check_nrpe!check_users
               }
define service{
        use                    generic-service
        host_name           mylinux
        service_description  otal_procs
        check_command     check_nrpe!check_total_procs
}
 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
define service{
        use                    generic-service
        host_name           mylinux
        service_description  httpd
        check_command     check_http! -H 192.168.0.27
}
 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
nagios监控mysql服务器:
 
1、建立专用数据库:
[root@svr3 ~]# /usr/local/webserver/mysql/bin/mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 51910
Server version: 5.5.3-m3-log Source distribution
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> create database nagios;
Query OK, 1 row affected (0.00 sec)
 
mysql> grant select on nagios.* to nagios@'%' identified by '123qweasd';
Query OK, 0 rows affected (0.00 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql> select User,Password,Host from user;
+----------------+-------------------------------------------+------------------+
| User           | Password                                  | Host             |
+----------------+-------------------------------------------+------------------+
| root           | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 | localhost        |
| nagios         | *A1F1CB851D62F002C09A0C9C4A76262473432F55 | %                |
+----------------+-------------------------------------------+------------------+
14 rows in set (0.00 sec)
12 rows in set (0.00 sec)
 
[root@svr3 ~]# /usr/local/nagios/libexec/check_mysql -H 192.168.0.3 -u nagios -d nagios -p 123qweasd
Uptime: 970046  Threads: 1  Questions: 684583  Slow queries: 3  Opens: 672  Flush tables: 1  Open tables: 
     注意:check_mysql必须如果没有则说明mysql-devel没有安装,需要安装后在重新编译安装nagios-plugins这个包
369  Queries per second avg: 0.705
 
[root@svr4 nrpe_install]# /usr/local/nagios/libexec/check_mysql -H 192.168.0.3 -u nagios -d nagios -p 123qweasd
Uptime: 970348  Threads: 1  Questions: 684584  Slow queries: 3  Opens: 672  Flush tables: 1  Open tables: 369  Queries per second avg: 0.705
 
果断开始设置:
#定义用户
#定义组,及隶属用户
#用户增加
 
command.cfg里增加插件命令:
#check mysql
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u nagios -d nagios -p 123qweasd
}
 
#定义服务:
define service {
        host_name mysql
     
        check_period 24x7
        max_check_attempts 2
        normal_check_interval 1
        retry_check_interval 1
        contact_groups admins
        notification_interval 5
        notification_period 24x7
        notification_options w,u,c,r
        check_command check_mysql
        }
       
       
飞信报警
1.修改模板文件
修改concont.cfg
2.
修改
 commands.cfg
define command{
        command_name notify-service-by-fetion
        command_line      /usr/bin/fetion --mobile 15003880800 --pwd 123qweQWE --to 15003880800 --msg-tpye=0  --msg-utf8 $HOSTNAME
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章