用 KVM 搭建web集群实验笔记 - nagios 安装配置

来源:互联网 发布:万网域名不备案能用吗 编辑:程序博客网 时间:2024/06/06 04:24

Nagios 是一个开源的监控工具,能够监控 windows、Linux等系统的主机状态信息,以及交换机、路由器等网络设备。Nagios有一个主程序(Nagios)、一个插件程序(Nagios-plugins)和一些可选的附加程序 (NPRE、NSClient++、NSCA 和NDAOUtils)等组成。

服务器端:安装nagios和nagios-plugins插件(必选),NDOUtils(可选),存储配置信息和产生的数据。

客服端:linux/unix 安装NRPE组件( 被动方式),windows安装NSClient++组件。

服务器  nagios 192.168.122.34

客户端 nfssvr 192.168.122.41

一、 服务器安装

在nagios上执行操作

1. 配置对时,192.168.122.1为服务器

echo '#time sync by oliver on 2016-09-30 ' >> /var/spool/cron/rootecho '*/5 * * * * /usr/sbin/ntpdate 192.168.122.1 > /dev/null 2>&1' >> /var/spool/cron/rootcrontab -l
2. 安装软件

yum install -y gcc glibc glibc-common yum install -y gd gd-develyum install -y mysql-server mysql-develyum install -y httpd php php-gd
3. 创建用户组和用户

/usr/sbin/useradd nagios -g nagios /usr/sbin/useradd apache -g nagios -M -s /sbin/nologin/usr/sbin/groupadd nagcmd/usr/sbin/usermod -a -G nagcmd nagios/usr/sbin/usermod -a -G nagcmd apache
4. 启动httpd

vi /etc/httpd/conf/httpd.conf

设置

ServerName 192.168.122.34:80

service httpd start 或者 /etc/init.d/httpd start

5. 下载nagios的软件包

check_iostatcheck_memory.plClass-Accessor-0.31.tar.gzConfig-Tiny-2.12.tar.gzlibart_lgpl-2.3.17.tar.gzMath-Calc-Units-1.07.tar.gznagios-3.5.1.tar.gzNagios-Plugin-0.34.tar.gznagios-plugins-1.4.16.tar.gznrpe-2.12.tar.gzParams-Validate-0.91.tar.gzpnp-0.4.14.tar.gzRegexp-Common-2010010201.tar.gzrrdtool-1.2.14.tar.gz
在网上可以搜到。可以进入http://www.filewatcher.com/ 这个网站搜。

6. 编译nagios-3.5.1.tar.gz

tar -xvf nagios-3.5.1.tar.gzcd nagios./configure --with-command-group=nagcmdmake allmake installmake install-initmake install-configmake install-commandmodemake install-webconfhtpasswd -bc /usr/local/nagios/etc/htpasswd.users nagios 123456service httpd restart

配置邮件(这一步没有实际测试)

sed -i 's#nagios@localhost#em21@qq.com#g' /usr/local/nagios/etc/objects/contacts.cfg

7. 编译nagios-plugins-1.4.16.tar.gz

tar xvf nagios-plugins-1.4.16.tar.gzcd nagios-plugins-1.4.16./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules --with-mysqlmakemake installcd ..
确认configure的输出,然后在执行make 和 make install

config.status: creating po/Makefile            --with-apt-get-command:               --with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s               --with-ping-command: /bin/ping -n -U -w %d -c %d %s                       --with-ipv6: yes                      --with-mysql: /usr/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                   --enable-libtap: no
8. 编译nrpe-2.12.tar.gz
tar xvf nrpe-2.12.tar.gzcd nrpe-2.12./configuremake allmake install-pluginmake install-daemonmake install-daemon-configls /usr/local/nagios/libexec/check_nrpe
9.启动httpd和nagios
chkconfig httpd onchkconfig nagios on
二、 客服端安装配置

在nfssvr上操作

1.安装基本软件、增加用户

yum install -y gcc glibc glibc-commonyum install -y mysql-server mysql-develyum install -y perl-devel perl-CPAN openssl-develuseradd nagios -M -s /sbin/nologin

2.编译nagios-plugins-1.4.16.tar.gz

tar -xvf nagios-plugins-1.4.16.tar.gzcd nagios-plugins-1.4.16./configure --with-nagios=nagios --with-nagios-group=nagios --enable-perl-modules --with-mysqlmakemake installcd ..

检查插件个数

[root@nfssvr _soft]# ls /usr/local/nagios/libexec/ |wc -l58[root@nfssvr _soft]# 
3.安装插件

#---------------tar xvf nrpe-2.12.tar.gzcd nrpe-2.12./configuremake allmake install-pluginmake install-daemonmake install-daemon-configcd ..#-------------------------tar xvf Params-Validate-0.91.tar.gzcd Params-Validate-0.91perl Makefile.PLmakemake installcd ..#----------------------------------tar xvf Class-Accessor-0.31.tar.gzcd Class-Accessor-0.31 perl Makefile.PLmakemake installcd ..#---------------------------------tar xvf Config-Tiny-2.12.tar.gzcd Config-Tiny-2.12 perl Makefile.PLmakemake installcd ..#-------------------------------tar xvf Math-Calc-Units-1.07.tar.gzcd Math-Calc-Units-1.07perl Makefile.PLmakemake installcd ..#-------------------------------tar xvf Regexp-Common-2010010201.tar.gzcd Regexp-Common-2010010201perl Makefile.PLmakemake installcd ..#-------------------------------tar xvf Nagios-Plugin-0.34.tar.gzcd Nagios-Plugin-0.34perl Makefile.PLmakemake installcd ..yum install -y sysstatyum install -y dos2unixcp /_soft/check_memory.pl /usr/local/nagios/libexeccp /_soft/check_iostat /usr/local/nagios/libexecchmod 755 check_memory.plchmod 755 check_iostatdos2unix /usr/local/nagios/libexec/check_memory.pldos2unix /usr/local/nagios/libexec/check_iostat
4.配置nrpe服务

[root@nfssvr etc]# cd /usr/local/nagios/etc[root@nfssvr etc]# sed -n '79'p nrpe.cfgallowed_hosts=127.0.0.1[root@nfssvr etc]# sed -i 's#allowed_hosts=127.0.0.1#allowed_hosts=127.0.0.1,192.168.122.34#g' nrpe.cfg[root@nfssvr etc]# sed -n '79'p nrpe.cfgallowed_hosts=127.0.0.1,192.168.122.34
vi nrpe.cfg
199~233行替换为
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20command[check_hda1]=/usr/local/nagios/libexec/check_memory.pl -w 10% -c 3%command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 15% -c 7% -p /command[check_hda1]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%  command[check_hda1]=/usr/local/nagios/libexec/check_iostat -w 6 -c 10
启动nrep服务并检查

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -dnetstat -lntup|grep nrpeps -ef|grep nrpe |grep -v grep
三、服务器端配置

1.编辑 /usr/local/nagios/etc/nagios.cfg

在34行下增加
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_dir=/usr/local/nagios/etc/objects/services

注释
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

2. 在ojbects 下将services目录

3. 配置/usr/local/nagios/etc/objects/hosts.cfg

cd /usr/local/nagios/etc/objectshead -51 localhost.cfg > hosts.cfgchown nagios.nagios /usr/local/nagios/etc/objects/hosts.cfg
增加host
define host{        use                     linux-server            ; Name of host template to use                                                        ; This host definition will inherit all variables that are defined                                                        ; in (or inherited by) the linux-server host template definition.        host_name               nfssvr        alias                   nfssvr        address                 192.168.122.41        }
在组内增加一个成员

define hostgroup{        hostgroup_name  linux-servers ; The name of the hostgroup        alias           Linux Servers ; Long name of the group        members         nfssvr     ; Comma separated list of hosts that belong to this group        }

4. 配置/usr/local/nagios/etc/objects/services.cfg

touch services.cfg
chown nagios.nagios services.cfg

增加以下内容

define service {    use                       generic-service    host_name                 nfssvr    service_description       Disk Partition    check_command             check_nrpe!check_disk}define service {    use                       generic-service    host_name                 nfssvr    service_description       Swap Useage    check_command             check_nrpe!check_swap}define service {    use                       generic-service    host_name                 nfssvr    service_description       MEM Useage    check_command             check_nrpe!check_mem}define service {    use                       generic-service    host_name                 nfssvr    service_description       Current Load    check_command             check_nrpe!check_load}define service {    use                       generic-service    host_name                 nfssvr    service_description       Disk Iostat    check_command             check_nrpe!check_iostat!5!11}define service {    use                       generic-service    host_name                 nfssvr    service_description       PING    check_command             check_ping!100.0,20%!500.0,60%}

5. 配置/usr/local/nagios/etc/objects/commands.cfg

增加以下内容

define command{       command_name    check_nrpe       command_line    $USER1$/check_nrpe -h $HOSTADDRESS$ -c $ARG1$       }
6.建目录

mkdir -p /usr/local/nagios/etc/objects/serviceschown -R nagios.nagios services

7. 修改 /usr/local/nagios/etc/cgi.cfg

将授权用户改为nagios,否则用nagios登录,不能查看相应的信息。

grep ^"authorized_for" cgi.cfgsed -i 's#nagiosadmin#nagios#g' cgi.cfg
8. 验证

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

验证无误后重新启动nagios服务

servie nagios restart

9. 浏览器登录

四、问题诊断

如出现问题,可用以下方法诊断。

1. 检查客服端的nrpe是否能连接上,连接上会打印出版本号

在服务器端操作

[root@nagios libexec]# pwd/usr/local/nagios/libexec[root@nagios libexec]# ./check_nrpe -H 192.168.122.41Connection refused by host[root@nagios libexec]# ./check_nrpe -H 192.168.122.41NRPE v2.12[root@nagios libexec]# 

2. 检查某个service是否正常

在服务器端操作

[root@nagios libexec]# ./check_nrpe -H 192.168.122.41 -c check_memOK - 77.9% (391240 kB) free.|TOTAL=502096KB;;;; USED=110856KB;;;; FREE=391240KB;;;; CACHES=54296KB;;;;[root@nagios libexec]# ./check_nrpe -H 192.168.122.41 -c check_diskDISK OK - free space: / 8937 MB (90% inode=95%);| /=990MB;8895;9732;0;10465[root@nagios libexec]# 

如无返回可以倒客服端上执行相应的命令,及在客户端上执行如下命令(在/usr/local/nagios/etc/nrpe.cfg)

[root@nfssvr etc]# /usr/local/nagios/libexec/check_disk -w 15% -c 7% -p /DISK OK - free space: / 8937 MB (90% inode=95%);| /=990MB;8895;9732;0;10465[root@nfssvr etc]# 







0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 广联达识别板筋负筋重叠怎么办 掌上品的钱怎么办 财务纠纷被起诉怎么办 牙齿补后疼痛怎么办 牙齿表面蛀了怎么办 虫牙全掉了怎么办 牙齿蛀光了怎么办 虫牙全部掉完了怎么办 不喜欢向人请教怎么办 单位不交公积金怎么办 电锯链条掉了怎么办 天津公积金怎么办外地转入 学籍档案涂抹了怎么办 气相点火失败怎么办 小米闹钟声音小怎么办 河北省监理员证怎么办 买的商铺烂尾了怎么办 钢表带被磨花了怎么办 资料员到期了怎么办 八大员挂靠社保怎么办 安许证三类人员不足了怎么办 考试准考证号写错了怎么办 科目一失约两次怎么办 钢筋送检两次不合格怎么办 公路原材料抽检不合格怎么办 混凝土回弹强度不合格怎么办 毕业证照片太丑怎么办 政审时找不到档案怎么办 劳动解除书开不出来怎么办 双流办健康证怎么办 户口本人数满了怎么办 二建有效期到了怎么办 二级建造师到期怎么办 网上选车牌号后怎么办 政府拖欠水利工程款怎么办 重庆造价员到期了怎么办 枕大神经发炎怎么办 塑钢推拉窗下沉怎么办 网上买东西数量不够怎么办 淘宝买东西数量不够怎么办 康佳遥控器坏了怎么办