Nagios安装与配置
分类:运维技术日期:2013-10-27 - 16:05:19作者:老谢
本篇文章使用MarkDown写作!
公司近期需要搭建一个监控平台,主要目的是实现服务器服务或负载异常的及时报警功能,经过选择最终决定使用Nagios实现
安装Nagios Core
yum -y install gcc glibc glibc-common gd gd-devel php openssl-devel httpd useradd -m nagios #添加一个名为nagios的用户来运行nagios usermod -a -G nagios apache #将运行apache用户apache加入nagios组 wget http://ssh.xj123.info/monitor/nagios-3.5.0.tar.gz tar -zxf nagios-3.5.0.tar.gz mkdir /etc/httpd/conf/extra //用来存放关于nagios的http配置文件 cd nagios ./configure --prefix=/usr/local/nagios/ --with-comman-group=nagios --with-httpd-conf=/etc/httpd/conf/extra/ //指定安装目录及用户、组和http的配置目录 make all&&make install make install-init;make install-config;make install-commandmode;make install-webconf //初始生成启动脚本、配置文件、命令配置模块和httpd的配置文件 |
安装nagios plugins
wget http://ssh.xj123.info/monitor/nagios-plugins-1.5.tar.gz tar -zxf nagios-plugins-1.5.tar.gz cd nagios-plugins-1.5 ./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios/ //指定安装目录及用户和组 make all&&make install |
配置Apache
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin //创建登陆用户名nagiosadmin及密码,为web登陆时的用户名和密码 vim /etc/httpd/conf/httpd.conf #添加如下行,让nagios.conf生效 Include conf/extra/nagios.conf |
启动各项服务
chkconfig --add nagios
chkconfig nagios on
chkconfig httpd on
service nagios start
service httpd start |
安装NRPE
客户端安装nagios插件
useradd -s /sbin/nologin nagios //添加nagios用户 cd /usr/local/src tar zxvf nagios-plugins-1.4.16.tar.gz cd nagios-plugins-1.4.16 ./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios/ //指定安装目录及运行该软件用户和组 make&&make install |
客户端安装nrpe
wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz tar -zxf nrpe-2.14.tar.gz cd nrpe-2.14 ./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios/ make all make install-plugin;make install-daemon;make install-daemon-config ls /usr/local/nagios/libexec/ //验证安装 |
客户端配置、启动、测试NRPE
cd /usr/local/nagios/ vim etc/nrpe.cfg #找到allowed_hosts添加服务器端ip:allowed_hosts=127.0.0.1,23.监控服务器ip /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d //启动NRPE守护进程 netstat -utpln |grep nrpe //查看nrpe进程是否已正常启动 tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 17619/nrpe echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >>/etc/rc.local //添加nrpe为开机自动启动 /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 NRPE v2.14 //nrpe测试结果,此结果为nrpe已经正常工作了 |
自定义监控内容
vim /usr/local/nagios/etc/nrpe.cfg command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10 #监控登陆的用户数量 command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20 #监控CPU的负载 command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2 #监控磁盘利用率,这里的sda2必须是实际的硬盘分区,可使用fdisk –l查 command[check_swap]=/usr/local/nagios//libexec/check_swap -w 20 -c 10 #监控交换空间 command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z #监控进程中的僵尸进程 command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200 #监控所有进程 注意:command后面括号中的内容就是定义的变量,变量名可以任意指定,只需和服务器配置文件中的一致即可 |
服务器端安装NRPE插件
wget http://ssh.xj123.info/monitor/nrpe-2.14.tar.gz tar -zxf nrpe-2.14.tar.gz cd nrpe-2.14 ./configure --with-nagios-user=nagios -with-nagios-group=nagios --prefix=/usr/local/nagios/ make all;make install-plugin ; make install-daemon;make install-daemon-config //将check_nrpe插件安装到/usr/local/nagios/libexec/目录下 /usr/local/nagios/libexec/check_nrpe -H 客户端ip NRPE v2.14 //该结果表示能与客户端通讯 |
配置Nagios服务器支持远程监控
添加监控主机
cd /usr/local/nagios/etc/objects vim host.cfg define host{ use linux-server host_name slaves address 192.168.8.15 } |
定义要监控的服务
# vim services.cfg #定义要监控的服务 define service{ use local-service host_name slaves service_description http check_command check_http } |
添加定义check_nrpe命令
vim commands.cfg #定义check_nrpe监控命令 define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ } |
添加host.cfg及ervices.cfg到nagios.cfg
cd /usr/local/nagios/etc vim nagios.cfg cfg_file=/usr/local/nagios//etc/objects/host.cfg cfg_file=/usr/local/nagios//etc/objects/services.cfg |
修改接受报警邮箱
vim contacts.cfg email test@test.com ; #请修改为自己的邮箱地址 |
测试及启动Nagios服务
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #检测配置文件是否正确 Total Warnings: 0 Total Errors: 0 #结果表示配置无错误 service nagios restart #重启Nagios服务 |
主要参考(感谢以下所有文章的作者):
http://loosky.net/2758.html
http://night85.blog.51cto.com/231209/271546
http://blog.csdn.net/xiangliangyu/article/details/7758739
暂时没有评论!