Nagios部署维护
- 安装环境及软件版本
系统版本 |
rhel-server-5.3-x86_64 |
IP: |
192.168.19.29 |
Nagios软件 |
nagios-3.5.0.tar.gz |
Nagios插件 |
nagios-plugins-1.4.16.tar.gz |
Apache版本 |
httpd-2.2.24.tar.gz |
Php版本 |
php-5.4.13.tar.gz |
- 为PHP添加GD库
Nagios组件的运行依赖于httpd,gcc和php,php的运行又依赖于GD库
- 下载GD库和php相关组件
zlib-1.2.7.tar.gz
libpng-1.2.29.tar.gz
freetype-2.4.11.tar.gz
jpegsrc.v9.tar.gz
gd-2.0.33.tar.gz
- 按顺序安装GD库
安装zlib:
tar zxvf zlib-1.2.7.tar.gz
cd zlib-1.2.7
./configure
make
make install
安装libpng:
tar zxvf libpng-1.2.29.tar.gz
cd libpng-1.2.29/scripts
mv makefile.linux ../makefile
cd ..
make
make install
注意:这里的makefile不是用./configure生成,而是直接从scripts/里拷贝一个!
安装freetype:
tar zxvf freetype-2.4.11.tar.gz
cd freetype-2.4.11
./configure
make
make install
安装jpeg:
tar zxvf jpegsrc.v9.tar.gz
cd jpeg-9
./configure –enable-shared
make
make test
make install
注意:这里configure一定要带--enable-shared参数,否则不会生成共享库!
安装GD:
tar zxvf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure --with-png --with-freetype --with-jpeg
make
make install
- 编译安装nagios
- 在linux防火墙上开启80,5666端口
- 创建nagios运行所需用户和组
[root@nagios ~]# groupadd nagios [root@nagios ~]# useradd –G nagios nagios [root@nagios ~]#passwd nagios |
- 安装nagios
[root@nagios nagios]# cd software/ [root@nagios software]# tar zxvf nagios-3.5.0.tar.gz [root@nagios software]# cd nagios [root@nagios nagios]# ./configure --prefix=/home/nagios/nagios [root@nagios nagios]# make all [root@nagios nagios]# make install 安装主要程序,CGI及HTML文件 [root@nagios nagios]# make install-init 把nagios做成运行脚本,nagios随开机启动 [root@nagios nagios]# make install-commandmode 给外部命令访问nagios配置文件的权限 [root@nagios nagios]# make install-config 把配置文件的例子复制到nagios的安装目录
|
- 验证程序是否正确安装
[root@nagios nagios]# ll 总计 24 drwxrwxr-x 2 nagios nagios 4096 05-06 10:11 bin drwxrwxr-x 3 nagios nagios 4096 05-06 10:13 etc drwxrwxr-x 2 nagios nagios 4096 05-06 10:11 libexec drwxrwxr-x 2 nagios nagios 4096 05-06 10:11 sbin drwxrwxr-x 10 nagios nagios 4096 05-06 10:11 share drwxrwxr-x 5 nagios nagios 4096 05-06 10:12 var |
如果etc、bin、 sbin、 share、 var、libexec六个目录存在,则表明程序被正确安装,下边是六个目录功能的简要说明:
etc |
Nagios配置文件位置,包括*.cfg文件,对象模板,密码文件 |
bin |
Nagios执行程序所在目录,这个目录只有两个文件nagios,nagiostats |
sbin |
Nagios Cgi文件所在目录,也就是执行外部命令所需文件所在的目录 |
share |
Nagios网页文件所在的目录 |
var |
Nagios日志文件、spid 等文件所在的目录 |
libexec |
Nggios插件安装目录,未装插件之前此目录为空 |
- 安装nagios插件
[root@nagios nagios]# cd software/ [root@nagios software]# tar zxvf nagios-plugins-1.4.16.tar.gz [root@nagios software]# cd nagios-plugins-1.4.16 [root@nagios nagios-plugins-1.4.16]# ./configure --prefix=/home/nagios/nagios [root@nagios nagios-plugins-1.4.16]#make [root@nagios nagios-plugins-1.4.16]#make install
注意:nagios插件指定的安装路径为nagios安装路径/home/nagios/nagios,安装完成后将在目录/home/nagios/nagios/libexec中生成许多插件,这正是nagios所需的。 |
- 安装apache
Apache的运行依赖于apr,apr-util和pcre三个包
- 下载apache依赖包
[root@nagios nagios]# cd software/ [root@nagios software]# wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz [root@nagios software]# wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz [root@nagios software]# wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip |
- 安装apache依赖包
安装apr: [root @nagios software]# tar -zxvf apr-1.4.5.tar.gz [root @nagios software]# cd apr-1.4.5 [root @nagios apr-1.4.5]# ./configure --prefix=/usr/local/apr [root @nagios apr-1.4.5]# make && make install
安装apr-util: [root @nagios software]# tar -zxvf apr-util-1.3.12.tar.gz [root @nagios software]# cd apr-util-1.3.12 [root @nagios apr-util-1.3.12]# ./configure --prefix=/usr/local/apr-util -with- apr=/usr/local/apr/bin/apr-1-config [root @nagios apr-util-1.3.12]# make && make install
安装pcre: [root @nagios software]#unzip -zxvf pcre-8.10.zip [root @nagios software]#cd pcre-8.10 [root @nagios pcre-8.10]#./configure –prefix=/usr/local/pcre [root @nagios pcre-8.10]# make && make install |
- 拷贝ape和apr-util源码到apache源码目录
[root @nagios software]# cp -rf apr-1.4.6 httpd-2.4.1/srclib/apr [root @nagios software]# cp -rf apr-util-1.4.6 httpd-2.4.1/srclib/apr-util |
- 安装apache
[root @nagios software]# tar zxvf httpd-2.2.24.tar.gz [root @nagios software]# cd httpd-2.2.24 [root@nagios httpd-2.2.24]# ./configure --prefix=/home/nagios/apache --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --with-included-apr --enable-so --enable-mods-shared=most [root@nagios httpd-2.2.24]# make [root@nagios httpd-2.2.24]# make install |
- 安装PHP运行环境
[root@nagios ~]# cd /home/nagios/software/gd_software/ [root@nagios gd_software]# tar zxvf php-5.4.13.tar.gz [root@nagios gd_software]# cd php-5.4.13 [root@nagios php-5.4.13]# ./configure --prefix=/opt/php --with-config-file-path=/opt/php --with-apxs2=/home/nagios/apache/bin/apxs [root@nagios php-5.4.13]# make [root@nagios php-5.4.13]# make test =====================================================================
You may have found a problem in PHP. This report can be automatically sent to the PHP QA team at http://qa.php.net/reports and http://news.php.net/php.qa.reports This gives us a better understanding of PHP's behavior. If you don't want to send the report immediately you can choose option "s" to save it. You can then email it to qa-reports@lists.php.net later. Do you want to send this report now? [Yns]: n [root@nagios php-5.4.13]# make install |
注意:PHP应该在apache之后安装,否则无法在apache的modules下生成libphp5.so文件,导致不能登录页面。
- 配置Apache
- 编辑apache/conf/httpd.conf文件
[root@nagios conf]# vi httpd.conf
User example Group example 改为 User nagios Group nagios
<IfModule dir_module> DirectoryIndex index.html </IfModule> 改为 <IfModule dir_module> DirectoryIndex index.php index.html </IfModule>
[root@nagios nagios]# chown -R nagios:nagios apache/ [root@nagios nagios]# chown -R nagios:nagios nagios/
#setting for nagios ScriptAlias /nagios/cgi-bin /home/nagios/nagios/sbin <Directory "/home/nagios/nagios/sbin"> AuthType Basic Options ExecCGI AllowOverride None Order allow,deny Allow from all AuthName "Nagios Access" AuthUserFile /home/nagios/nagios/etc/htpasswd Require valid-user </directory> Alias /nagios /home/nagios/nagios/share <Directory "/home/nagios/nagios/share"> AuthType Basic Options None AllowOverride None Order allow,deny Allow from all AuthName "nagios Access" AuthUserFile /home/nagios/nagios/etc/htpasswd Require valid-user </directory> LoadModule php5_module modules/libphp5.so AddType application/x-httpd-php .php .phtml AddType applicatoin/x-httpd-php-source .phps AddDefaultCharset utf-8 |
- 生成用户验证文件
[root@nagios nagios]# /home/nagios/apache/bin/htpasswd -c /home/nagios/nagios/etc/htpasswd jsbzb New password: Re-type new password: Adding password for user jsbzb
修改生成的密码文件的用户和属组 [root@nagios nagios]# cd nagios/etc/ [root@nagios etc]# chown nagios:nagios htpasswd |
疑问:密码中不能有字母,否则无法登录,只能用数字。
- 启动nagios和apache并登录
- apache配置完成后执行如下命令,检查配置是否正确
[root@nagios etc]# /home/nagios/apache/bin/apachectl -t Syntax OK |
- 用root用户启动nagios和apache
[root@nagios nagios]# ./apache/bin/apachectl start& [root@nagios nagios]# service nagios start |
- 至此,nagios安装完成,验证配置
在浏览器中输入地址:http://192.168.19.29/nagios,出现下图登录等待窗口,输入之前创建的用户和密码登录。
登录成功后进入nagios首页
- 安装nagios的snmp采集插件
nagios-snmp-plugins是一套用Perl编写的通过SNMP方式监控主机的插件程序。
配置check_snmp_int.pl这些插件的使用时需要配置cpan,CPAN是Comprehensive Perl Archive Network的缩写.。它是一个巨大的Perl软件收藏库,收集了大量有用的Perl模块(modules)及其相关的文件。这里主要是使用Perl-Net-SNMP模块。
- 安装Perl-Net-SNMP模块
有两种方式安装:
A)通过CPAN来安装
#perl -MCPAN -e shell cpan> install Net::SNMP |
B) 手工安装
首先去官方网站下载以下几个模块:
Crypt::DES Digest::MD5 Digest::SHA1 Digest::HMAC Net::SNMP |
下载后对于每个模块依次按照下面的方式安装
#tar zxvf *.tar.gz 表示模块名,具体请按上面提到的模块替换 #cd |