Required Software
Perl >= 5.x without additional modules
RRDtool >= 1.x, better 1.2 but not compulsory
Attention: installing RRDtool without a packet manager might lead to missing dejavu fonts. If you see graphs without text then this may be the cause.
PHP >= 4.3.8 for Webfrontend
PHP-extension zlib and GD.
Nagios 2.x oder higher
wget http://nchc.dl.sourceforge.net/sourceforge/pnp4nagios/pnp-0.4.14.tar.gz
tar -xvzf pnp-0.4.14.tar.gz
cd pnp-0.4.14
./configure
checking for rrdtool… no
checking rrdtool path … no
configure: error: is a directory! PNP needs the Path to the rrdtool binary!
export PKG_CONFIG_PATH=/usr/local/rrdtool/lib/pkgconfig
export PKG_CONFIG=/usr/local/rrdtool/bin/pkg-config
export PATH=/usr/local/rrdtool/bin:$PATH
*** Configuration summary for pnp 0.4.14 05-02-2009 ***
General Options:
————————- ——————-
Nagios user/group: nagios nagios
Install directory: /usr/local/nagios
HTML Dir: /usr/local/nagios/share/pnp
Config Dir: /usr/local/nagios/etc/pnp
Location of rrdtool binary: /usr/local/rrdtool/bin/rrdtool Version 1.3.7
RRDs Perl Modules: *** NOT FOUND ***
RRD Files stored in: /usr/local/nagios/share/perfdata
process_perfdata.pl Logfile: /usr/local/nagios/var/perfdata.log
Perfdata files (NPCD) stored in: /usr/local/nagios/var/spool/perfdata/
Review the options above for accuracy. If they look okay,
type ‘make all’ to compile.
WARNING: The RRDs Perl Modules are not found on your System
Using RRDs will speedup things in larger Installtions.
make all
make install
make install-config
make install-init
define host {
name host-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$
process_perf_data 1
}
define service {
name srv-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
process_perf_data 1
}
修改etc/objects/localhost.cfg增加相应命令
define host{
use linux-server,host-pnp ; Name of host templates to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name localhost
alias localhost
address 127.0.0.1
}
define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
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参数编译
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/ 输入口令后就可以看到界面了
疑难杂征在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)FreeWRL和OpenVRML
好像最后两个没有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
#监控机只需安装到这步
export BUILD_DIR=/tmp/rrdbuild
export INSTALL_DIR=/usr/local/rrdtool
mkdir -p $BUILD_DIR
cd $BUILD_DIR
export CFLAGS=”-O3 -fPIC”
#export LDFLAGS=”-Wl,–rpath -Wl,${INSTALL_DIR}/lib”
export PKG_CONFIG_PATH=${INSTALL_DIR}/lib/pkgconfig
export PATH=$INSTALL_DIR/bin:$PATH
export PKG_CONFIG=$INSTALL_DIR/bin/pkg-config
cd $BUILD_DIR
wget -c http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.3.7.tar.gz
tar zxvf rrdtool-1.3.7.tar.gz
wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.23.tar.gz
tar zxvf pkg-config-0.23.tar.gz
cd pkg-config-0.23
./configure –prefix=$INSTALL_DIR
make
make install
cd $BUILD_DIR
wget http://oss.oetiker.ch/rrdtool/pub/libs/zlib-1.2.3.tar.gz
tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure –prefix=$INSTALL_DIR –shared
make
make install
cd $BUILD_DIR
wget http://oss.oetiker.ch/rrdtool/pub/libs/libpng-1.2.18.tar.gz
tar zxvf libpng-1.2.18.tar.gz
cd libpng-1.2.18
./configure –prefix=$INSTALL_DIR
make
make install
cd $BUILD_DIR
wget http://oss.oetiker.ch/rrdtool/pub/libs/freetype-2.3.5.tar.gz
tar zxvf freetype-2.3.5.tar.gz
cd freetype-2.3.5
./configure –prefix=$INSTALL_DIR CFLAGS=”-O3 -fPIC”
make
make install
cd $BUILD_DIR
wget http://oss.oetiker.ch/rrdtool/pub/libs/libxml2-2.6.32.tar.gz
tar zxvf libxml2-2.6.32.tar.gz
cd libxml2-2.6.32
./configure –prefix=$INSTALL_DIR
make
make install
cd $BUILD_DIR
wget http://oss.oetiker.ch/rrdtool/pub/libs/fontconfig-2.4.2.tar.gz
tar zxvf fontconfig-2.4.2.tar.gz
cd fontconfig-2.4.2
./configure –prefix=$INSTALL_DIR –with-freetype-config=$INSTALL_DIR/bin/freetype-config
make
make install
cd $BUILD_DIR
wget http://oss.oetiker.ch/rrdtool/pub/libs/pixman-0.10.0.tar.gz
tar zxvf pixman-0.10.0.tar.gz
cd pixman-0.10.0
./configure –prefix=$INSTALL_DIR
make
make install
cd $BUILD_DIR
wget http://oss.oetiker.ch/rrdtool/pub/libs/cairo-1.6.4.tar.gz
tar zxvf cairo-1.6.4.tar.gz
cd cairo-1.6.4
./configure –prefix=$INSTALL_DIR \
–enable-xlib=no \
–enable-xlib-render=no \
–enable-win32=no \
FONTCONFIG_CFLAGS=-I/usr/local/rrdtool/include FONTCONFIG_LIBS=”-L/usr/local/rrdtool/lib -lfontconfig ” \
FREETYPE_CFLAGS=-I/usr/local/rrdtool/include/freetype2 FREETYPE_LIBS=”-L/usr/local/rrdtool/lib -lfreetype”
pixman_CFLAGS=-I/usr/local/rrdtool/include/pixman-1 pixman_LIBS=”-L/usr/local/rrdtool/lib -lpixman-1″ \
make
make install
cd $BUILD_DIR
wget http://oss.oetiker.ch/rrdtool/pub/libs/glib-2.15.4.tar.gz
tar zxvf glib-2.15.4.tar.gz
cd glib-2.15.4
./configure –prefix=$INSTALL_DIR
make
make install
#gconvert.c:51:2: #error GNU libiconv not in use but included iconv.h is from libiconv
需带上–with-libiconv
cd $BUILD_DIR
wget http://oss.oetiker.ch/rrdtool/pub/libs/pango-1.21.1.tar.bz2
bunzip2 pango-1.21.1.tar.bz2
tar xf pango-1.21.1.tar
cd pango-1.21.1
./configure –prefix=$INSTALL_DIR –without-x
make
make install
cd $BUILD_DIR/rrdtool-1.3.7
./configure –prefix=$INSTALL_DIR –disable-tcl –disable-python
Find 3rd-Party Libraries
checking for cairo_font_options_create in -lcairo… no
checking for pkg-config… pkg-config
configure: WARNING:
—————————————————————————-
* I found a copy of pkgconfig, but there is no cairo-png.pc file around.
You may want to set the PKG_CONFIG_PATH variable to point to its
location.
—————————————————————————-
configure: WARNING:
—————————————————————————-
* I could not find a working copy of cairo-png. Check config.log for hints on why
this is the case. Maybe you need to set LDFLAGS and CPPFLAGS appropriately
so that compiler and the linker can find libcairo and its header files. If
you have not installed cairo-png, you can get it either from its original home on
http://cairographics.org/releases/
You can find also find an archive copy on
http://oss.oetiker.ch/rrdtool/pub/libs
The last tested version of cairo-png is 1.4.6.
LIBS=-lm
LDFLAGS=
CPPFLAGS=
—————————————————————————-
checking for cairo_svg_surface_create in -lcairo… no
checking for pkg-config… (cached) pkg-config
有以上信息请检查cairo安装和环境变量
checking in… and out again
ordering CD from http://tobi.oetiker.ch/wish …. just kidding ;-)
—————————————————————-
Config is DONE!
With MMAP IO: yes
Build rrd_getopt: no
Static programs: no
Perl Modules: perl_piped perl_shared
Perl Binary: /usr/bin/perl
Perl Version: 5.8.5
Perl Options: PREFIX=$(DESTDIR)/usr/local/rrdtool LIB=$(DESTDIR)/usr/local/rrdtool/lib/perl/5.8.5
Ruby Modules:
Ruby Binary: no
Ruby Options: sitedir=$(DESTDIR)/usr/local/rrdtool/lib/ruby
Build Tcl Bindings: no
Build Python Bindings: no
Build rrdcgi: yes
Build librrd MT: yes
Link with libintl: yes
Libraries: -lxml2 -lcairo -lcairo -lcairo -lm -lcairo -lpng12 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0
Type ‘make’ to compile the software and use ‘make install’ to
install everything to: /usr/local/rrdtool.
… that wishlist is NO JOKE. If you find RRDtool useful
make me happy. Go to http://tobi.oetiker.ch/wish and
place an order.
其中系统中已安装的是(参见https://blog.c1gstudio.com/archives/152)
zlib-1.2.3.tar.gz
freetype-2.3.5.tar.gz
libpng-1.2.31.tar.gz
libxml2-2.6.32.tar.gz
fontconfig-2.6.0.tar.gz
tar zxvf glib-2.15.4.tar.gz
cd glib-2.15.4
./configure –with-libiconv
make
configure: error: Cairo requires at least one native font backend. Please install FreeType and fontconfig and try again
make clean
cp /usr/local/freetype/include/ft2build.h /usr/local/freetype/include/freetype2/
./configure FREETYPE_LIBS=/usr/local/freetype/lib/libfreetype.so FREETYPE_CFLAGS=”-I/usr/local/freetype/include/freetype2″ FONTCONFIG_CFLAGS=”-I/usr/local/fontconfig/include” FONTCONFIG_LIBS=/usr/local/fontconfig/lib/libfontconfig.so
cairo (version 1.8.6 [release]) will be compiled with:
make
make install
The following surface backends:
Image: yes (always builtin)
Xlib: no (requires X development libraries)
Xlib Xrender: no (requires –enable-xlib)
Quartz: no (requires CoreGraphics framework)
Quartz-image: no (disabled, use –enable-quartz-image to enable)
XCB: no (disabled, use –enable-xcb to enable)
Win32: no (requires a Win32 platform)
OS2: no (disabled, use –enable-os2 to enable)
PostScript: yes
PDF: yes
SVG: yes
glitz: no (disabled, use –enable-glitz to enable)
BeOS: no (disabled, use –enable-beos to enable)
DirectFB: no (disabled, use –enable-directfb to enable)
The following font backends:
User: yes (always builtin)
FreeType: yes
Win32: no (requires a Win32 platform)
Quartz: no (requires CoreGraphics framework)
The following functions:
PNG functions: yes
And the following internal features:
gcov support: no
test surfaces: no (disabled, use –enable-test-surfaces to enable)
ps testing: yes
pdf testing: no (requires poppler-glib >= 0.9.2)
svg testing: no (requires librsvg-2.0 >= 2.15.0)
It is strictly recommended that you enable the native surface backend
feature for your platform.
CPPFLAGS=”-I/usr/local/lib/pkgconfig/ -I/usr/local/include/libart-2.0/ -I/usr/local/freetype/ -I/usr/local/lib/” ./configure –prefix=/usr/local/rrdtool –disable-tcl –disable-python
make clean
make
make install
近期评论