nagios安装部署
1安装 nagios(中文版本的)Get nagios-cn-3.2.3.tar.bz2 nagios-plugins-1.4.16.tar.gz
www.nagios.org官网下载安装包和查看文档
tarjxfnagios-cn-3.2.3.tar.bz2
cd/nagios-cn-3.2.3
./configure
Useradd nagios
Usermod-G nagios apache
Yum install-yperl-ExtUtils-Embed
Rpm -qgd查看系统上gd的版本号
Yum listgd查看安装包的gd版本
Get gd-devel-2.0.35-11.el6.x86.rpm
Yum localinstallgd-devel-2.0.35-11.el6.x86.rpm
./configure --enable-embedded-perl配置完成后
Make all
Make install
Makeinstall-init
Makeinstall-commandmode
Make install-config
Make install-webconf
Cd /usr/local/nagios/
Cd etc/
Vi nagios.cfg主配置文件
Cdobjects/
Vi commands.cfg命令配置文件
Cd /usr/local/nagios/libexec/
Tarzxfnagios-plugins-1.4.16.tar.gz
Cd nagios-plugins-1.4.16
./configure --enable-extra-opts --enable-perl-modules --enable-libtap
make
make install
Cd /usr/local/nagios/libexec/
Chown nagios.nagios *
/usr/local/nagios/bin/nagios-v /usr/local/nagios/etc/nagios.cfg 检查语法错误
Total Warnings:0
Total Errors:0 说明没有错误
/etc/init.d/nagios restart
Cd /etc/httpd/conf.d/
Cat nagios.conf
Cat /usr/local/nagios/etc/htpasswd.users
Cd/usr/local/nagios/etc/
Mv htpasswd.user htpasswd.users
Htpasswd -m /usr/local/nagios/etc/htpasswd.users nagiosadmin更改nagios的ssl密码它是加密访问的
Cat/usr/local/nagios/etc/htpasswd.uers 验证密码
/etc/init.d/httpd restart
https://ip/nagios
输入用户名和密码
Yum install-ymailx
Cd /usr/local/nagios/etc/
Vi nagios.cfg 更改如下:
(Cfg_file=/usr/local/nagios/etc/objects/hosts.cfg原来的)吧主机配置和服务配置分开
cfg_file=/usr/local/nagios/etc/objects/host187.cfg
cfg_file=/usr/local/nagios/etc/objects/server187.cfg
Cd objects/
Cp -plocalhost.cfg hosts.cfg
Cp -plocalhost.cfg servers.cfg
Vihosts.cfg 更改如下:
Definehost{
Use linux-server
Host_name server67.example.com
Alias Manager
Address 192.168.0.196
Icon_image server.gif
Statusmap_image server.gd2
2d_coords 500,200
3d_coords 500,200,100
}
Definehostgroup{
Hostgroup_name linux-server
Alias linuxServer
Members *
}
Vi servers.cfg更改如下:
删除掉所有的hosts,替换所有的田朝阳家用机为server96.example.com
:%s/田朝阳家用机/server96.example.com/g
Defineservicegroup{
Servicegroup_name系统负荷检查
Alias 负荷检查
Membersserver96.example.com,进程总数,server96.example.com,登录用户数,server96.example.com,更分区,server96.example.com,交换空间利用率
}(只留一个servergroup)
/usr/local/nagios/bin/nagios-v /usr/local/nagios/etc/nagios.cfg检查语法错误
/etc/init.d/nagios restart
用nagios监控另外一台主机上的mysql
Server27 上yum install mysql-server
/etc/init.d/mysqld restart
Mysql
Createdatabase nagdb;
Grantselect onnagdb.* tonagios@’192.168.0.196’ ;
Server96上
Cd/usr/local/nagio/libexec
./check_mysql--help
./check_mysql -H 192.168.0.127 -unagios -dnagdb
Cd/usr/local/nagios/etc/objects/
Vi commands.cfg 更改如下:
#’check_mysql’command definition
Define command{
Command_name check_mysql
Command_line $UER1$/check_mysql-H $HOSTADDRESS$-u$ARG1$ -d $ARG2$
}
Vihosts.cfg更改如下:
define host{
use linux-server
host_name mytest2
alias mysql
address 192.168.11.185
icon_image server.gif
statusmap_image server.gd2
2d_coords 400,100
3d_coords 400,100,50
}
Vi services.cfg更改如下:
define service{
use local-service
host_name mytest2
service_description MySQL
check_command check_mysql!nagios!cactidb
}
/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg检查语法错误
/etc/init.d/nagiosreload
Vi contacts.cfg 设置监控的内容出现错误时email通知的地址
Definecontact{
Contact_name nagiosadmin
Use generic-contact
Alias NagiosAdmin
Email yakexi007@westos.org
}
/etc/init.d/nagios reload
nagios安装好后,网页访问出现如下错误:
无权查看任何主机的信息。
请检查HTTP服务器关于该CGI的访问权限设置。
解决办法:
vi /usr/local/nagios/etc/cgi.cfg
将use_authentication的值改为0.
use_authentication=0
然后重启nagios服务
service nagios restart
还有可能:
配置文件中的hostname和service_description使用了中文。
建议hostname和service_description 不要使用中文
Su - nagios
Mailyakexi007@westos.org发送测试邮件
在/usr/locl/nagios/var/ 查看nagios的日志nagios.log
用nagios监控其他主机的磁盘,用户,根分区等要在所要监控的织机上安装nagios的插件
Server27
Getnrpe-2.14.tar.gz
Tar zxfnrpe-2.14.tar.gz
在 nrpe-2.14/docs/查看安装步骤
Evince NRPE.pdf &
Useraddnagios
Getnagios-plugins-1.4.16.tar.gz
Tar nagios-plugins-1.4.16.tar.gz
Cdnagios-plugins-1.4.16
Yuminstall gccmake-y
./configure配置出现如图但要支持那些功能
Yuminstall –y mysql-developenssl-devel
./configure
Make &&makeinstall
Cd/usr/local/
Ll-d nagios
Chown -Rnagios.nagios nagios/
Chown -Rnagios.nagios/usr/local/nagios/libexec
Yuminstallxinetd-y
Cd nrpe-2.14
./configure
Make all
Makeinstall-plugin
Makeinstall-daemon
Makeinstall-daemon-config
Makeinstall-xinetd
Vi /etc/xinetd.d/nrpe更改如下:
吧only-from =192.168.0.196 改成这样
Vi/etc/services 更改如下:
nrpe 5666/tcp添加这一行让xinetd接听nrpe的端口
/etc/init.d/xinetd start
Netstat-natple|grep5666
Cd/usr/local/nagios/etc/
Vim nrpe.cfg 更改如下:
更改这行如command=/usr/local/nagios/libexec/check_disk-w 20%-c10% -p/
/etc/init.d/xinetd restart
在server96上也安装nrpe
Tarzxf nrpe-2.14.tar.gz
Cd nrpe-2.14
./configure
Make all
Makeinstall-plugin
Cd/usr/local/nagios/libexec/
./check_nrpe -H 192.168.0.127
如果出现NRPEV2.14则配置成功
./check_nrpe-H 192.168.0.127 -c check_disk
./check_nrpe -H 192.168.0.127-ccheck_users
Cd /usr/local/nagios/etc/objects/
Vi commands.cfg添加
Definecommand{
Command_name check_nrpe
Command_line $USER1$/check_nrpe-H $HOSTADDRESS$-c$ARG1$
}
Viservices.cfg添加
Define servicegroup{
Servicegroup_name 系统负荷检查
Alias 系统负荷
Members server96.example.com,进程总数,server96.example.com,登录用户数,server96.example.com,交换空间利用率,server27.example.com,根分区,server27.example.com,登录用户数,server27.example.com,系统负荷
}
Defineservice{
Use local-service
Host_name server27.example.com
Service_description更分区
Check_command check_nrpe!check_disk
}
Define service{
Use local-service
Host_name server27.example.com
Service_description 登录用户数
Check_command check_nrpe!check_users
}
Defineservice{
Use local-service
Host_name server27.example.com
Service_description 系统负荷
Check_command check_nrpe!check_load
}
/usr/local/nagios/bin/nagios-v /usr/locals/nagios/etc/nagios.cfg
/etc/init.d/nagios reload 这样就可以在图形中监控另外一台主机的根分区,登录用户等信息了。
当系统出现问题时用飞信给管理员发短信
Getfetion linuxso_2010113.tar.gz
Mvfetion/usr/local/nagios/libexec/
Cd/usr/lib/
Tarzxflinuxso_20101113.tar.gz -C/usr/lib
Cd/usr/lib
Ll
Chmod+x libACE-5.7.2.solibACE_ssl-5.7.2.solibcrypto.so.4libssl.so.4
Ldconfig/usr/lib不关机的情况下更新系统的库
Cd/usr/local/nagios/libexec/
Chmod+xfetion
Chownnagios.nagios fetion
./fetion 运行飞信提示错误
-bash:./fetion:/lib/ld-linux.so.2:bad ELFinterpreter Nosuch file or directory
Yuminstall –y /lib/ld-linux.so.2
Sunagios
/usr/local/nagios/libexec/fetion提示错误error whileloadingshare libraries :libstdc++.so.6
Su-root
Yum installlibstdc++.so.6-y
Su- nagios
/usr/local/nagios/libexec/fetion提示错误error whileloading sharedlibraries:libgssapi_krb5.so.2
Su-root
Yum install -ylibgssapi_krb5.so.2
Su- nagios
/usr/local/nagios/libexec/fetion提示错误errorwhile loading shared librarles:libz.so.1
Su-root
Yum install –ylibz.so.1
Su- nagios
/usr/local/nagios/libexec/fetion好了
/usr/local/nagios/libexec/fetion --mobile=18091883113(发送飞信的号)
--pwd=(发送飞信的手机号的密码)--to=18091883113(收飞信的手机号) –msg-utf8=”good luck(飞信的内容)”
如果提示要输入验证码则在一台装了图形的主机上用ssh连接次主机然后cd/usr/local/nagios/libexecscp 13679270227.jpg 192.168.0.251:/home/wxh/Desktop(装了图形的主机) 然后再装了图形的主机上打开此图片得到验证码
Su-nagios
Cd/usr/local/nagios/libexec/
Vi fetion.sh
/usr/local/nagios/libexec/fetion --mobile=13679270227 --pwd=yakxi007--to=”$1” –msg-utf8=”$2”
Cd/usr/local/nagios/etc/objects
Vicommands.cfg 更改如下:
Definecommand{
Command_name notify-host-by-fetion
Command_line $USER1$/fetion.sh $CONTACTPAGER$”NOTIFICATIONTYPE$HostAlert: $HOSTNAME$ is $HOSTSTATE$”
}
Definecommand{
Command_name notify-service-by-fetion
Command_line $USER1$/fetion.sh $CONTACTPAGER$ “$NOTIFICATIONTYPEservice Alert:$HOSTALIAS$/$SERVICEDESC$is $SERVICETATE$”
}
Vitemplates.cfg 更改如下:
Definecontact{
在这一样添加如下:
Host_notification_commands notify-host-by-email,notify-host-by-fetion
}
Vicontacts.cfg更改如下:
Definecontact{
加一行 pager 18209184795
}
/urs/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios reload
页:
[1]