Nagios 系统监控管理篇
一、安装准备:
RPM包:gcc, perl, gd, gd-devel, jpeg, jpeg-devel,libpng, libpng-devel, openssl, openssl-devel
软件包:httpd-2.2.6.tar.gz, php-5.3.4.tar.gz, pnp-latest.tar.gz, rrdtool-1.0.50.tar.gz
mysql-5. 5.6.tar.gz,nagios-2.9.tar.gz, nagios-plugins-1.4.9.tar.gz, nrpe-2.12.tar.gz
check_traffic.tar.gz, nagiosgraph.tar.gz
二、监控端安装过程:
1、RPM包安装:
yum �Cy installgcc perl gd gd-devel jpeg jpeg-devellibpng libpng-devel openssl openssl-devel net-snmp cgi rrdtool rrdtool-devel
2、基本软件包安装:
1)Apache安装:
tar zxvfhttpd-2.2.6.tar.gz
cd httpd-2.2.6
./configure �Cprefix=/usr/local/app/apache2
make && make install
2)Mysql安装:
tar zxvfmysql-5. 5.6.tar.gz
mv mysql-5.5.6 /usr/local/mysql
groupadd mysql
useradd -d /usr/local/mysql �Cs/sbin/nologin �Cg mysql
chown �CR mysql:mysql /usr/local/mysql
mkdir �Cp /u1/mysql/data
mkdir �Cp /u1/mysql/log
chown �CR mysql:mysql /u1/mysql
cd /usr/local/mysql
#修改主配置文件my.cnf
basedir = /usr/local/mysql
datadir =/u1/mysql/data
bind-address =192.168.0.210
port = 3306
socket =/tmp/mysql.sock
log-bin =/u1/mysql/logs/mysql-bin
innodb_log_group_home_dir = /u1/mysql/logs
./scripts/mysql_install_db �Cuser=mysql�Cdefaults-file=/usr/local/mysql/my.cnf
cp support-files/my-medium.cnf /etc/my.cnf#有提示输入y
cp support-files/mysql.server /etc/init.d/mysqld
bin/mysqld_safe --user=mysql &#后台启动mysql服务,ctrl+c退出或者Enter退出
vim /etc/profile#设环境变量,添加如下内容(重启生效)
PATH=$PATH:/usr/local/mysql/bin/
export PATH
mysql#登录数据库(正确登录,表示安装完成)
vim start.sh#建立启动脚本文件,添加如下一行内容
/usr/local/mysql/bin/mysqld--defaults-file=/usr/local/mysql/my.cnf &
chmod +x start.sh#添加可执行权限
3)php安装:
mkdir �Cp /usr/local/app/php
tar zxvf php-5.4.8.tar.gz
cd php-5.4.8
yuminstall bison
./configure \
--prefix=/usr/local/app/php\
--with-mysql=/usr/local/mysql\
--with-apxs2=/usr/local/app/apache2/bin/apxs\
--with-gd--with-jpeg-dir=/usr/lib --enable-gd-native-ttf \
--with-zlib-dir=/usr/lib--with-png-dir=/usr/lib \
--with-freetype-dir=/usr/include/freetype2\
--enable-sockets--enable-ftp --enable-mbstring
libtool --finish /u1/tool/php-5.4.8/libs
make&& make install
cp php.ini-development /usr/local/app/php/lib/php.ini
cd /usr/local/app/php/etc
cp php-fpm.conf.default php-fpm.conf
4)nagios安装:
mkdir /usr/local/nagios
groupadd nagios
useradd �Cg nagios nagios
chown -R nagios.nagios /usr/local/nagios
tar -zxvf nagios-2.9.tar.gz
cd nagios-2.9
./configure --prefix=/usr/local/nagios --with-gd-lib=/usr/local/lib --with-gd-inc=/usr/local/include
make all
make install #安装主程序,CGI和HTML文件
make install-init #在/etc/rc.d/init.d安装启动脚本
make install-commandmode #配置目录权限
make install-config #安装示例配置文件,安装的路径是#/usr/local/nagios/etc
5)插件nagios-plugins安装:
tar -zxvf nagios-plugins-1.4.9.tar.gz
cd nagios-plugins-1.4.9
./configure --prefix=/usr/local/nagios/--enable-redhat-pthread-workaround
make && makeinstall
1)注意:在redhat系统上面安装可能出现configure时,到这里checking for redhat spopen problem...就不动了,所以需要在configure时再加上--enable-redhat-pthread-workaround;
6)插件nagiosgraph安装:
tar�Czxvf nagiosgraph.tar.gz
cp�Ca nagiosgraph /usr/local/nagios/.
7)插件check_traffic安装:
tar �Czxvf check_traffic.tar.gz
cpcheck_traffic/check_traffic /usr/local/nagios/libexec/.
8)插件nrpe安装:
tar �Czxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --enable-command-args
make all
make install-plugin
make install-daemon
make install-daemon-config
/usr/local/nagios/bin/nrpe-c /usr/local/nagios/etc/nrpe.cfg -d #启动nrpe服务
/usr/local/nagios/libexec/check_nrpe -H localhost #以下均为测试
/usr/local/nagios/libexec/check_nrpe -H 192.168.0.208 -c check_cpu
/usr/local/nagios/libexec/check_nrpe-H 192.168.0.208 -c check_mem
/usr/local/nagios/libexec/check_nrpe-H 192.168.0.208 -c check_disk -a /home
3、基本配置:
1)修改apache配置:
/usr/local/app/apache2/conf/httpd.conf
user nagios
group nagios
ServerName 192.168.0.201
index.php #不加此无法打开页面
AddType application/x-httpd-php .php .phtml #这两行是添加对php的支持
AddType application/x-httpd-php-source .phps
#setting for nagios
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
#配置好后添加用户用如下命令:
/usr/local/app/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd test
New password:123456
Re-type new password: 123456
Adding password for user test
less /usr/local/nagios/etc/htpasswd #查看用户认证文件
test:OmWGEsBnoGpIc #格式:用户名:密码
2)Nagios主要配置:
Nagios主要配置说明:
/usr/local/nagios/etc
cgi.cfg #web界面配置文件(基本无需修改)
contacts.cfg #联系人定义文件(基本无需修改)
log.conf #日志配置文件(基本无需修改)
nagios.cfg #nagios主配置文件
resource.cfg #资源配置文件(基本无需修改)
/usr/local/nagios/etc/objects
commands.cfg #命令解析文件
templates.cfg #服务模版文件(无需修改)
timeperiods.cfg #监视时段配置文件
/usr/local/nagios/etc/objects/gy
hosts.cfg #配置被监控主机文件
service.cfg #配置被监控服务文件
3)具体配置实例(略)
4、检测,启动与登录:
1)启动前必须的步骤:检测
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors: 0 #出现这样的信息表示配置正确,可以启动
2)启动:
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
3)登录:
http://192.168.0.201/nagios/
user:test
password: 123456
三、被监控端的安装过程:
1)安装过程:
mkdir �Cp /usr/local/nagios
groupadd nagios
useradd nagios �Cd/usr/local/nagios �Cs /sbin/nologin �Cg nagios
yum install openssl openssl-devel
tar -zxvf nagios-plugins-1.4.9.tar.gz
cd nagios-plugins-1.4.9
./configure --enable-redhat-pthread-workaround
make && make install
chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec
tar �Czxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --enable-command-args
make all
make install-plugin
make install-daemon
make install-daemon-config
cd /usr/local/nagios
vim start.sh
/usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg -d
chmod +x start.sh
2)配置nrpe.cfg
/usr/local/nagios/etc/nrpe.cfg
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=127.0.0.1,192.168.0.201
dont_blame_nrpe=1
debug=0
command_timeout=60
connection_timeout=300
# The following examples use hardcoded commandarguments...
command[check_users]=/usr/local/nagios/libexec/check_users-w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load-w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk-w 20% -c 10% -p /dev/hda1
#command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs-w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs-w 150 -c 200
command[check_cpu]=/usr/local/nagios/libexec/check_cpu -w 40-c 20 -s 3
command[check_cpuidle]=/usr/local/nagios/libexec/check_cpuidle-w 30 -c 20 -s 3
command[check_disk_root]=/usr/local/nagios/libexec/check_disk-w 20% -c 10% -p /
command[check_disk_home]=/usr/local/nagios/libexec/check_disk-w 20% -c 10% -p /home
command[check_disk_u1]=/usr/local/nagios/libexec/check_disk-w 20% -c 10% -p /u1
command[check_total_procs]=/usr/local/nagios/libexec/check_procs-w 150 -c 200
command[check_swap]=/usr/local/nagios/libexec/check_swap -w80% -c 70%
command[check_mem]=/usr/local/nagios/libexec/check_mem
command[check_io]=/usr/local/nagios/libexec/check_io
#command[check_users]=/usr/local/nagios/libexec/check_users-w $ARG1$ -c $ARG2$
#command[check_load]=/usr/local/nagios/libexec/check_load-w $ARG1$ -c $ARG2$
command[check_disk]=/usr/local/nagios/libexec/check_disk -w20% -c 10% -p $ARG1$
#command[check_procs]=/usr/local/nagios/libexec/check_procs-w $ARG1$ -c $ARG2$ -s $ARG3$
3)其他被监控主机安装:(简化安装)
yum install openssl openssl-devel
cd /usr/local/
scp -r 192.168.0.100:/usr/local/nagios /usr/local/
cd /usr/local/nagios/
groupadd nagios
useradd -g nagios -d /usr/local/nagios -s /sbin/nologinnagios
chown -R nagios:nagios nagios .
vim start.sh
/usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg -d
chmod +x start.sh
附管理界面:
本文出自 “zhangdh开放空间” 博客,谢绝转载!