Linux下nagios的安装与配置
一、Nagios客户端配置
1. 安装http和mysql
# yum -y install httpdgettext mysql mysql-server mysql-devel php php-mysql php-pear php-mysql mysqlperl mysql-server perl-DBI perl-DBD-MySQL httpd gcc glibc glibc-common gdgd-devel php gcc automake autoconf libtool make

10余年的镶黄网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。
营销型网站的优势是能够根据用户设备显示端的尺寸不同,自动调整镶黄建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。
成都创新互联从事“
镶黄网站设计”,“
镶黄网站推广”以来,每个客户项目都认真落实执行。
2. 创建nagios用户和用户组
#useradd -s /sbin/nologinnagios
#useradd –s /sbin/nologinapache
#echo "nagios" |passwd --stdin nagios
#groupadd nagcmd
#usermod -G nagcmd nagios
3. 安装Nagios 插件
先安装plugins插件在安装nrpe
1) 安装nagios-plugins
# wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
# tar zxvf nagios-plugins-2.1.1.tar.gz
# cd nagios-plugins-2.1.1
# ./configure--prefix=/usr/local/nagios
# make&& make install
2) 安装nrpe
# wget --no-check-certificate http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
#tar xf nrpe-2.15.tar.gz
# cd nrpe-2.15
# ./configure && make && make install
cp sample-config/nrpe.cfg.in /usr/local/nagios/etc/
cp init-script /etc/init.d/nrpe
chmod +x /etc/init.d/nrpe
vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=192.168.104.60
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20%-c 10%
服务启动
/etc/init.d/nrpe restart
service nagios restart
service httpd restart
service mysqld restart
一、 Nagios服务端安装
1. 基础支持套件:gcc glibc glibc-common gd gd-devel xinetd openssl-devel gettext automake autoconf libtool make
#
yuminstall -y gcc glibc glibc-common gdgd-devel xinetd openssl-devel gettext automake autoconf libtool make
2. 创建nagios用户和用户组
#useradd -s /sbin/nologinnagios
#useradd –s /sbin/nologinapache
#echo "nagios" |passwd --stdin nagios
#groupadd nagcmd
#usermod -G nagcmd nagios
#usermod -G nagcmd apache
#mkdir -p /usr/local/nagios

查看nagios 目录的权限
#ll -d /usr/local/nagios/

3. 编译安装Nagios
# wget --no-check-certificatehttps://sourceforge.net/projects/nagios-cn/files/sourcecode/zh_CN%203.2.3/nagios-cn-3.2.3.tar.bz2
# tar xfnagios-cn-3.2.3.tar.bz2
#cd nagios-cn-3.2.3
#./configure --prefix=/usr/local/nagios/ --with-nagios-user=nagios--with-nagios-group=nagios --with-command-group=nagcmd


# make all

# makeinstall

# makeinstall-init

# makeinstall-commandmode

# makeinstall-config

# chkconfig--add nagios
# chkconfig--level 35 nagios on
# chkconfig--list nagios

1. 验证程序是否被正确安装
切换目录到安装路径(这里是/usr/local/nagios),看是否存在etc、bin、sbin、share、var这五个目录,如果存在则可以表明程序被正确的安装到系统了。Nagios各个目录用途说明如下:
bin | Nagios可执行程序所在目录 |
etc | Nagios配置文件所在目录 |
sbin | Nagios CGI文件所在目录,也就是执行外部命令所需文件所在的目录 |
share | Nagios网页文件所在的目录 |
libexec | Nagios外部插件所在目录 |
var | Nagios日志文件、lock等文件所在的目录 |
var/archives | Nagios日志自动归档目录 |
var/rw | 用来存放外部命令文件的目录 |
1. 安装Nagios 插件
先安装plugins插件在安装nrpe
1) 安装nagios-plugins
# wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
# tar zxvf nagios-plugins-2.1.1.tar.gz
# cd nagios-plugins-2.1.1
# ./configure--prefix=/usr/local/nagios
# make&& make install


2) 安装nrpe
NRPE是监控软件nagios的一个扩展,它被用于被监控的服务器上,向nagios监控平台提供该服务器的一些本地的情况。例如,cpu负载、内存使用、硬盘使用等等。NRPE可以称为nagios的for linux 客户端。
# wget --no-check-certificate http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
#tar xf nrpe-2.15.tar.gz
# cd nrpe-2.15
# ./configure && make && make install
3) 安装nagiosQL
NagiosQL是专为nagios设计的web图形化管理应用,主要作用就是操作数据库和配置文件,其中包括将配置文件的信息写到数据库中,在数据库中修改Nagios的监控配置信息,并将数据库中存放的配置更新到文件中。用户可以通过NagiosQL提供的Web页面直观的修改配置。实现架构很简单,功能很实用。
Nagiosql功能介绍:
1. 具有基本的nagios的配置管理能力,导入,导出配置文件的功能
2. 具有nagios配置文件检查、排错的能力
3. Nagiosql可对文件结构进行定制,可延续之前的配置结构,按IP生成配置
4. Nagiosql将每一次配置的变更做一次配置备份,以时间戳为后缀保存,理论上可以回滚到任意一个历史配置
# wget --no-check-certificatehttp://downloads.sourceforge.net/project/nagiosql/nagiosql/NagiosQL%203.1.1/nagiosql_311.tar.gz
# tar xf nagiosql_311.tar.gz
# cp -R nagiosql /usr/local/nagios/nagiosql
# mkdir -p/etc/nagiosql/{hosts,services,backup/{,hosts,services},import}
# chown -R apache:nagios /etc/nagiosql/
# chmod -R 755 /etc/nagiosql
# chmod 777 /usr/local/nagios/nagiosql/config
# chown nagios:apache /usr/local/nagios/etc
# chown nagios:apache /usr/local/nagios/etc/{nagios.cfg,cgi.cfg}
# chown nagios:apache /usr/local/nagios/etc/*
# chmod 664 /usr/local/nagios/etc/{nagios.cfg,cgi.cfg}
# chmod 775 /usr/local/nagios/etc
# chown nagios:apache /usr/local/nagios/bin/nagios
# chmod 750 /usr/local/nagios/bin/nagios
# chown -R apache.nagios /usr/local/nagios/var/spool/
# chown nagios:apache /usr/local/nagios/var/rw/nagiosNaNd
# chmod 660 /usr/local/nagios/var/rw/nagiosNaNd
2. 安装与配置http、mysql和Phpls
http和Php 不是安装nagios 所必须的,但是nagios提供了web监控界面,通过web监控界面可以清晰的看到被监控主机、资源的运行状态,因此,安装一个web服务是很必要的。 需要注意的是,nagios在nagios3.1.x版本以后,配置web监控界面时需要php的支持。这里我们下载的nagios版本为nagios-cn-3.2.3,因此在安装完成http后,还需要编译php模块,
安装http、mysql和php
1) yum安装
# yum install -y httpd phpphp-mysql php-pear perl-DBD-MySQL perl perl-DBImysql mysql-server mysql-devel

2) 配置http
编辑nagios的文件,路径:/etc/httpd/conf.d/nagios.conf
#vim /etc/httpd/conf.d/nagios.conf
Alias/nagiosQL "/usr/local/nagios/nagiosql"
#SSLRequireSSL
OptionsNone
AllowOverrideNone
Orderallow,deny
Allowfrom all
找的httpd.conf文件,路径:/etc/httpd/conf/httpd.con
#vim /etc/httpd/conf/httpd.con
添加如下内容:
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.users
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.users
Require valid-user
3) 启动http、mysql、nagios服务
# service nagios restart
# service httpd restart
# service mysqld restart
4) 注册服务
# chkconfig nagios on
# chkconfig httpd on
# chkconfig mysqld on
5) 建立nagios的安装文件
# touch/usr/local/nagios/nagiosql/install/ENABLE_INSTALLER
6) 手动安装nagiosql
打开浏览器:http://本机的IP/nagiosQL

测试所需环境通过,直接按下一步即可

配置数据库,选择默认即可。

删除安装目录,这里使用改权限:
# chmod 000/usr/local/nagios/nagiosql/install

1. nagioSQL配置
浏览器输入http://本机的IP/nagiosQL输入用户名和密码

点击 管理-域-localhost---点“修改”

nagios基目录/usr/local/nagios/etc/
导入路径/etc/nagiosql/import/
nagios命令文件/usr/local/nagios/var/rw/nagiosNaNd
nagios进程文件/usr/local/nagios/var/nagios.lock
nagios配置文件/usr/local/nagios/etc/nagios.cfg

工具-导入数据 右边会列出一些配置文件,选择导入即可。
导入只是把配置文件内容导入到Mysql数据库,而使用其配置文件时,是一个个cfg文件,所以下面要进行写入过程


工具-nagios控制-写入检测数据-写入其他数据
检查配置文件成功

写入之后就可以看到相应的cfg文件了,查看写入是否成功
ls /etc/nagisql/

vim/usr/local/nagios/etc/nagios.cfg
将cfg_file开头全部注释
然后添加如下语句
cfg_dir=/etc/nagiosql/hosts/
cfg_dir=/etc/nagiosql/services/
cfg_file=/etc/nagiosql/commands.cfg
cfg_file=/etc/nagiosql/contactgroups.cfg
cfg_file=/etc/nagiosql/contacts.cfg
cfg_file=/etc/nagiosql/contacttemplates.cfg
cfg_file=/etc/nagiosql/hostdependencies.cfg
cfg_file=/etc/nagiosql/hostescalations.cfg
cfg_file=/etc/nagiosql/hostextinfo.cfg
cfg_file=/etc/nagiosql/hostgroups.cfg
cfg_file=/etc/nagiosql/hosttemplates.cfg
cfg_file=/etc/nagiosql/servicedependencies.cfg
cfg_file=/etc/nagiosql/serviceescalations.cfg
cfg_file=/etc/nagiosql/serviceextinfo.cfg
cfg_file=/etc/nagiosql/servicegroups.cfg
cfg_file=/etc/nagiosql/servicetemplates.cfg
cfg_file=/etc/nagiosql/timeperiods.cfg
检查nagios配置文件
/usr/local/nagios/bin/nagios -v/usr/local/nagios/etc/nagios.cfg
重启nagios
/etc/init.d/nagios restart
2. nagioSQL添加监控主机
1.登录nagiosqlweb管理界面
浏览器访问192.168.200.166/nagiosQL
2.添加命令
点击命令—定义—添加,然后输入要添加的命令。

1) 添加nrpe命令

2) 添加监控主机
进入nagiosQL管理控制台点 监督-host-添加

列如:添加一个test的主机,添加内容如下
注意:保存完主机配置后,还需要单击写入按钮,否则无效。

3) 添加监控服务
监督-服务-添加

添加服务内容如下:

配置名称:imp_check_swap //注:这里的配置名称一定和已监控主机的相关项目的配置文件名一致,
服务描述:linux_swap //自定义
检查命令:check_nrpe //前面定义好的命令
$ARG1$: check_swap//在被监控主机定义好的命令
单击保存按钮,添加完成记得要点写入配置。

然后在主机端关联刚才自定义好的服务,操作过程如下图所示:
在监督—host选项中找到已添加好的被监控的主机,我这里被监控的主机是test,单击后面的修改。



注意:别忘记了写入操作,否则无效。
4) 最后重启服务,是配置文件生效

3. 查看nagios监控界面,验证监控效果。

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享文章:web+nagios+nagiosql安装部署-创新互联
文章网址:
http://njwzjz.com/article/dsjpgs.html