所有安装包和文档http://down.51cto.com/data/1877051
1安装 nagios(中文版本的)
Get nagios-cn-3.2.3.tar.bz2 nagios-plugins-1.4.16.tar.gz
www.nagios.org 官网下载安装包和查看文档
tar jxf nagios-cn-3.2.3.tar.bz2
cd /nagios-cn-3.2.3
./configure
Useradd nagios
Usermod -G nagios apache
Yum install -y perl-ExtUtils-Embed
Rpm -q gd 查看系统上gd的版本号
Yum list gd 查看安装包的gd版本
Get gd-devel-2.0.35-11.el6.x86.rpm
Yum localinstall gd-devel-2.0.35-11.el6.x86.rpm
./configure --enable-embedded-perl 配置完成后
Make all
Make install
Make install-init
Make install-commandmode
Make install-config
Make install-webconf
Cd /usr/local/nagios/
Cd etc/
Vi nagios.cfg 主配置文件
Cd objects/
Vi commands.cfg 命令配置文件
Cd /usr/local/nagios/libexec/
Tar zxf nagios-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 -y mailx
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 -p localhost.cfg hosts.cfg
Cp -p localhost.cfg servers.cfg
Vi hosts.cfg 更改如下:
Define host{
Use linux-server
Host_name server67.example.com
Alias Manager
Address 192.168.0.196
Icon_p_w_picpath server.gif
Statusmap_p_w_picpath server.gd2
2d_coords 500,200
3d_coords 500,200,100
}
Define hostgroup{
Hostgroup_name linux-server
Alias linux Server
Members *
}
Vi servers.cfg更改如下:
删除掉所有的hosts,替换所有的田朝阳家用机为server96.example.com
:%s/田朝阳家用机/server96.example.com/g
Define servicegroup{
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
Create database nagdb;
Grant select on nagdb.* to nagios@’192.168.0.196’ ;
Server96 上
Cd /usr/local/nagio/libexec
./check_mysql --help
./check_mysql -H 192.168.0.127 -u nagios -d nagdb
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$
}
Vi hosts.cfg更改如下:
define host{
use linux-server
host_name mytest2
alias mysql
address 192.168.11.185
icon_p_w_picpath server.gif
statusmap_p_w_picpath 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/nagios reload
Vi contacts.cfg 设置监控的内容出现错误时email通知的地址
Define contact{
Contact_name nagiosadmin
Use generic-contact
Alias Nagios Admin
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
Mail yakexi007@westos.org 发送测试邮件
在/usr/locl/nagios/var/ 查看nagios的日志nagios.log
用nagios监控其他主机的磁盘,用户,根分区等要在所要监控的织机上安装nagios的插件
Server27
Get nrpe-2.14.tar.gz
Tar zxf nrpe-2.14.tar.gz
在 nrpe-2.14/docs/查看安装步骤
Evince NRPE.pdf &
Useradd nagios
Get nagios-plugins-1.4.16.tar.gz
Tar nagios-plugins-1.4.16.tar.gz
Cd nagios-plugins-1.4.16
Yum install gcc make -y
./configure 配置出现如图但要支持那些功能
Yum install –y mysql-devel openssl-devel
./configure
Make &&make install
Cd /usr/local/
Ll -d nagios
Chown -R nagios.nagios nagios/
Chown -R nagios.nagios /usr/local/nagios/libexec
Yum install xinetd -y
Cd nrpe-2.14
./configure
Make all
Make install-plugin
Make install-daemon
Make install-daemon-config
Make install-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 | grep 5666
Cd /usr/local/nagios/etc/
Vim nrpe.cfg 更改如下:
更改这行如command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
/etc/init.d/xinetd restart
在server96上也安装nrpe
Tar zxf nrpe-2.14.tar.gz
Cd nrpe-2.14
./configure
Make all
Make install-plugin
Cd /usr/local/nagios/libexec/
./check_nrpe -H 192.168.0.127
如果出现NRPE V2.14则配置成功
./check_nrpe -H 192.168.0.127 -c check_disk
./check_nrpe -H 192.168.0.127 -c check_users
Cd /usr/local/nagios/etc/objects/
Vi commands.cfg添加
Define command{
Command_name check_nrpe
Command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
Vi services.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,系统负荷
}
Define service{
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
}
Define service{
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 这样就可以在图形中监控另外一台主机的根分区,登录用户等信息了。
当系统出现问题时用飞信给管理员发短信
Get fetion linuxso_2010113.tar.gz
Mv fetion /usr/local/nagios/libexec/
Cd /usr/lib/
Tar zxf linuxso_20101113.tar.gz -C /usr/lib
Cd /usr/lib
Ll
Chmod +x libACE-5.7.2.so libACE_ssl-5.7.2.so libcrypto.so.4 libssl.so.4
Ldconfig /usr/lib 不关机的情况下更新系统的库
Cd/usr/local/nagios/libexec/
Chmod +x fetion
Chown nagios.nagios fetion
./fetion 运行飞信提示错误
-bash:./fetion:/lib/ld-linux.so.2:bad ELF interpreter Nosuch file or directory
Yum install –y /lib/ld-linux.so.2
Su nagios
/usr/local/nagios/libexec/fetion提示错误 error while loading share libraries :libstdc++.so.6
Su - root
Yum install libstdc++.so.6 -y
Su - nagios
/usr/local/nagios/libexec/fetion提示错误error while loading shared libraries:libgssapi_krb5.so.2
Su - root
Yum install -y libgssapi_krb5.so.2
Su - nagios
/usr/local/nagios/libexec/fetion提示错误error while 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/libexec scp 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
Vi commands.cfg 更改如下:
Define command{
Command_name notify-host-by-fetion
Command_line $USER1$/fetion.sh $CONTACTPAGER$”NOTIFICATIONTYPE$Host Alert: $HOSTNAME$ is $HOSTSTATE$”
}
Define command{
Command_name notify-service-by-fetion
Command_line $USER1$/fetion.sh $CONTACTPAGER$ “$NOTIFICATIONTYPE service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICETATE$”
}
Vi templates.cfg 更改如下:
Define contact{
在这一样添加如下:
Host_notification_commands notify-host-by-email,notify-host-by-fetion
}
Vi contacts.cfg更改如下:
Define contact{
加一行 pager 18209184795
}
/urs/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios reload
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。