centos7 实测 nagios 安装

Nagios是一套开源的监控系统,可监控你的系统和网络.
Nagios最新版本是Nagios Core 4.3.4,Nagios plugins 2.2.1.
目前支持RHEL 7.x/6.x/5.x, CentOS 7.x/6.x/5.x 等系统.本文以CentOS7为平台.

安装Nagios 4.3.4 and Nagios Plugin 2.2
假如你根据本手册正确安装后,你应该能找到以下信息:

nagios,plugin安装目录 /usr/local/nagios
默认监控本机服务(Disk Usage, CPU Load, Current Users, Total Processes)
可以通过浏览器访问 http://localhost/nagios
step1 安装依赖软件
安装需要apache,php,gcc等.
1
[root@host]# yum install -y httpd httpd-tools php gcc glibc glibc-common gd gd-devel make net-snmp
1
step2 创建nagios用户和用户组
创建nagios用户和组,并设置密码
1
[root@host] useradd nagios
[root@host] groupadd nagcmd
1
2
将nagios和apache加入 nagios组
1
[root@host]usermod -G nagcmd nagios
[root@host] usermod -G nagcmd apache
1
2
step3 下载nagios4.3,nagios plugin 2.2
创建一个nagios下载目录

[root@host]# mkdir /root/nagios
[root@host]# cd /root/nagios
1
2
适用wget 下载最新版本

[root@host]# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.4.tar.gz
[root@host]# wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
1
2
step4 解压
[root@host nagios~]# tar -xvf nagios-4.3.4.tar.gz
[root@hostnagios~]# tar -xvf nagios-plugins-2.2.1.tar.gz
1
2
解压后有2个新的文件夹

[root@host nagios ~]# ls -l
drwxrwxr-x 18 root root 4096 Aug 24 17:43 nagios-4.3.4
drwxr-xr-x 15 root root 4096 Apr 19 12:04 nagios-plugins-2.2.1
1
2
3
配置Nagios
进入nagios目录,进行配置

[root@host nagios~]# cd nagios-4.3.4/
[root@host nagios-4.3.4 ]# ./configure --with-command-group=nagcmd
1
2
sample配置文件:

Creating sample config files in sample-config/ ...

*** Configuration summary for nagios 4.3.4 2017-08-24 ***:

General Options:
-------------------------
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagcmd
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Install ${includedir}: /usr/local/nagios/include/nagios
Lock file: /run/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /etc/rc.d/init.d
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /usr/bin/mail
Host OS: linux-gnu
IOBroker Method: epoll

Web Interface Options:
------------------------
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /usr/bin/traceroute


Review the options above for accuracy. If they look okay,
type 'make all' to compile the main program and CGIs.


编译,安装包

[root@host nagios-4.3.4 ]# make all
[root@host nagios-4.3.4 ]# make install

*** Exfoliation theme installed ***
NOTE: Use 'make install-classicui' to revert to classic Nagios theme

make[1]: Leaving directory `/root/nagios/nagios-4.3.4'
make install-basic
make[1]: Entering directory `/root/nagios/nagios-4.3.4'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/archives
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/spool/checkresults
chmod g+s /usr/local/nagios/var/spool/checkresults

*** Main program, CGIs and HTML files installed ***

You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

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/nagios/nagios-4.3.4'

安装初始化init脚本

[root@host nagios-4.3.4 ]# make install-init
1
安装命令行运行脚本

[root@host nagios-4.3.4 ]# make install-commandmode
1
安装样本脚本

[root@host nagios-4.3.4 ]# 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.

step 5 按自己需求配置
配置联系人

# vi /usr/local/nagios/etc/objects/contacts.cfg

###############################################################################
###############################################################################
#
# CONTACTS
#
###############################################################################
###############################################################################

# Just one contact defined by default - the Nagios admin (that's you)
# This contact definition inherits a lot of default values from the 'generic-contact'
# template which is defined elsewhere.

define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user

email admin@tecmint.com ; *** CHANGE THIS TO YOUR EMAIL ADDRESS ****
}


step 6 安装配置web接口
配置web接口,首先会创建管理员账号 nagiosadmin,并要求输入管理密码

[root@host nagios-4.3.4 ]# make install-webconf

[root@host nagios-4.3.4]# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

重启apache,使配置生效

[root@host ]# service httpd start 
[root@host ]# systemctl start httpd.service 
1
2
step7 编译安装nagios plugin
按如下命令运行

[root@host nagios]# cd /root/nagios
[root@host nagios]# cd nagios-plugins-2.2.1/
[root@host nagios]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@host nagios]# make
[root@hostt nagios]# make install

step8 验证nagios配置文件
已经完成所有安装,按一下命令验证配置文件

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

Nagios Core 4.3.4
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2017-08-24
License: GPL

Website: https://www.nagios.org
Reading configuration data...
Read main config file okay...
Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
Checked 8 services.
Checked 1 hosts.
Checked 1 host groups.
Checked 0 service groups.
Checked 1 contacts.
Checked 1 contact groups.
Checked 24 commands.
Checked 5 time periods.
Checked 0 host escalations.
Checked 0 service escalations.
Checking for circular paths...
Checked 1 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors: 0

Things look okay - No serious problems were detected during the pre-flight check

step 9 将nagios加到系统服务中
[root@host ]# systemctl enable nagios
[root@host ]# systemctl enable httpd
[root@host]# systemctl start nagios.service 
1
2
3
Step 10: 适用浏览器访问nagios
在浏览器中输入 “http://Your-server-IP-address/nagios” or “http://FQDN/nagios” ,并输入账号和密码.

 

host view


service view


补充一下,升级nagios3到nagios4
假如你是旧版本,你可以随时升级到最新版本,你可以下载最新版本,按以下命令升级.

[root@host ]# service nagios stop
[root@host ]# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.4.tar.gz
[root@host ]# tar -zxvf nagios-4.3.4.tar.gz
[root@host ]# cd nagios-4.3.4
[root@host ]# ./configure
[root@host ]# make all
[root@host ]# make install
[root@host ]# service nagios start
--------------------- 
作者:CSDN1887 
来源:CSDN 
原文:https://blog.csdn.net/csdn1887/article/details/83022323 

posted @ 2019-03-29 16:11  菜鸟起飞中  阅读(166)  评论(0编辑  收藏  举报