Skip to content


Nagios 安装

nagios nagios

Nagios是一个用来监控主机、服务和网络的开放源码软件,很多大的公司或组织都在使用它。

参考资料: http://yahoon.blog.51cto.com/13184/41300 http://bbs.linuxtone.org/thread-1281-1-1.html http://bbs.linuxtone.org/thread-2269-1-1.html nagios官方文档 http://www.nagios.org/docs/ nagios中文文档 http://www.itnms.net/docs/nagios/cn/build/html/ nagios中文相关讨论区 http://bbs.linuxtone.org/forum-20-1.html http://www.itnms.net/discuz/forumdisplay.php?fid=10&pageD1

nagios下载地址: http://www.nagios.org/download/

这里选用 nagios-3.0.6.tar.gz nagios-plugins-1.4.13.tar.gz nrpe2.12 wget http://downloads.sourceforge.net/sourceforge/nagios/nagios-3.0.6.tar.gz?use_mirror=nchc wget http://downloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz?use_mirror=nchc wget http://nchc.dl.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz

安装nagios 系统为as4

1.创建用户和用户组

#创建用户和用户组 useradd -m nagios

-s /sbin/nologin 禁止登录,运行命令时可能会有限制,也可以不加本限制

groupadd nagcmd usermod -G nagcmd nagios #将nginx或apache运行用户加入组中 usermod -G nagcmd nobody

2.安装nagios

tar zxvf nagios-3.0.6.tar.gz cd nagios-3.0.6 #gd默认安装路径 #./configure –with-command-group=nagcmd –prefix=/usr/local/nagios –with-gd-lib=/usr/lib64/ –with-gd-inc=/usr/include

./configure –with-command-group=nagcmd –prefix=/usr/local/nagios –with-gd-lib=/usr/local/gd2/lib –with-gd-inc=/usr/local/gd2/include #以下为编译结果

Configuration summary for nagios 3.0.6 12-01-2008 :

General Options:

Nagios executable: nagios Nagios user/group: nagios,nagios Command user/group: nagios,nagcmd Embedded Perl: no Event Broker: yes Install ${prefix}: /usr/local/nagios Lock file: ${prefix}/var/nagios.lock Check result directory: ${prefix}/var/spool/checkresults Init directory: /etc/rc.d/init.d Apache conf.d directory: /etc/httpd/conf.d Mail program: /bin/mail Host OS: linux-gnu

Web Interface Options:

HTML URL: http://localhost/nagios/ CGI URL: http://localhost/nagios/cgi-bin/ Traceroute (used by WAP): /bin/traceroute

Review the options above for accuracy. If they look okay, type ‘make all’ to compile the main program and CGIs.

make all make install make install-init make install-config make install-commandmode

3.安装nagios-plugins

tar zxvf nagios-plugins-1.4.13.tar.gz cd nagios-plugins-1.4.13 ./configure –with-nagios-user=nagios –with-nagios-group=nagios –prefix=/usr/local/nagios

checking for ping6… /bin/ping6 checking for ICMP ping syntax… 到这里就停住了,应该是ipv6问题,加上–with-ping-command参数编译

参考下面地址: http://www.linuxquestions.org/questions/linux-software-2/.configure-script-hangs-at-checking-for-icmp-ping-syntax…l-499235/ http://bbs.bitscn.com/195707 ./configure –with-nagios-user=nagios –with-nagios-group=nagios –prefix=/usr/local/nagios –with-ping-command=”/bin/ping” –enable-perl-modules –with-mysql=/opt/mysql make

–with-apt-get-command: –with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s –with-ping-command: /bin/ping –with-ipv6: yes –with-mysql: /opt/mysql/bin/mysql_config –with-openssl: yes –with-gnutls: no –enable-extra-opts: no –with-perl: /usr/bin/perl –enable-perl-modules: yes –with-cgiurl: /nagios/cgi-bin –with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin

如果没有mysql关联,libexec目录不会产生check_mysql,utils.pm等文件

make install #查看播件文件是否已安装在这个目录 ls /usr/local/nagios/libexec 4.配置nginx的web口 如果使用apache可以在安装nagios时使用make install-webconf,不需要下面的配置 我的web server是nginx ,编辑nginx.conf location ~ \.cgi$ { root /usr/local/nagios/sbin; allow 192.168.54.83; #充许访问的客户端ip deny all; auth_basic “Restricted”; auth_basic_user_file nagios; rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break; fastcgi_index index.cgi; fastcgi_pass unix:/dev/shm/perl_cgi-dispatch.sock; fastcgi_param HTTP_ACCEPT_ENCODING gzip,deflate; fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name; include fcgi.conf; } location /nagios/ { alias /usr/local/nagios/share/; allow 192.168.54.83; deny all; auth_basic “Restricted”; auth_basic_user_file nagios; } 5.使用apache的htpasswd生成用户和口令 /opt/apache/bin/htpasswd -c /opt/nginx/conf/nagios nagiosadmin 6.修改nagios配置文件 修改etc/cgi.cfg中的用户为nagiosadmin authorized_for_system_information=nagiosadmin authorized_for_configuration_information=nagiosadmin authorized_for_system_commands=nagiosadmin//多个用户之间用逗号隔开 authorized_for_all_services=nagiosadmin authorized_for_all_hosts=nagiosadmin authorized_for_all_service_commands=nagiosadmin authorized_for_all_host_commands=nagiosadmin 测试时可以将use_authentication=0 修改etc/objects/contacts.cfg联系人 define contact{ contact_name nagiosadmin ; Short name of user use generic-contact ; Inherit default values from generic-contact template (defined above) alias Nagios Admin ; Full name of user email nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** }   修改本机配置etc/objects/localhost.cfg 上传配置文件 检查配置文件 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 7.启动nagios #启动 /etc/rc.d/init.d/nagios start #手工启动 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg #重启 /etc/rc.d/init.d/nagios reload 8.reload nginx server /opt/nginx/sbin/nginx -t kill -HUP `cat /opt/nginx/logs/nginx.pid` nagios安装完成 访问http://localhost/nagios/就可以看到了 安装内存监控插件 wget “http://www.nagiosexchange.org/cgi-bin/jump.cgi?ID=1789&view=File1;d=1” mv jump.cgi\?ID\=1789\&view\=File1\;d\=1 check_mem.pl.gz gunzip check_mem.pl.gz mv check_mem.pl /usr/local/nagios/libexec/check_mem chown nagios:nagios check_mem chmod 0755 check_mem ./check_mem -w 95,60 -c 120,80 #测试结果 OK: Memory Usage (W> 95, C> 120): 83% Swap Usage (W> 60, C> 80): 3%|MemUsed=83%;95;120 SwapUsed=3%;60;80 commands.cfg增加 define command{ command_name check_mem command_line $USER1$/check_mem -w $ARG1$ -c $ARG2$ } 监控对像文件localhost.cfg添加 define service{ use local-service ; Name of service template to use host_name localhost service_description memory check_command check_mem!110,50!150,80 notifications_enabled 0 } 重新加载文件 /etc/init.d/nagios reload 访问http://localhost/nagios/ 输入口令后就可以看到界面了 nagios_screen1 疑难杂征 在service detail中看到ping的命令行是黄色的。 Current Status: UNKNOWN (for 3d 17h 46m 12s) Status Information: ping CRITICAL – Could not interpret output from ping command 多数情况为nagios用户没有执行ping的权限 可以先测试下ping命令有无返回 ping 127.0.0.1 nagios用户无执行权权时: root下 chmod u+s /path/ping 参考:http://blog.chinaunix.net/u/9861/showart_1001559.html 路径不正确时: nagios插件编译时使用参数 –with-ping-command=”/bin/ping” 参考:http://marc.info/?l=netsaintplug-help&m=101980226726163&w=2 禁ping时: cat /proc/sys/net/ipv4/icmp_echo_ignore_all #非0执行下面 echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all 还需检查下其它地方有无禁ping设置,如/etc/rc.local nagios里点”3-D Status Map”时提示”打开statuswrl.cgi”的问题 这个问题是玩nagios最常见的问题 nagios的官方网站的faq里都有得说,看这里 意思差不多就是说:“如果要看3-D statusmap CGI (statuswrl.cgi)的输出的话,得为你的web浏览器安装vrml的client(客户端)或plugin(插件)” 然后还推荐了四个 Cortona (Parallel Graphics) Cosmo Player (Computer Associates and NIST) FreeWRLOpenVRML 好像最后两个没有windows版本 所以如果是用windows机器看的话 需要装前两个软件之一,我安装的是Cortona3D Viewer ,支持ie7和firefox 访问本网址可以查看适合的plugin http://cic.nist.gov/vrml/vbdetect.html Firefox添加Nagios插件 https://addons.mozilla.org/en-US/firefox/addon/3607 解决Nagios安装好后statusmap.cgi找不到的问题
  • libgd
  • libgd-devel
  • libpng
  • libpng-devel
  • libjpeg
  • libjpeg-devel
  • zlib
  • zlib-devel
run ‘ make devclean‘ in your Nagios source code distribution directory and rerun the configure script 我的gd安装在/usr/local/gd2/ ./configure –prefix=/usr/local/nagios –with-gd-lib=/usr/local/gd2/lib –with-gd-inc=/usr/local/gd2/include iconv找不时的出错 statusmap.cgi: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory ldd /usr/local/nagios/sbin/statusmap.cgi libgd.so.2 => /usr/lib64/libgd.so.2 (0x0000003f16e00000) libiconv.so.2 => not found 找一下libiconv.so.2是不是在/usr/local/lib/中,并且该目录不在/etc/ld.so.conf中 将目录放入动态库中 echo “/usr/local/lib” >> /etc/ld.so.conf ldconfig -v 再刷新下页面,问题解决. 安装NRPE tar zxvf nrpe2.12.tar.gz cd nrpe2.12 ./configure ./make all ./make install-plugin #监控机只需安装到这步

Posted in Nagios, 技术.

Tagged with .


4 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. katy says

    你好。
    在进行nginx配置是11行的配置是什么意思?
    11.fastcgi_pass unix:/dev/shm/perl_cgi-dispatch.sock;

    我的电脑上面没有:/dev/shm/perl_cgi-dispatch.sock文件。
    我用的是redhat Enterprise 4.4
    是不是需要安装什么东西了?

  2. C1G says

    我的web server是nginx,apache不需要这步
    这个是fastcgi的UNIX sockets 路径
    如果是IP sockets那可能是”127.0.0.1:8999″
    取决于你的fastcgi配置

  3. vincentzhu says

    您好
    请教个问题 我也是nginx+nagios 用的是perl fastcgi
    状况是 nagios 能够访问 但是web访问超级慢 打开一个页面大概需要1分钟
    我的fastcgi 是wiki 里下的 地址为 http://wiki.nginx.org//NginxSimpleCGI
    解答下

  4. C1G says

    我的nginx配置可以参见这里
    http://blog.c1gstudio.com/archives/152



Some HTML is OK

or, reply to this post via trackback.