nagios中文安装说明

(1) nagios
[root@localhost ~]# mkdir /usr/local/nagios
[root@localhost ~]# useradd -s /sbin/nologin nagios
[root@localhost ~]# chown -R nagios:nagios /usr/local/nagios/
[root@localhost ~]# cd /install/
[root@localhost install]# tar -zxvf nagios-3.2.0.tar.gz -C /usr/src
[root@localhost install]# cd /usr/src/nagios-3.2.0/
[root@localhost nagios-3.2.0]# ./configure --prefix=/usr/local/nagios
[root@localhost nagios-3.2.0]# make all
[root@localhost nagios-3.2.0]# make install
[root@localhost nagios-3.2.0]# make install-init
[root@localhost nagios-3.2.0]# make install-commandmode
[root@localhost nagios-3.2.0]# make install-config
[root@localhost nagios-3.2.0]# chkconfig --add nagios
[root@localhost nagios-3.2.0]# chkconfig --level 35 nagios on
[root@localhost nagios-3.2.0]# chkconfig --list nagios
nagios          0:关闭  1:关闭  2:关闭  3:启用  4:启用  5:启用  6:关闭

(2)nagios-plugins
[root@localhost install]# tar -zxvf nagios-plugins-1.4.14.tar.gz -C /usr/src/
[root@localhost install]# cd /usr/src/nagios-plugins-1.4.14/
[root@localhost nagios-plugins-1.4.14]# ./configure --prefix=/usr/local/nagios
[root@localhost nagios-plugins-1.4.14]# make
[root@localhost nagios-plugins-1.4.14]# make install

(3)nagios汉化插件
[root@localhost install]# tar -jxvf nagios-cn-3.2.0.tar.bz2 -C /usr/src/
[root@localhost install]# cd /usr/src/nagios-cn-3.2.0/
[root@localhost nagios-cn-3.2.0]# ./configure
[root@localhost nagios-cn-3.2.0]# make all
[root@localhost nagios-cn-3.2.0]# make install

(11)配置apache
[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf  在最好添加如下:
#setting for nagios
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>

[root@localhost ~]# /usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd pengliang
New password: 11qq```
Re-type new password: 11qq```
Adding password for user pengliang

(4)

[root@localhost objects]# touch hosts.cfg
[root@localhost objects]# chmod 664 hosts.cfg
[root@localhost objects]# chown nagios:nagios hosts.cfg
[root@localhost objects]# vim /usr/local/nagios/etc/objects/hosts.cfg
############################################################################
define host{
    use             linux-server
    host_name       115-server
    alias           115
    address         192.168.1.115
}

define  host{
    use             linux-server
    host_name       120-server
    alias           120
    address         192.168.1.120
}

define hostgroup{
    hostgroup_name      sa-servers
    alias               sa servers
    members             115-server,120-server
}



(5)
[root@localhost objects]# touch services.cfg
[root@localhost objects]# chmod 664 services.cfg
[root@localhost objects]# chown nagios:nagios services.cfg
[root@localhost objects]# vim /usr/local/nagios/etc/objects/services.cfg
#################################  115主机 #########################################
define service{
    use         local-service
    host_name   115-server
    service_description     PING
    check_command       check_ping!100.0,20%!500.0,60%
}

define service{
    use         local-service
    host_name   115-server
    service_description     SSHD
    check_command       check_tcp!22
}

define service{
    use         local-service
    host_name   115-server
    service_description     http
    check_command       check_http
}

define service{
    use         local-service
    host_name   115-server
    service_description     smtp
    check_command       check_smtp!0.0020!0.0050!10
}

######################################## 125主机 ##############################################

define service{
    use         local-service
    host_name   120-server
    service_description     PING
    check_command       check_ping!100.0,20%!500.0,60%
}

define service{
    use         local-service
    host_name   120-server
    service_description     SSH
    check_command       check_ssh
}

define service{
    use         local-service
    host_name  120-server
    service_description     SSHD
    check_command       check_tcp!22
}

define service{
    use         local-service
    host_name   120-server
    service_description     ftp
    check_command       check_ftp
}

define service{
    use         local-service
    host_name   120-server
    service_description     mysqlport
    check_command       check_tcp!3306
}

6、
[root@localhost objects]# vim /usr/local/nagios/etc/objects/contacts.cfg
define contact{
        contact_name                    shancg      ; Short name of user
        use             generic-contact     ; Inherit default values from generic-contact template (defined above)
        alias                           sa-system       ; Full name of user

        email                           shancg@corpmail.cn  ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }
####################################################################
define contactgroup{
        contactgroup_name       admins
        alias                   system administrators group
        members                 shancg
        }
######################################################################

[root@localhost etc]# vim /usr/local/nagios/etc/cgi.cfg
107 default_user_name=pengliang
119 authorized_for_system_information=nagiosadmin,pengliang
131 authorized_for_configuration_information=nagiosadmin,pengliang
144 authorized_for_system_commands=pengliang
157 authorized_for_all_services=nagiosadmin,pengliang
158 authorized_for_all_hosts=nagiosadmin,pengliang
171 authorized_for_all_service_commands=nagiosadmin,pengliang
172 authorized_for_all_host_commands=nagiosadmin,pengliang

-------------------------------------------------
/usr/local/nagios/etc/objects/templates.cfg
/usr/local/nagios/etc/resource.cfg
/usr/local/nagios/etc/objects/commands.cfg
/usr/local/nagios/etc/objects/hosts.cfg
/usr/local/nagios/etc/objects/services.cfg
/usr/local/nagios/etc/objects/contacts.cfg
/usr/local/nagios/etc/objects/timeperiods.cfg
-------------------------------------------------


9、
[root@localhost etc]# vim /usr/local/nagios/etc/nagios.cfg
log_file=/usr/local/nagios/var/nagios.log
# OBJECT CONFIGURATION FILE(S)
# These are the object configuration files in which you define hosts,
# host groups, contacts, contact groups, services, etc.
# You can split your object definitions across several config files
# if you wish (as shown below), or keep them all in a single config file.

# You can specify individual object config files as shown below:
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg

object_cache_file=/usr/local/nagios/var/objects.cache
resource_file=/usr/local/nagios/etc/resource.cfg
status_file=/usr/local/nagios/var/status.dat
status_update_interval=10

nagios_user=nagios
nagios_group=nagios

check_external_commands=1

command_check_interval=2

interval_length=60

(14)验证nagios文件是否配置正常

[root@localhost objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Total Warnings: 0
Total Errors:   0

[root@localhost objects]# /etc/init.d/nagios stop                                         
[root@localhost objects]# /etc/init.d/nagios start

http://192.168.1.120/nagios