首页 / IOS / Nagios安装部署
Nagios安装部署
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Nagios安装部署,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含10495字,纯文字阅读大概需要15分钟。
内容图文
![Nagios安装部署](/upload/InfoBanner/zyjiaocheng/1082/6ca30a47a6d144b9bc697765212efc0c.jpg)
Nagios 安装
Nagios 工作原理
Nagios 的功能是监控服务和主机,但是他自身并不包括这部分功能,所有的监控、检测功能都是通过各种插件来完成的。
启动 Nagios 后,它会周期性的自动调用插件去检测服务器状态,同时 Nagios 会维持一个队列,所有插件返回来的状态信息都进入队列, Nagios 每次都从队首开始读取信息,并进行处理后,把状态结果通过 web 显示出来。
Nagios 提供了许多插件,利用这些插件可以方便的监控很多服务状态。安装完成后,在 nagios 主目录下的 /libexec 里放有 nagios 自带的可以使用的所有插件,如, check_disk 是检查磁盘空间的插件, check_load 是检查 CPU 负载的,等等。每一个插件可以通过运行 ./check_xxx –h 来查看其使用方法和功能。
Nagios 可以识别 4 种状态返回信息,即 0(OK) 表示状态正常 / 绿色、 1(WARNING) 表示出现警告 / 黄色、 2(CRITICAL) 表示出现非常严重的错误 / 红色、 3(UNKNOWN) 表示未知错误 / 深黄色。 Nagios 根据插件返回来的值,来判断监控对象的状态,并通过 web 显示出来,以供管理员及时发现故障。
四种监控状态
再说报警功能,如果监控系统发现问题不能报警那就没有意义了,所以报警也是 nagios 很重要的功能之一。但是,同样的, Nagios 自身也没有报警部分的代码,甚至没有插件,而是交给用户或者其他相关开源项目组去完成的。
Nagios 安装,是指基本平台,也就是 Nagios 软件包的安装。它是监控体系的框架,也是所有监控的基础。
知道 Nagios 是如何通过插件来管理服务器对象后,现在开始研究它是如何管理远端服务器对象的。 Nagios 系统提供了一个插件 NRPE 。 Nagios 通过周期性的运行它来获得远端服务器的各种状态信息。它们之间的关系如下图所示:
Nagios 通过 NRPE 来远端管理服务
1. Nagios 执行安装在它里面的 check_nrpe 插件,并告诉 check_nrpe 去检测哪些服务。
2. 通过 SSL , check_nrpe 连接远端机子上的 NRPE daemon
3. NRPE 运行本地的各种插件去检测本地的服务和状态 (check_disk,..etc)
4. 最后, NRPE 把检测的结果传给主机端的 check_nrpe , check_nrpe 再把结果送到 Nagios 状态队列中。
5. Nagios 依次读取队列中的信息,再把结果显示出来。
实验环境
Host Name |
OS |
IP |
Software |
Nagios-Server |
CentOS 6.5 |
192.168.44.100 |
LAMP 、 Nagios 、 nagios-plugins 、 nrpe |
Nagios-Linux |
CentOS 6.5 |
192.168.44.200 |
nagios-plugins 、 nrpe 、 |
LAMP 环境安装
注意:先安装 MySQL 和 Apache, 后安装 PHP, 因为 PHP 配置编译的时候需要指定 mysql 路径和 apache 路径。
需要用到软件:
http-2.2.4.tar.gz
mysql-5.6.22-linux-glibc2.5-x86_64.tar.gz
php-5.3.27.tar.gz
安装 Apache
解压
先查看 Linux 是 64 位 , 就上传 64 的源码包。
配置编译
[root@darker src]# cd httpd-2.2.4
[root@darker httpd-2.2.4]# ./configure \
--prefix=/usr/local/apache2 \
--with-included-apr \
--enable-so \
--enable-deflate=shared \
--enable-expires=shared \
--enable-rewrite=shared \
--with-pcre
使用 echo $? 如果返回 0 代表没有问题 如果返回 1 代表安装错误
编译安装
常见问题分析
错误: error: mod_deflate has been requested but can not be built due to prerequisite failures
解决: yum -y install zlib-devel
安装 MySQL
解包
初始化
mv mysql-5.6.22-linux-glibc2.5-x86_64 /usr/local/mysql
useradd -s /sbin/nologin -M mysql
cd /usr/local/mysql/
mkdir -p /data/mysql
chown -R mysql.mysql /data/mysql/
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
配置
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3007
server_id = 1
启动
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
ln -s /usr/local/mysql/bin/mysql /usr/bin/
常见问题分析
error while loading shared libraries: libaio.so.1
解决: yum -y install libaio
错误: Starting MySQL.The server quit without updating PID file (/[FAILED]ql/darker.pid).
InnoDB: mmap(137363456 bytes) failed; errno 12
[ERROR] InnoDB: Cannot allocate memory for the buffer pool
[ERROR] Plugin ‘InnoDB‘ init function returned error.
[ERROR] Plugin ‘InnoDB‘ registration as a STORAGE ENGINE failed.
[ERROR] Unknown/unsupported storage engine: InnoDB
[ERROR] Aborting
解决: innodb_buffer_pool_size = 8M
将 innodb 修改为 8M 由于服务器内存过小导致
安装 PHP
解压
cd /usr/local/src/
tar -zxf php-5.3.27.tar.gz
cd php-5.3.27
配置编译
[root@darker php-5.3.27]# ./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-bz2 \
--with-openssl \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-mbstring \
--enable-sockets \
--enable-exif \
--disable-ipv6
echo $?
make
echo $?
编译安装
make install
echo $?
配置文件
cp php.ini-production /usr/local/php/etc/php.ini
常见问题分析
配置编译报错
错误: configure: error: xml2-config not found. Please check your libxml2 installation.
解决: yum -y install libxml2-devel
错误: configure: error: Cannot find OpenSSL‘s <evp.h>
解决: yum install -y openssl openssl-devel
错误: configure: error: Please reinstall the BZip2 distribution
解决:yum install -y bzip2 bzip2-devel
错误: configure: error: jpeglib.h not found.
解决: yum install -y libjpeg-devel
错误: configure: error: png.h not found.
解决: yum install -y libpng libpng-devel
错误: configure: error:freetype.h not found.
解决: yum install -y freetype freetype-devel
错误: configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决: rpm -ivh http://www.lishiming.net/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm
yum install -y libmcrypt-devel
编译安装报错
错误:make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
这是由于内存小于1G所导致. 在./configure加上选项:
解决: --disable-fileinfo
错误:Disable fileinfo support 禁用 fileinfo
需重新编译
错误:make: *** [libphp5.la] Error 1
解决: yum -y install libtool libtool-ltdl-devel
安装完后直接make
Apache 结合 PHP
修改配置文件
vim /usr/local/apache2/conf/httpd.conf
AddType application/x-httpd-php .php
DirectoryIndex index.php index.html index.htm
ServerName localhost:80
测试 LAMP 是否成功
/usr/local/apache2/bin/apachectl -t 测试配置文件
/usr/local/apache2/bin/apachectl start 启动 httpd
Nagios 服务端安装
安装前准备
需要用到软件:
nagios-4.0.8.tar.gz
nagios-plugins-2.0.3.tar.gz
nrpe-2.15.tar.gz
yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel
安装 nagios 需要这个基础支持套件
useradd -s /sbin/nologin nagios 创建 nagios 用户 , 但不允许登陆
mkdir /usr/local/nagios 创建 nagios 目录
chown -R nagios.nagios /usr/local/nagios 给目录赋予属主或者属组
解压
cd /usr/local/src 进入源码包
tar -xf nagios-4.0.8.tar.gz 解压
cd nagios-4.0.8 进入目录
配置编译
./configure --prefix=/usr/local/nagios/ \
--with-nagios-user=nagios \
--with-nagios-group=nagios
编译安装
make all 编译所有
make install 编译安装
make install-init 把 nagios 做成一个运行脚本,使 nagios 开机启动
make install-commandmode 把配置文件样例复制到 nagios 的安装目录
make install-config 给外部命令访问 nagios 配置文件的权限
chkconfig --add nagios 将 nagios 添加到系统服务
chkconfig --level 35 nagios on 设置 3 5 开启
验证安装
切换目录到安装路径(这里是 /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 |
用来存放外部命令文件的目录 |
Ngios-plugins 插件
解压
cd /usr/local/src 进入源码包目录
tar -zxf nagios-plugins-2.0.3.tar.gz 解压 plugins
cd nagios-plugins-2.0.3 进入 plugins 目录
配置编译
./configure--prefix=/usr/local/nagios \
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--with-mysql=/usr/local/mysql
编译安装
make 编译
make install 编译安装
验证安装
/usr/local/nagios/libexex/ 下是否有很多 check 文件
有成功,无就重新安装
常见问题分析
错误: ./check_mysql: error while loading shared libraries: libmysqlclient.so.18
解决: ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
NagiosWeb 配置
usermod -G nagios apache
把 apache 加入到 nagios 组,便于在通过 web 操作 nagios 时能够具有足够的权限
源码编译 apache 配置 web 接口
vim /usr/local/apache2/conf/httpd.conf 修改配置文件
添加配置信息
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>
/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin
提示输入密码: darker
确认密码: darker
YUM 安装 apache 配置 web 接口
yum install httpd yum 安装 Apache
安装 Nagios 的 web 配置文件到 Apache 的 conf.d 目( /etc/httpd/conf.d ):
在 Nagios 源码安装包里 make install-webconf
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
创建访问 Nagios Web 页面的用户名和密码
启动 Nagios
在启动前先检测一下 Apache
/usr/local/apache2/bin/apachectl -t 验证配置文件是否有错误
/usr/local/apache2/bin/apachectl graceful 重新加载修改后配置文件
在启动前先检测一下 nagios
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果最后显示如下,则说明配置没有问题了。
Total Warnings: 0
Total Errors: 0
service nagios start 启动 nagios
访问 nagios
用户名: nagiosadmin
密码: darker
原文:http://www.cnblogs.com/xuliangwei/p/6337920.html
内容总结
以上是互联网集市为您收集整理的Nagios安装部署全部内容,希望文章能够帮你解决Nagios安装部署所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。