Centos 配置nagios 监控服务器
实验环境如下Nagios监控服务器IP:192.168.11.5
*** 监控服务器IP:192.168.11.6
Nagios 配置如下:
一 、安装Apache+php
1 编译安装apache服务器。(在之前的博客中已经写过,这里就偷懒了。)
2 编译安装php
[*]yum install libxml2-devel
[*]Cd/usr/local/php-5.4.3
[*]./configure--prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs
[*]make&& make install
3 修改apache的配置文件
[*]vi /usr/local/apache2/conf/httpd.conf
[*]
[*] DirectoryIndex index.html index.php # 添加 index.php
[*]
[*]
[*]#LoadModule rewrite_module modules/mod_rewrite.so
[*]LoadModule php5_module modules/libphp5.so #添加
[*]
[*] AddType application/x-compress .Z
[*] AddType application/x-gzip .gz .tgz
[*]AddType application/x-httpd-php .php# 添加
4 测试php是否安装成功
[*]cd /usr/local/apache2/htdocs/
[*]vi test.php
[*]
5 使用游览器访问
http://blog.运维网.com/attachment/201301/125410552.jpg
php到此安装成功
二 、安装Nagios监控服务器
安装nagios
1 安装nagios
[*] useradd -s /sbin/nologin nagios # 建立nagios用户
[*]cd /usr/local/nagios-3.2.3/
[*]./configure --prefix=/usr/local/nagios
[*]make all
[*]make install
[*]make install-init #在/etc/rc.d/init.d/目录下创建启动脚本
[*]make install-commandmode #配置目录权限
[*]make install-config #安装nagios示例配置文件,这里安装路径为/usr/local/nagios/etc
2 安装nagios 插件
[*]cd /usr/local/nagios-plugins-1.4.15/
[*] ./configure --prefix=/usr/local/nagios #这里插件安装的位置与nagios相同
[*]make && make install
3 配置apache ,使用apache支持nagios
[*]vi /usr/local/apache2/conf/httpd.conf
[*]修改为
[*]User nagios
[*]Group nagios
[*]最后添加
[*]#nagios
[*]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
[*]
4 创建nagios访问的用户 用户名称为nagios
[*] /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd naigos
[*]New password:
[*]Re-type new password:
[*]Adding password for user naigos
5 启动apache
[*]/usr/local/apache2/bin/apachectl restart
6 修改naigos的权限
[*]chown nagios.nagios /usr/local/nagios
[*] chown nagios.nagios -R /usr/local/nagios/libexec/
7 使用游览器访问nagios服务器
http://blog.运维网.com/attachment/201301/132616861.jpg
显示乱码,解决方法:
主要是apache没有开启cgi脚本的缘故
进入apache的主配置文件httpd.conf
[*]vi /usr/local/apache2/conf/httpd.conf
[*]#LoadModule cgid_module modules/mod_cgid.so
[*]#LoadModule actions_module modules/mod_actions.so
[*]将上面2行的#去掉,重启apache就OK了
http://blog.运维网.com/attachment/201301/132921368.jpg
8 配置nagios服务器
[*]# cd /usr/local/nagios-3.2.3/
[*]# cd /usr/local/nagios
[*]# ls
[*]binetcincludelibexecsbinsharevar
[*]# vi /usr/local/nagios/etc/cgi.cfg
[*]main_config_file=/usr/local/nagios/etc/nagios.cfg
[*]physical_html_path=/usr/local/nagios/share
[*]url_html_path=/nagios show_context_help=0
[*]use_pending_states=1
[*]use_authentication=1
[*]use_ssl_authentication=0
[*]default_user_name=nagios
[*]authorized_for_system_information=nagiosadmin,nagios
[*]#添加刚才使用htpasswd建立的用户naigos (使用nagios于nagiosadmin用户才能看到监控的主机)
[*]authorized_for_configuration_information=nagiosadmin,nagios
[*]authorized_for_system_commands=nagios
[*]authorized_for_all_services=nagiosadmin,nagios
[*]authorized_for_all_hosts=nagiosadmin,nagios
[*]authorized_for_all_service_commands=nagiosadmin,nagios
[*]authorized_for_all_host_commands=nagiosadmin,nagios
[*]default_statusmap_layout=5 default_statuswrl_layout=4
[*]ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$
[*]refresh_rate=90 escape_html_tags=1
[*]action_url_target=_blank notes_url_target=_blank lock_author_names=1
[*]
[*]/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监控服务器
9 通过游览器可以看到nagios监控服务器本机的状态
http://blog.运维网.com/attachment/201301/133916564.jpg
至此 nagios监控服务器安装成功
三、配置被监控的linux 主机 (***主机)
1 安装nagios-plugins和nrpe插件
[*]Yum –yinstall gcc
[*]useradd -s /sbin/nologin nagios
[*]安装nagios-plugins
[*]tar xzvf nagios-plugins-1.4.15.tar.gz
[*]cd nagios-plugins-1.4.15
[*]./configure –prefix=/usr/local/nagios
[*]make
[*]make install
[*]
[*]安装 nagios_nrpe_2.9
[*]wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.9/nrpe-2.9.tar.gz
[*]tar xzvfnrpe-2.9.tar.gz
[*]cd nrpe-2.9
[*]./configure --with-command-group=nagios--prefix=/usr/local/nagios
[*](如果报缺少ssl,请安装 yuminstallopenssl-devel)
[*]make all
[*]make install-plugin
[*]make install-daemon
[*]make install-daemon-config
2 修改nrpe的配置文件
[*]vi /usr/local/nagios/etc/nrpe.cfg
[*]找到 allowed_hosts=127.0.0.1
[*]后面加nagios服务器的IP, 用“,”隔开,加了之后如下:
[*]allowed_hosts=127.0.0.1,192.168.11.5
[*]
3 配置nrpe的监控对象
[*]#配置监控对象
[*]说明:由监控原理可知被监控端做监控,然后将数据传给监控服务器绘总,设置监控详细参数主要是设置被监控端的nrpe.cfg文件,可以看到里面监控对象
[*]vi /usr/local/nagios/etc/nrpe.cfg,查找并修改如下一行
[*]command=/usr/local/nagios/libexec/check_users -w 5 -c 10 command=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20 command=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda5 command=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z command=/usr/local/nagios/libexec/check_procs -w 150 -c 200 command=/usr/local/nagios/libexec/check_*** -w 150 -c 200
[*]............................................#自已添加..........................................................
[*]#command=/usr/local/nagios/libexec/check_http -I 127.0.0.1 -w 10 -c 20
[*]#command=/usr/local/nagios/libexec/check_ssh -4 127.0.0.1
注释 在/usr/local/nagios/libexec 这个目录下,都是监控脚本(当我们需要监控特定服务时,需要在此目录下创建监控脚本,然后
在nrpe.cfg的配置文件中添加监控的命令)
[*]# ls
[*]check_apt check_dummy check_ircd check_ntp check_rpc check_wave
[*]check_breeze check_file_age check_load check_ntp_peercheck_sensorsnegate
[*]check_by_ssh check_flexlm check_log check_ntp_timecheck_smtp urlize
[*]check_clamd check_ftp check_mailq check_nwstat check_ssh utils.pm
[*]check_cluster check_http check_mrtg check_oracle check_swap utils.sh
[*]check_dhcp check_icmp check_mrtgtrafcheck_overcr check_tcp
[*]check_dig check_ide_smart check_nagios check_ping check_time
[*]check_disk check_ifoperstatuscheck_nntp check_pop check_udp
[*]check_disk_smbcheck_ifstatus check_nrpe check_procs check_ups
[*]check_dns check_imap check_nt check_real check_user
4 启动nrpe
[*]启动nrpe,并测试
[*]/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d启动nrpe
[*]echo '/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d &> /dev/null'
[*]>> /etc/rc.local 设置开机自启动
[*]netstat -atulnp | grep 'nrpe'
[*]tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 3308/nrpe
[*]/usr/local/nagios/libexec/check_nrpe -H localhost
[*]NRPE v2.12
四、配置监控服务器 (nagios服务器)
1 添加需要监控的linux客户端
[*] vi /usr/local/nagios/etc/nagios.cfg
[*]cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
[*]cfg_file=/usr/local/nagios/etc/objects/***.cfg # 添加此行
2、在commands.cfg中添加nrpe插件
[*]vi /usr/local/nagios/etc/objects/commands.cfg
[*]#check nrpe
[*]define command{
[*]command_name check_nrpe
[*]command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
[*]}
3、建立被监控服务器的配置文件(***.cfg)
[*]vi /usr/local/nagios/etc/objects/***.cfg
[*]define host{
[*] use linux-server ; Name of host template to use
[*] host_name ***
[*] alias ***
[*] address 192.168.11.6
[*] }
[*]define hostgroup{
[*] hostgroup_name*** ; The name of the hostgroup
[*] alias Linux Servers ; Long name of the group
[*] members *** Server
[*] }
[*]define service{
[*] use local-service ; Name of service template to use
[*] host_name ***
[*] service_description PING
[*] check_command check_ping!100.0,20%!500.0,60%
[*] }
[*]define service{
[*] use local-service ; Name of service template to use
[*] host_name ***
[*] service_description disk
[*] check_command check_nrpe!check_sda5 # 通过nrpe插件监控***服务器的硬盘
[*] }
[*]
[*]define service{
[*] use local-service ; Name of service template to use
[*] host_name ***
[*] service_description SSH
[*] check_command check_ssh
[*] notifications_enabled 0
[*] }
[*]define service{
[*] use local-service ; Name of service template to use
[*] host_name ***
[*] service_description ***
[*] check_command check_tcp!1723#监控tcp的1723端口
[*] notifications_enabled 0
[*] }
当我们使用相同的参数监控多台服务器时候,我们可以建立组的方式,这样不必建立多个配置文件,例如监控多台tomcat 服务器
[*] vi /usr/local/nagios/etc/nagios.cfg
[*]cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
[*]cfg_file=/usr/local/nagios/etc/objects/***.cfg # 添加此行
[*]cfg_file=/usr/local/nagios/etc/objects/tomcat.cfg # 添加此行
当有多台服务器时候使用组的优点
[*]vi /usr/local/nagios/etc/objects/tomcat.cfg
[*]define host{
[*] use linux-server ; Name of host template to use
[*] ; This host definition will inherit all variables that are defined
[*] ; in (or inherited by) the linux-server host template definition.
[*] host_name Tomcat1
[*] alias web1
[*] address 192.168.11.7
[*] }
[*]define host{
[*] use linux-server ; Name of host template to use
[*] ; This host definition will inherit all variables that are defined
[*] ; in (or inherited by) the linux-server host template definition.
[*] host_name Tomcat2
[*] alias web2
[*] address 192.168.11.8
[*] }
[*]define host{
[*] use linux-server ; Name of host template to use
[*] ; This host definition will inherit all variables that are defined
[*] ; in (or inherited by) the linux-server host template definition.
[*] host_name Tomcat3
[*] alias web3
[*] address 192.168.11.9
[*] }
[*]define host{
[*] use linux-server ; Name of host template to use
[*] ; This host definition will inherit all variables that are defined
[*] ; in (or inherited by) the linux-server host template definition.
[*] host_name Tomcat4
[*] alias web4
[*] address 192.168.11.10
[*] }
[*]define host{
[*] use linux-server ; Name of host template to use
[*] ; This host definition will inherit all variables that are defined
[*] ; in (or inherited by) the linux-server host template definition.
[*] host_name Tomcat5
[*] alias web5
[*] address 192.168.11.11
[*] }
[*]define host{
[*] use linux-server ; Name of host template to use
[*] ; This host definition will inherit all variables that are defined
[*] ; in (or inherited by) the linux-server host template definition.
[*] host_name Tomcat6
[*] alias web6
[*] address 192.168.11.12
[*] }
[*]define hostgroup{
[*] hostgroup_nameTomcat ; The name of the hostgroup
[*] alias Linux Servers ; Long name of the group
[*] members Tomcat1,Tomcat2,Tomcat3,Tomcat4,Tomcat5,Tomcat6 ; Comma separated list of hosts that belong to this group
[*] }#在组中添加hostname
[*]define service{
[*] use local-service ; Name of service template to use
[*] hostgroup_name Tomcat #由host_name 改成hostgroup—name
[*] service_description PING
[*] check_command check_ping!100.0,20%!500.0,60%
[*] }
[*]
[*]define service{
[*] use local-service ; Name of service template to use
[*] hostgroup_name Tomcat
[*] service_description SSH
[*] check_command check_ssh
[*] notifications_enabled 0
[*] }
[*]define service{
[*] use local-service ; Name of service template to use
[*] hostgroup_name Tomcat
[*] service_description HTTP
[*] check_command check_http
[*] notifications_enabled 0
[*] }
4、通过游览器访问nagios服务器
http://blog.运维网.com/attachment/201301/144743382.jpg
页:
[1]