系统环境:

[root@nagios_server ~]# cat /etc/redhat-release 

CentOS release 6.9 (Final)


1、更新yum源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

wget -O /etc/yum.repos.d/CentOS-Base.repo   http://mirrors.aliyun.com/repo/Centos-6.repo


2.调整字符集

echo 'export LC_ALL=C'>>/etc/profile

source /etc/profile


3.关闭iptables与selinux


4.更新系统时间

/usr/sbin/ntpdate pool.ntp.org

然后放入定时任务


5.安装gcc和LAMP

yum install gcc glibc glibc-common gd gd-devel php-gd httpd php mysql* unzip -y


6.添加用户

[root@Nagios tools]# useradd -m nagios

[root@Nagios tools]# useradd apache

[root@Nagios tools]# groupadd nagcmd

[root@Nagios tools]# usermod -a -G nagcmd nagios

[root@Nagios tools]# usermod -a -G nagcmd apache


7.下载与安装nagios

[root@Nagios tools]# unzip oldboy_training_nagios_soft.zip

Archive:  oldboy_training_nagios_soft.zip

  inflating: check_memory.pl #内存监控插件       

  inflating: check_mysql     #mysql监控插件        

  inflating: Class-Accessor-0.31.tar.gz  

 extracting: Config-Tiny-2.12.tar.gz  

  inflating: libart_lgpl-2.3.17.tar.gz  

  inflating: Math-Calc-Units-1.07.tar.gz  

  inflating: Nagios-Plugin-0.34.tar.gz  

  inflating: nrpe-2.12.tar.gz  #客户端的nrpe守护进程      

  inflating: Params-Validate-0.91.tar.gz  

  inflating: pnp-0.4.14.tar.gz #nagios的web图形展示程序      

  inflating: Regexp-Common-2010010201.tar.gz  

  inflating: rrdtool-1.2.14.tar.gz  #nagios的画图工具 

  inflating: check_iostat  #io监控插件          

  inflating: nagios-3.5.1.tar.gz  #nagios主程序   

  inflating: nagios-plugins-1.4.16.tar.gz  #nagios插件

[root@Nagios tools]# tar xf nagios-3.5.1.tar.gz

[root@Nagios tools]# cd nagios  

[root@Nagios nagios]# ./configure --with-command-group=nagcmd

[root@Nagios nagios]# make all

[root@Nagios nagios]# make install

。。。。。。。。。。。。。。。。。。。。。。。。

  make install-init

     - This installs the init script in /etc/rc.d/init.d


  make install-commandmode

     - This installs and configures permissions on the

       directory for holding the external command file


  make install-config

     - This installs sample config files in /usr/local/nagios/etc


make[1]: Leaving directory `/root/tools/nagios'


[root@Nagios nagios]# make install-init

/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d

/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios


*** Init script installed ***


[root@Nagios nagios]# make install-commandmode

/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw

chmod g+s /usr/local/nagios/var/rw


*** External command directory configured ***


[root@Nagios nagios]# make install-config     

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg

/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg


*** Config files installed ***


Remember, these are *SAMPLE* config files.  You'll need to read

the documentation for more information on how to actually define

services, hosts, etc. to fit your particular needs.


[root@Nagios nagios]# make install-webconf

/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf


*** Nagios/Apache conf file installed ***


8.配置web认证

[root@Nagios nagios]# vi /etc/httpd/conf.d/nagios.conf

# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER

# Last Modified: 11-26-2005

#

# This file contains examples of entries that need

# to be incorporated into your Apache web server

# configuration file.  Customize the paths, etc. as

# needed to fit your system.


ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"


<Directory "/usr/local/nagios/sbin">

#  SSLRequireSSL

   Options ExecCGI

   AllowOverride None

   Order allow,deny

   Allow from all

#  Order deny,allow

#  Deny from all

#  Allow from 127.0.0.1

   AuthName "Nagios Access"

   AuthType Basic

   AuthUserFile /usr/local/nagios/etc/htpasswd.users

   Require valid-user

</Directory>


Alias /nagios "/usr/local/nagios/share"

[root@Nagios nagios]# htpasswd -cb /usr/local/nagios/etc/htpasswd.users oldboy 123456  #创建登录nagios的web用户名和密码

Adding password for user oldboy


9.安装nagios插件

[root@Nagios tools]# yum -y install perl-devel

[root@Nagios tools]# tar xf nagios-plugins-1.4.16.tar.gz

[root@Nagios tools]# cd nagios-plugins-1.4.16

[root@Nagios nagios-plugins-1.4.16]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules

[root@Nagios nagios-plugins-1.4.16]# make && make install

[root@Nagios nagios-plugins-1.4.16]# ll /usr/local/nagios/libexec/|wc -l

60  #此处为60-61个左右

[root@Nagios nagios-plugins-1.4.16]# cd ../


10.安装nrpe

[root@Nagios tools]# tar xf nrpe-2.12.tar.gz

[root@Nagios tools]# cd nrpe-2.12

[root@Nagios nrpe-2.12]# ./configure

[root@Nagios nrpe-2.12]# make all

[root@Nagios nrpe-2.12]# make install-plugin

[root@Nagios nrpe-2.12]# make install-daemon

[root@Nagios nrpe-2.12]# make install-daemon-config


11.启动服务与检查

[root@Nagios tools]# /etc/init.d/nagios start

Starting nagios: done.

[root@Nagios tools]# /etc/init.d/httpd start      

Starting httpd:                                        [  OK  ]

[root@Nagios tools]# netstat -tunlp|grep 80

tcp        0      0 :::80                       :::*                        LISTEN      7853/httpd  

[root@Nagios tools]# ps -ef|grep nagios

nagios    7841     1  0 16:31 ?        00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

root      7871 53845  0 16:32 pts/0    00:00:00 grep nagios


最后成果图:

Nagios服务端安装_nagios