在centos上使用AWS官方的硬盘和内存监控脚本,会发现脚本出错,无法正常工作,这是因为aws的官方文档中提到该脚本没有在centos上做过测试,并不能保证脚本能正常使用 那么该如何解决呢,需要安装以下软件:
yuminstall-yperl-CPAN exportPERL_MM_USE_DEFAULT=1 #setupdefaultconfig perl-MCPAN-eshell#进入MCPANShell,自动生成默认配置,并退出 #类似于yum,下载安装各种包,需要花点时间 perl-MCPAN-e'CPAN::Shell->rematein("notest","install","Bundle::CPAN")' perl-MCPAN-e'CPAN::Shell->rematein("notest","CPAN")' perl-MCPAN-e'CPAN::Shell->rematein("notest","Bundle::LWP")' perl-MCPAN-e'CPAN::Shell->rematein("notest","LWP")' perl-MCPAN-e'CPAN::Shell->rematein("notest","LWP::Protocol::https")' perl-MCPAN-e'CPAN::Shell->rematein("notest","Crypt::SSLeay")' perl-MCPAN-e'CPAN::Shell->rematein("notest","Switch")'
安装完成后,可能仍然会出现问题:
Can'tlocateobjectmethod"new"viapackage"LWP::Protocol::https::Socket"
需要再次安装:
cpan> installNet::HTTPS installNet::SSL installIO::Socket::SSL
但是仍然报错:
[root@serveraws-scripts-mon1]#perlmon-put-instance-data.pl--mem-util ERROR:FailedtocallCloudWatch:HTTP500.Message:Can'tconnecttomonitoring.us-east-1.amazonaws.com:443 (Crypt-SSLeaycan'tverifyhostnames)Net::SSLfromCrypt-SSLeaycan'tverifyhostnames; eitherinstallIO::Socket::SSLorturnoffverificationbysettingthePERL_LWP_SSL_VERIFY_HOSTNAME environmentvariableto0at/usr/local/share/perl5/LWP/Protocol/http.pmline46.
提示IO::Socket::SSL没安装,但确实是安装了;不过,根据错误提示可以设置环境变量得以解决
[root@pa01aws-scripts-mon]#exportPERL_LWP_SSL_VERIFY_HOSTNAME=0 [root@pa01aws-scripts-mon]#perlmon-put-instance-data.pl--mem-util SuccessfullyreportedmetricstoCloudWatch.ReferenceId:cab2a044-1515-11e7-9631-9fb8068ec2cc
再次执行就成功了;但是,注意监控脚本一般是放在crontab中执行的,因此crontab中还需要加入环境变量
*/5****exportPERL_LWP_SSL_VERIFY_HOSTNAME=0&&perl/opt/alarm/aws-scripts-mon/mon-put-instance-data.pl--mem-util--mem-avail--mem-used--swap-used--swap-util原文链接:https://www.f2er.com/centos/378138.html