Nagios安装部署
@font-face { font-family: 宋体 }
@font-face { font-family: Calibri }
@font-face { font-family: Verdana }
@font-face { font-family: “Calibri Light” }
@font-face { font-family: 仿宋 }
@font-face { font-family: “@宋体” }
@font-face { font-family: “@仿宋” }
p.MsoNormal, li.MsoNormal, div.MsoNormal { mso-style-name: “正文\,正文_alt+`”; mso-style-unhide: no; mso-style-qformat: yes; mso-style-parent: “”; margin: 0 0 0.0001pt; line-height: 150%; mso-pagination: widow-orphan; font-size: 13.5pt; mso-bidi-font-size: 10.0pt; font-family: “Calibri”, “sans-serif”; mso-fareast-font-family: 宋体; mso-bidi-font-family: “Times New Roman”; mso-font-kerning: 1.0pt }
h1 { mso-style-name: “标题 1\,标题 1_alt+1”; mso-style-update: auto; mso-style-priority: 9; mso-style-unhide: no; mso-style-qformat: yes; mso-style-link: “标题 1 Char\,标题 1_alt+1 Char”; margin: 17pt 0 16.5pt; text-indent: 56.2pt; line-height: 240%; mso-pagination: widow-orphan lines-together; page-break-after: avoid; mso-outline-level: 1; font-size: 22pt; font-family: “Calibri”, “sans-serif”; mso-bidi-font-family: “Times New Roman”; mso-font-kerning: 22.0pt; font-weight: bold }
h2 { mso-style-name: “标题 2\,标题 2_alt2”; mso-style-update: auto; mso-style-priority: 9; mso-style-qformat: yes; mso-style-link: “标题 2 Char\,标题 2_alt2 Char”; mso-style-next: “正文\,正文_alt+`”; margin: 13pt 0; line-height: 172%; mso-pagination: widow-orphan lines-together; page-break-after: avoid; mso-outline-level: 2; font-size: 18pt; mso-bidi-font-size: 16.0pt; font-family: “Verdana”, “sans-serif”; mso-fareast-font-family: 宋体; mso-fareast-theme-font: major-fareast; mso-bidi-font-family: “Times New Roman”; mso-bidi-theme-font: major-bidi; mso-font-kerning: 1.0pt; font-weight: bold }
h3 { mso-style-name: “标题 3\,标题 3_alt3”; mso-style-update: auto; mso-style-priority: 9; mso-style-qformat: yes; mso-style-link: “标题 3 Char\,标题 3_alt3 Char”; mso-style-next: “正文\,正文_alt+`”; margin: 13pt 0; line-height: 172%; mso-pagination: widow-orphan lines-together; page-break-after: avoid; mso-outline-level: 3; font-size: 16pt; font-family: “Calibri”, “sans-serif”; mso-bidi-font-family: “Times New Roman”; mso-font-kerning: 1.0pt; font-weight: bold }
h4 { mso-style-name: “标题 4\,标题 4_alt+4”; mso-style-update: auto; mso-style-priority: 9; mso-style-qformat: yes; mso-style-link: “标题 4 Char\,标题 4_alt+4 Char”; mso-style-next: “正文\,正文_alt+`”; margin: 14pt 0 14.5pt; line-height: 156%; mso-pagination: widow-orphan lines-together; page-break-after: avoid; mso-outline-level: 4; font-size: 14pt; font-family: “Calibri Light”, “sans-serif”; mso-ascii-font-family: “Calibri Light”; mso-ascii-theme-font: major-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: major-fareast; mso-hansi-font-family: “Calibri Light”; mso-hansi-theme-font: major-latin; mso-bidi-font-family: “Times New Roman”; mso-bidi-theme-font: major-bidi; mso-font-kerning: 1.0pt; font-weight: bold }
p.MsoHeader, li.MsoHeader, div.MsoHeader { mso-style-priority: 99; mso-style-link: “页眉 Char”; margin: 0 0 0.0001pt; text-align: center; line-height: 150%; mso-pagination: widow-orphan; tab-stops: center 207.65pt right 415.3pt; layout-grid-mode: char; border: none; mso-border-bottom-alt: solid windowtext .75pt; padding: 0; mso-padding-alt: 0cm 0cm 1.0pt 0cm; font-size: 9pt; font-family: “Calibri”, “sans-serif”; mso-fareast-font-family: 宋体; mso-bidi-font-family: “Times New Roman”; mso-font-kerning: 1.0pt }
p.MsoFooter, li.MsoFooter, div.MsoFooter { mso-style-priority: 99; mso-style-link: “页脚 Char”; margin: 0 0 0.0001pt; line-height: 150%; mso-pagination: widow-orphan; tab-stops: center 207.65pt right 415.3pt; layout-grid-mode: char; font-size: 9pt; font-family: “Calibri”, “sans-serif”; mso-fareast-font-family: 宋体; mso-bidi-font-family: “Times New Roman”; mso-font-kerning: 1.0pt }
a:link, span.MsoHyperlink { mso-style-priority: 99; color: rgba(5, 99, 193, 1); mso-themecolor: hyperlink; text-decoration: underline; text-underline: single }
a:visited, span.MsoHyperlinkFollowed { mso-style-noshow: yes; mso-style-priority: 99; color: rgba(149, 79, 114, 1); mso-themecolor: followedhyperlink; text-decoration: underline; text-underline: single }
em { mso-style-name: “强调\,注释强调_alt+9”; mso-style-priority: 20; mso-style-unhide: no; mso-style-qformat: yes; mso-ansi-font-size: 14.0pt; font-family: 仿宋; mso-fareast-font-family: 仿宋; font-weight: bold; mso-bidi-font-weight: normal; font-style: normal }
p { mso-style-noshow: yes; mso-style-priority: 99; mso-margin-top-alt: auto; margin-right: 0; mso-margin-bottom-alt: auto; margin-left: 0; mso-pagination: widow-orphan; font-size: 12pt; font-family: 宋体; mso-bidi-font-family: 宋体 }
pre { mso-style-noshow: yes; mso-style-priority: 99; mso-style-link: “HTML 预设格式 Char”; margin: 0 0 0.0001pt; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; font-size: 12pt; font-family: 宋体; mso-bidi-font-family: 宋体 }
span.MsoIntenseEmphasis { mso-style-priority: 21; mso-style-unhide: no; mso-style-qformat: yes; color: rgba(91, 155, 213, 1); mso-themecolor: accent1; font-weight: bold; font-style: italic }
{ mso-style-name: “标题 1 Char\,标题 1_alt+1 Char”; mso-style-priority: 9; mso-style-unhide: no; mso-style-locked: yes; mso-style-link: “标题 1\,标题 1_alt+1”; mso-ansi-font-size: 22.0pt; mso-bidi-font-size: 22.0pt; mso-font-kerning: 22.0pt; font-weight: bold }
{ mso-style-name: “标题 2 Char\,标题 2_alt2 Char”; mso-style-priority: 9; mso-style-unhide: no; mso-style-locked: yes; mso-style-link: “标题 2\,标题 2_alt2”; mso-ansi-font-size: 18.0pt; mso-bidi-font-size: 16.0pt; font-family: “Verdana”, “sans-serif”; mso-ascii-font-family: Verdana; mso-fareast-font-family: 宋体; mso-fareast-theme-font: major-fareast; mso-hansi-font-family: Verdana; mso-bidi-font-family: “Times New Roman”; mso-bidi-theme-font: major-bidi; font-weight: bold }
{ mso-style-name: “标题 3 Char\,标题 3_alt3 Char”; mso-style-priority: 9; mso-style-unhide: no; mso-style-locked: yes; mso-style-link: “标题 3\,标题 3_alt3”; mso-ansi-font-size: 16.0pt; mso-bidi-font-size: 16.0pt; font-weight: bold }
{ mso-style-name: “标题 4 Char\,标题 4_alt+4 Char”; mso-style-priority: 9; mso-style-unhide: no; mso-style-locked: yes; mso-style-link: “标题 4\,标题 4_alt+4”; mso-ansi-font-size: 14.0pt; mso-bidi-font-size: 14.0pt; font-family: “Calibri Light”, “sans-serif”; mso-ascii-font-family: “Calibri Light”; mso-ascii-theme-font: major-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: major-fareast; mso-hansi-font-family: “Calibri Light”; mso-hansi-theme-font: major-latin; mso-bidi-font-family: “Times New Roman”; mso-bidi-theme-font: major-bidi; font-weight: bold }
span.Char { mso-style-name: “页眉 Char”; mso-style-priority: 99; mso-style-unhide: no; mso-style-locked: yes; mso-style-link: 页眉; mso-ansi-font-size: 9.0pt; mso-bidi-font-size: 9.0pt }
span.Char0 { mso-style-name: “页脚 Char”; mso-style-priority: 99; mso-style-unhide: no; mso-style-locked: yes; mso-style-link: 页脚; mso-ansi-font-size: 9.0pt; mso-bidi-font-size: 9.0pt }
p.alt0, li.alt0, div.alt0 { mso-style-name: 代码_alt+0; mso-style-update: auto; mso-style-unhide: no; mso-style-qformat: yes; mso-style-next: “正文\,正文_alt+`”; margin: 0 0 0.0001pt; text-indent: 28pt; line-height: 150%; mso-pagination: widow-orphan; background: rgba(231, 230, 230, 1); mso-background-themecolor: background2; border: none; mso-border-alt: solid windowtext 1px; padding: 0; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; font-size: 13.5pt; mso-bidi-font-size: 10.0pt; font-family: “Calibri”, “sans-serif”; mso-fareast-font-family: 宋体; mso-bidi-font-family: “Times New Roman”; mso-font-kerning: 1.0pt }
span.HTMLChar { mso-style-name: “HTML 预设格式 Char”; mso-style-noshow: yes; mso-style-priority: 99; mso-style-unhide: no; mso-style-locked: yes; mso-style-link: “HTML 预设格式”; mso-ansi-font-size: 12.0pt; mso-bidi-font-size: 12.0pt; font-family: 宋体; mso-ascii-font-family: 宋体; mso-hansi-font-family: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt }
.MsoChpDefault { mso-style-type: export-only; mso-default-props: yes; font-size: 10pt; mso-ansi-font-size: 10.0pt; mso-bidi-font-size: 10.0pt; font-family: “Calibri”, “sans-serif”; mso-ascii-font-family: Calibri; mso-fareast-font-family: 宋体; mso-hansi-font-family: Calibri }
.MsoPapDefault { mso-style-type: export-only; line-height: 150% }
@page { mso-page-border-surround-header: no mso-page-border-surround-footer: no }
@page WordSection1 { size: 595.3pt 841.9pt margin-top: 36pt margin-right: 36pt margin-bottom: 36pt margin-left: 36pt mso-header-margin: 42.55pt mso-footer-margin: 49.6pt mso-paper-source: 0 layout-grid: 18.35pt }
div.WordSection1 { page: WordSection1 }
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