用 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 -l2. 安装软件
yum install -y gcc glibc glibc-common yum install -y gd gd-develyum install -y mysql-server mysql-develyum install -y httpd php php-gd3. 创建用户组和用户
/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 apache4. 启动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: no8. 编译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_nrpe9.启动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_iostat4.配置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.34vi 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.cfg8. 验证
/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]#
- 用 KVM 搭建web集群实验笔记 - nagios 安装配置
- 用 KVM 搭建web集群实验笔记 - 安装Nginx 和配置Web服务
- 用 KVM 搭建web集群实验笔记 - 环境准备
- 用 KVM 搭建web集群实验笔记 - LNMP
- 用 KVM 搭建web集群实验笔记 - memcached
- 用 KVM 搭建web集群实验笔记 - NFS & Samba 服务
- 用 KVM 搭建web集群实验笔记 - MySQL多实例和主从复制
- 用 KVM 搭建web集群实验笔记 - LVS和Keeplived负载均衡(DR模式)
- nagios配置安装笔记
- nagios安装配置笔记
- nagios安装和配置笔记
- nagios安装和配置笔记
- Hadoop集群安装配置实验
- Web集群搭建(3)-集群配置
- 搭建集群jdk安装配置
- zookeeper安装,配置,搭建集群
- Centos 下面安装nagios安装和配置笔记
- nagios安装与配置
- 根据递推公式构造系数矩阵用于快速幂
- Android网络编程之使用HttpClient批量上传文件(二)AsyncTask+HttpClient并实现上传进度监听
- 在Jupyter notebook和spyder上用python做数据挖掘,安装使用简介和常见错误
- c# Relative Path convert to Absolute Path
- POJ 2955 Brackets (区间DP,括号匹配)
- 用 KVM 搭建web集群实验笔记 - nagios 安装配置
- EF6
- Android网络编程之获取网络上的Json
- 经典图形的绘制(matlab)
- Url中处理中文参数问题
- 反范式
- hbm2dll的4种用法
- TensorFlow安装配置
- Oracle、MySql、SQLServer 数据分页查询