配置监控端yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devellibpng libpng-devel freetype freetype-devel libxml2 libxml2-develzlib zlib-devel glibc glibc-devel glib2 gd gd-devel glib2-develbzip2 bzip2-devel ncurses ncurses-devel curl curl-devel openssl openssl-devellibmcrypt-devel libtool libtool-devel
安装apache#useradd www#tar -jxvf httpd-2.2.24.tar.bz2#./configure --prefix=/usr/local/apache --enable-module=so--enable-deflate=shared --enable-expires=shared--enable-rewrite=shared --enable-cache --enable-file-cahe--enable-mem-cache --enable-disk-cache --enable-static-support --enable-ssl --enable-so#make && make install#cp /usr/local/apache/bin/apachectl /etc/init.d/httpd#vim /usr/local/apache/conf/httpd.conf #/etc/init.d/httpd start
安装PHP# tar -zxvf php-5.3.6.tar.gz#./configure --prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc--with-apxs2=/usr/local/apache/bin/apxs --with-gd--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib--enable-safe-mode --enable-mbstring --with-gd --enable-gd-native-ttf--with-openssl --enable-zip --enable-sockets # make && make install
编辑apache配置文件#vim /usr/local/apache/conf/httpd.conf找到AddType模块处添加 AddTypeapplication/x-httpd-php-source .phps AddTypeapplication/x-httpd-php .php .phtml在index.html前添加index.php
# useradd nagios -s /sbin/nologin# mkdir /usr/local/nagios# chown nagios:nagios /usr/local/nagios/ -R# tar -jxvf nagios-cn-3.2.3.tar.bz2# ./configure --prefix=/usr/local/nagios/--with-gd-lib=/usr/lib --with-gd-inc=/usr/include--with-nagios-user=nagios --with-nagios-group=nagios--with-command-group=nagios#make all#make install#make install-init#make install-commandmode#make install-config******#make install-webconf//如果是rpm包安装的apache,可以执行,否则报错,做如下操作即可#vim /usr/local/apache/conf/httpd.conf在最后添加Alias /nagios/cgi-bin/images/"/usr/local/nagios/share/images/" AllowOverride None Options None Order allow,deny Allow from all AuthName "NagiosAccess" AuthType Basic AuthUserFile/usr/local/nagios/etc/.passwd.conf Require valid-userScriptAlias /nagios/cgi-bin/ "/usr/local/nagios/sbin/" AllowOverride None Options None Order allow,deny Allow from all AuthName "NagiosAccess" AuthType Basic AuthUserFile/usr/local/nagios/etc/.passwd.conf Require valid-userAlias /nagios/ "/usr/local/nagios/share/" AllowOverride None Options None Order allow,deny Allow from all AuthName "NagiosAccess" AuthType Basic AuthUserFile/usr/local/nagios/etc/.passwd.conf Require valid-userAddDefaultCharset utf-8 //防止部分中文乱码# /usr/local/apache/bin/htpasswd -c/usr/local/nagios/etc/.passwd.conf nagiosadmin //生成nagios口令密码或者# /usr/local/apache/bin/htpasswd -bc/usr/local/nagios/etc/.passwd.conf nagiosadmin nagiosadmin
# /usr/local/nagios/bin/nagios -v/usr/local/nagios/etc/nagios.cfg //检查文件是否出错
#/etc/init.d/nagios start#/etc/init.d/httpd start
访问http://IP/nagios/ //别名里有/,这里就要有/
# chmod o+w /usr/local/nagios/var/rw/nagios.cmd//更改事件通知时会用到#/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg//nagios手动重启安装插件
# tar -zxvf nagios-plugins-1.4.16.tar.gz# ./configure--prefix=/usr/local/nagios/ # make && make install
#tar -zxvf nrpe-2.12.tar.gz#./configure--prefix=/usr/local/nagios/ #make all#make install-plugin#make install-daemon#make install-daemon-config#make install-xinetd
#vim /usr/local/nagios/etc/objects/commands.cfg在最后加上define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$-c $ARG1$ }或者define command{ command_name check_nrpe command_line/usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c$ARG1$ }
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg-d //启动nrpe#/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg//nagios手动重启
配置被监控的#yum install openssl openssl-devel# useradd nagios -s /sbin/nologin#tar -zxvf nagios-plugins-1.4.16.tar.gz -C/usr/local/src/#./configure --prefix=/usr/local/nagios#make#make install
#chown nagios:nagios /usr/local/nagios/ -R
#tar -zxvf nrpe-2.12.tar.gz -C /usr/local/src/#./configure --prefix=/usr/local/nagios/#make all#make install-plugin#make install-deamon#make install-daemon-config#make install-xinetd
#vim /usr/local/nagios/etc/nrpe.cfg修改如下内容,根据自己需求修改
allowed_hosts=127.0.0.1 //添加ip用逗号分隔
command[check_users]=/usr/local/nagios//libexec/check_users -w5 -c 10command[check_load]=/usr/local/nagios//libexec/check_load -w15,10,5 -c 30,25,20command[check_hda1]=/usr/local/nagios//libexec/check_disk -w20% -c 10% -p /dev/hda1command[check_zombie_procs]=/usr/local//nagios/libexec/check_procs-w 5 -c 10 -s Zcommand[check_total_procs]=/usr/local//nagios/libexec/check_procs-w 150 -c 200
# vim /etc/xinetd.d/nrpe修改only from的IP //多个ip用逗号分隔
# vim /etc/services在最后添加nrpe 5666/tcp #nrpe
# /etc/init.d/xinetd restart //启动xinetd# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg-d //启动nrpe,没生成/bin或者启动文件,可以从监控端cp一个过来# netstat -anpt |grep 5666 //查看端口,看nrpe是否启动
添加监控主机和监控服务例如:# vim host.cfg
define host{ use linux-server host_name webserver alias web# parents address 192.168.10.132 icon_image server.gif statusmap_image server.gd2 2d_coords 500,200 3d_coords 500,200,100 }
define service{ use local-service ; Name of service template touse host_name webserver service_description HTTP check_command check_nrpe!check_http -I192.168.10.132 -p 80 -e 403,202 //监控192.168.10.132主机的80端口,返回值为403和 202时,为ok状态 notifications_enabled 0 }
报错解决方法HTTP WARNING: HTTP/1.1 403 Forbidden - 5240 bytes in 0.070second response time主要是监控端在检测被监控端下/var/www/html/index.html文件,编译安装的apache可定不在这个下面,所以创建一个就好了
在被监控机上#touch /var/www/html/index.html
监控网站主页
# vim commands.cfg添加define command{ command_name check_index command_line $USER1$/check_http $ARG1$ }
# vim host.cfg define service{ use local-service ; Name of service template touse host_name localhost service_description HTTP check_command check_index!-H 192.168.0.106-u /index.php //如果域名监控,格式是check_index!-Hwww.testhost.test -u /index.php notifications_enabled 0 }
监控mysql查看libexec目录下有没有check_mysql,如果没有,yum installedmysql-devel,在重装nagios-plugin
创建nagios专用数据库mysql> create database nagios;Query OK, 1 row affected (0.00 sec) mysql> grant all on nagios.* tonagios@'localhost' identified by 'nagios';Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)
测试# /usr/local/nagios/libexec/check_mysql -H localhost -u nagios-d nagios -p nagiosUptime: 44649 Threads: 10 Questions: 152675 Slow queries:0 Opens: 292 Flush tables: 1 Open tables: 64 Queries persecond avg: 3.419
# vim commands.cfg //定义命令在最后添加
#check mysqldefine command{command_name check_mysqlcommand_line $USER1$/check_mysql -H $HOSTADDRESS$ -unagiosuser -d nagios -p nagiospwd}
# vim host.cfg //定义主机
define service{ use local-service ; Name of service template touse host_name localhost service_description Mysql check_command check_mysql notifications_enabled 0 }
报错解决办法
1.
Can't locate RRDs.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /usr/local/nagios/sbin/show.cgi line 9., referer: http://jk.ylwkj.com/nagios/cgi-bin/status.cgi?host=all
#cp -rp /usr/local/rrdtool/lib/perl/5.8.8/x86_64-linux-thread-multi/ /usr/lib64/perl5/site_perl/5.8.8/
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com