﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-xiaoguozi's Blog</title><link>http://www.cppblog.com/guojingjia2006/</link><description>Pay it forword - 我并不觉的自豪，我所尝试的事情都失败了······习惯原本生活的人不容易改变，就算现状很糟，他们也很难改变，在过程中，他们还是放弃了······他们一放弃，大家就都是输家······让爱传出去，很困难，也无法预料，人们需要更细心的观察别人，要随时注意才能保护别人，因为他们未必知道自己要什么·····</description><language>zh-cn</language><lastBuildDate>Sun, 19 Apr 2026 12:16:44 GMT</lastBuildDate><pubDate>Sun, 19 Apr 2026 12:16:44 GMT</pubDate><ttl>60</ttl><item><title> JavaSript模块规范 - AMD规范与CMD规范介绍</title><link>http://www.cppblog.com/guojingjia2006/archive/2014/09/10/208263.html</link><dc:creator>小果子</dc:creator><author>小果子</author><pubDate>Wed, 10 Sep 2014 10:09:00 GMT</pubDate><guid>http://www.cppblog.com/guojingjia2006/archive/2014/09/10/208263.html</guid><wfw:comment>http://www.cppblog.com/guojingjia2006/comments/208263.html</wfw:comment><comments>http://www.cppblog.com/guojingjia2006/archive/2014/09/10/208263.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guojingjia2006/comments/commentRss/208263.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guojingjia2006/services/trackbacks/208263.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: JavaSript模块化&nbsp;&nbsp;&nbsp;&nbsp;在了解AMD，CMD规范前，还是需要先来简单地了解下什么是模块化，模块化开发？&nbsp;&nbsp;&nbsp;&nbsp;模块化是指在解决某一个复杂问题或者一系列的杂糅问题时，依照一种分类的思维把问题进行系统性的分解以之处理。模块化是一种处理复杂系统分解为代码结构更合理，可维护性更高的可管理的模块的方式。可以想象一个巨大的...&nbsp;&nbsp;<a href='http://www.cppblog.com/guojingjia2006/archive/2014/09/10/208263.html'>阅读全文</a><img src ="http://www.cppblog.com/guojingjia2006/aggbug/208263.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guojingjia2006/" target="_blank">小果子</a> 2014-09-10 18:09 <a href="http://www.cppblog.com/guojingjia2006/archive/2014/09/10/208263.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> shrio 权限管理filterChainDefinitions过滤器配置 </title><link>http://www.cppblog.com/guojingjia2006/archive/2014/05/14/206956.html</link><dc:creator>小果子</dc:creator><author>小果子</author><pubDate>Wed, 14 May 2014 03:57:00 GMT</pubDate><guid>http://www.cppblog.com/guojingjia2006/archive/2014/05/14/206956.html</guid><wfw:comment>http://www.cppblog.com/guojingjia2006/comments/206956.html</wfw:comment><comments>http://www.cppblog.com/guojingjia2006/archive/2014/05/14/206956.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/guojingjia2006/comments/commentRss/206956.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guojingjia2006/services/trackbacks/206956.html</trackback:ping><description><![CDATA[<div><p><span>/** </span></p> <p><span>* Shiro-1.2.2内置的FilterChain </span></p> <p><span><span>* @see  =============================================================================================================================</span> </span></p> <p><span>* @see 1)Shiro验证URL时,URL匹配成功便不再继续匹配查找(所以要注意配置文件中的URL顺序,尤其在使用通配符时) </span></p> <p><span>* @see&nbsp;&nbsp; 故filterChainDefinitions的配置顺序为自上而下,以最上面的为准 </span></p> <p><span>* @see 2)当运行一个Web应用程序时,Shiro将会创建一些有用的默认Filter实例,并自动地在[main]项中将它们置为可用 </span></p> <p><span>* @see&nbsp;&nbsp; 自动地可用的默认的Filter实例是被DefaultFilter枚举类定义的,枚举的名称字段就是可供配置的名称 </span></p> <p><span>* @see&nbsp;&nbsp; anon---------------org.apache.shiro.web.filter.authc.AnonymousFilter </span></p> <p><span>* @see&nbsp;&nbsp; authc--------------org.apache.shiro.web.filter.authc.FormAuthenticationFilter </span></p> <p><span>* @see&nbsp;&nbsp; authcBasic---------org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter </span></p> <p><span>* @see&nbsp;&nbsp; logout-------------org.apache.shiro.web.filter.authc.LogoutFilter </span></p> <p><span>* @see&nbsp;&nbsp; noSessionCreation--org.apache.shiro.web.filter.session.NoSessionCreationFilter </span></p> <p><span>* @see&nbsp;&nbsp; perms--------------org.apache.shiro.web.filter.authz.PermissionAuthorizationFilter </span></p> <p><span>* @see&nbsp;&nbsp; port---------------org.apache.shiro.web.filter.authz.PortFilter </span></p> <p><span>* @see&nbsp;&nbsp; rest---------------org.apache.shiro.web.filter.authz.HttpMethodPermissionFilter </span></p> <p><span>* @see&nbsp;&nbsp; roles--------------org.apache.shiro.web.filter.authz.RolesAuthorizationFilter </span></p> <p><span>*&nbsp;@see&nbsp;&nbsp; ssl----------------org.apache.shiro.web.filter.authz.SslFilter </span></p> <p><span>&nbsp;<a target="_blank" href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#42;&#64;&#115;&#101;&#101;">*@see</a>&nbsp;&nbsp; user---------------org.apache.shiro.web.filter.authz.UserFilter </span></p> <p><span><span>* @see  =============================================================================================================================</span> </span></p> <p><span>* @see 3)通常可将这些过滤器分为两组 </span></p> <p><span>* @see&nbsp;&nbsp; anon,authc,authcBasic,user是第一组认证过滤器 </span></p> <p><span>* @see&nbsp;&nbsp; perms,port,rest,roles,ssl是第二组授权过滤器 </span></p> <p><span>* @see&nbsp;&nbsp; 注意user和authc不同：当应用开启了rememberMe时,用户下次访问时可以是一个user,但绝不会是authc,因为authc是需要重新认证的 </span></p> <p><span>* @see&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; user表示用户不一定已通过认证,只要曾被Shiro记住过登录状态的用户就可以正常发起请求,比如rememberMe </span></p> <p><span>* @see&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 说白了,以前的一个用户登录时开启了rememberMe,然后他关闭浏览器,下次再访问时他就是一个user,而不会authc </span></p> <p><span><span>* @see  =============================================================================================================================</span> </span></p> <p><span>* @see 4)举几个例子 </span></p> <p><span>* @see&nbsp;&nbsp; /admin=authc,roles[admin]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 表示用户必需已通过认证,并拥有admin角色才可以正常发起'/admin'请求 </span></p> <p><span>* @see&nbsp;&nbsp; /edit=authc,perms[admin:edit]&nbsp; 表示用户必需已通过认证,并拥有admin:edit权限才可以正常发起'/edit'请求 </span></p> <p><span>* @see&nbsp;&nbsp; /home=user&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 表示用户不一定需要已经通过认证,只需要曾经被Shiro记住过登录状态就可以正常发起'/home'请求 </span></p> <p><span><span>* @see  =============================================================================================================================</span> </span></p> <p><span>* @see 5)各默认过滤器常用如下(注意URL Pattern里用到的是两颗星,这样才能实现任意层次的全匹配) </span></p> <p><span>* @see&nbsp;&nbsp; /admins/**=anon&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 无参,表示可匿名使用,可以理解为匿名用户或游客 </span></p> <p><span>* @see&nbsp;&nbsp; /admins/user/**=authc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 无参,表示需认证才能使用 </span></p> <p><span>* @see&nbsp;&nbsp; /admins/user/**=authcBasic&nbsp; 无参,表示httpBasic认证 </span></p> <p><span>* @see&nbsp;&nbsp; /admins/user/**=user&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 无参,表示必须存在用户,当登入操作时不做检查 </span></p> <p><span>* @see&nbsp;&nbsp; /admins/user/**=ssl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 无参,表示安全的URL请求,协议为https </span></p> <p><span>* @see&nbsp;&nbsp; /admins/user/**=perms[user:add:*] </span> </p> <p><span>* @see&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 参数可写多个,多参时必须加上引号,且参数之间用逗号分割,如/admins/user/**=perms["user:add:*,user:modify:*"] </span></p> <p><span>* @see&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 当有多个参数时必须每个参数都通过才算通过,相当于isPermitedAll()方法 </span></p> <p><span>* @see&nbsp;&nbsp; /admins/user/**=port[8081] </span></p> <p><span>* @see&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 当请求的URL端口不是8081时,跳转到schemal://serverName:8081?queryString </span></p> <p><span>* @see&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 其中schmal是协议http或https等,serverName是你访问的Host,8081是Port端口,queryString是你访问的URL里的?后面的参数 </span></p> <p><span>* @see&nbsp;&nbsp; /admins/user/**=rest[user] </span> </p> <p><span>* @see&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 根据请求的方法,相当于/admins/user/**=perms[user:method],其中method为post,get,delete等 </span></p> <p><span>* @see&nbsp;&nbsp; /admins/user/**=roles[admin] </span> </p> <p><span>* @see&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 参数可写多个,多个时必须加上引号,且参数之间用逗号分割,如/admins/user/**=roles["admin,guest"] </span></p> <p><span>* @see&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 当有多个参数时必须每个参数都通过才算通过,相当于hasAllRoles()方法 </span></p> <span>* @see<br /><br /><div>http://liureying.blog.163.com/blog/static/61513520136205574873/</div><br /><div>spring中 shiro logout 配置方式<br />     有两种方式实现logout<br />1. 普通的action中 实现自己的logout方法，取到Subject，然后logout<br />这种需要在ShiroFilterFactoryBean 中配置 filterChainDefinitions <br />对应的action的url为anon<br />&lt;property name="filterChainDefinitions"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;value&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # some example chain definitions:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /index.htm = anon<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /logout = anon<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /unauthed = anon<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /console/** = anon<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /css/** = anon<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /js/** = anon<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /lib/** = anon<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /admin/** = authc, roles[admin]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /docs/** = authc, perms[document:read]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /** = authc<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # more URL-to-FilterChain definitions here<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/value&gt;<br /><br />2. 使用shiro提供的logout filter<br />需要定义 相应的bean<br />&lt;bean id="logout" class="org.apache.shiro.web.filter.authc.LogoutFilter"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;property name="redirectUrl" value="/loginform" /&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/bean&gt;<br /><br />然后将相应的url filter配置为logout如下<br />&lt;property name="filterChainDefinitions"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;value&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # some example chain definitions:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /index.htm = anon<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>/logout = logout</strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /unauthed = anon<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /console/** = anon<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /css/** = anon<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /js/** = anon<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /lib/** = anon<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /admin/** = authc, roles[admin]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /docs/** = authc, perms[document:read]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /** = authc<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # more URL-to-FilterChain definitions here<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/value&gt;  </div><br /><div>http://kdboy.iteye.com/blog/1154652</div><div>http://blog.csdn.net/peterwanghao/article/details/8084126</div><div>http://www.oschina.net/question/593111_62454</div><div>http://blog.csdn.net/shadowsick/article/details/17265625</div><br /></span></div><img src ="http://www.cppblog.com/guojingjia2006/aggbug/206956.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guojingjia2006/" target="_blank">小果子</a> 2014-05-14 11:57 <a href="http://www.cppblog.com/guojingjia2006/archive/2014/05/14/206956.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CentOS 6下安装nodejs 0.9.0</title><link>http://www.cppblog.com/guojingjia2006/archive/2014/01/20/205486.html</link><dc:creator>小果子</dc:creator><author>小果子</author><pubDate>Mon, 20 Jan 2014 02:11:00 GMT</pubDate><guid>http://www.cppblog.com/guojingjia2006/archive/2014/01/20/205486.html</guid><wfw:comment>http://www.cppblog.com/guojingjia2006/comments/205486.html</wfw:comment><comments>http://www.cppblog.com/guojingjia2006/archive/2014/01/20/205486.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guojingjia2006/comments/commentRss/205486.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guojingjia2006/services/trackbacks/205486.html</trackback:ping><description><![CDATA[<div><div id="cnblogs_post_body"><p>确保安装了python，大部分安装失败都是由于python版本过低导致。安装之前，升级python版本，升级步骤 <a href="http://www.tomtalk.net/wiki/Python">http://www.tomtalk.net/wiki/Python</a>。</p>  <p>[root@SNDA-192-168-15-161 ~]# python -V   <br />Python 2.7.3    <br />开始安装：</p>  <p>1).下载nodejs到本地并解压缩   <br />[root@SNDA-192-168-15-161 node]# wget http://nodejs.org/dist/v0.9.0/node-v0.9.0.tar.gz    <br />[root@SNDA-192-168-15-161 node]# tar zxvf node-v0.9.0.tar.gz    <br />2).进入到该目录编译和安装    <br />[root@SNDA-192-168-15-161 node-v0.9.0]# cd node-v0.9.0    <br />[root@SNDA-192-168-15-161&nbsp; node-v0.9.0]# ./configure --prefix=/usr/local/node/0.9.0    <br />这里安装在了/usr/local/node/0.9.0目录下    <br />[root@SNDA-192-168-15-161 node-v0.9.0]# make    <br />[root@SNDA-192-168-15-161 node-v0.9.0]# make install    <br />3).配置NODE_HOME    <br />[root@SNDA-192-168-15-161 node-v0.9.0]# vi /etc/profile    <br />在export PATH USER 。。。一行的上面添加如下内容，并将NODE_HOME/bin设置到系统path中    <br />#set for nodejs    <br />export NODE_HOME=/usr/local/node/0.9.0    <br />export PATH=$NODE_HOME/bin:$PATH    <br />保存退出后执行如下命令，使刚才的配置生效    <br />[root@SNDA-192-168-15-161 node-v0.9.0]# source /etc/profile</p>  <p>执行node -h命令验证设置成功</p>  <p>[root@SNDA-192-168-15-161 ~]# node -h   <br />Usage: node [options] [ -e script | script.js ] [arguments]    <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; node debug script.js [arguments] </p>  <p>Options:   <br />&nbsp; -v, --version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print node's version    <br />&nbsp; -e, --eval script&nbsp;&nbsp;&nbsp; evaluate script    <br />&nbsp; -p, --print&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print result of --eval    <br />&nbsp; -i, --interactive&nbsp;&nbsp;&nbsp; always enter the REPL even if stdin    <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; does not appear to be a terminal    <br />&nbsp; --no-deprecation&nbsp;&nbsp;&nbsp;&nbsp; silence deprecation warnings    <br />&nbsp; --trace-deprecation&nbsp; show stack traces on deprecations    <br />&nbsp; --v8-options&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print v8 command line options    <br />&nbsp; --max-stack-size=val set max v8 stack size (bytes) </p>  <p>Environment variables:   <br />NODE_PATH&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ':'-separated list of directories    <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; prefixed to the module search path.    <br />NODE_MODULE_CONTEXTS&nbsp;&nbsp; Set to 1 to load modules in their own    <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; global contexts.    <br />NODE_DISABLE_COLORS&nbsp;&nbsp;&nbsp; Set to 1 to disable colors in the REPL </p>  <p>Documentation can be found at <a href="http://nodejs.org/">http://nodejs.org/</a>    <br />至此安装设置完毕。</p>  <p>运行一个简单的node应用程序 + socket.io，首先需要安装socket.io模块</p>  <p>[root@SNDA-192-168-15-161 ~]# npm install socket.io</p>  <p>[root@SNDA-192-168-15-161 ~]# vi app.js</p>  <p>var http=require('http');   <br />var io =require('socket.io');    <br />var server = http.createServer(function(req,res){ </p>  <p>&nbsp;&nbsp;&nbsp; res.writeHead(200,{'Content-Type':'text/plain'});   <br />&nbsp;&nbsp;&nbsp; res.end('Hello world');    <br />}); </p>  <p>server.listen(process.argv[2]); </p>  <p>var socket = io.listen(server);   <br />socket.on('connection',function(client){    <br />&nbsp;&nbsp;&nbsp; console.log('client has connected');    <br />&nbsp;&nbsp;&nbsp; client.on('message',function(){ });    <br />});    <br />&nbsp;</p>  <p>[root@SNDA-192-168-15-161 ~]# nodejs ./app.js 8001 &amp;</p>  <p>[root@SNDA-192-168-15-161 ~]# nodejs ./app.js 8002 &amp;</p>  <p>[root@SNDA-192-168-15-161 ~]# nodejs ./app.js 8003 &amp;</p>  <p>[root@SNDA-192-168-15-161 ~]# nodejs ./app.js 8004 &amp;</p>  <p>更详细的参照<a href="http://socket.io/#how-to-use">socket.io的官网</a>的例子。 </p>  <p><a href="http://cnodejs.org/topic/4f16442ccae1f4aa27001139" target="_blank">websocket与node.js的完美结合</a></p>  <p><a title="http://wanshuiqianshan.iteye.com/blog/1618498" href="http://wanshuiqianshan.iteye.com/blog/1618498">http://wanshuiqianshan.iteye.com/blog/1618498</a></p></div></div><img src ="http://www.cppblog.com/guojingjia2006/aggbug/205486.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guojingjia2006/" target="_blank">小果子</a> 2014-01-20 10:11 <a href="http://www.cppblog.com/guojingjia2006/archive/2014/01/20/205486.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Nagios插件编写及调试方法</title><link>http://www.cppblog.com/guojingjia2006/archive/2013/09/03/202981.html</link><dc:creator>小果子</dc:creator><author>小果子</author><pubDate>Tue, 03 Sep 2013 01:39:00 GMT</pubDate><guid>http://www.cppblog.com/guojingjia2006/archive/2013/09/03/202981.html</guid><wfw:comment>http://www.cppblog.com/guojingjia2006/comments/202981.html</wfw:comment><comments>http://www.cppblog.com/guojingjia2006/archive/2013/09/03/202981.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guojingjia2006/comments/commentRss/202981.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guojingjia2006/services/trackbacks/202981.html</trackback:ping><description><![CDATA[<div><p style="text-indent: 2em">前言：  Nagios是相当不错的监控工具，被称作是&#8220;监控之神&#8221;，但同样也有&#8220;难搞死&#8221;头衔。发挥Nagios一切魅力的都是他的插件，正因为丰富多样的插件让 nagios有血有肉。监控的内容不断在变化，插件也不断变化，默认的一些插件可能越来越不能满足需求，这个时候就要自己来写些插件了。</p> <p style="text-indent: 2em">以下就是用我的第一个Nagios插件来说明编写方法和我遇到一些问题调试方法。如果你有耐心可以通篇看完，应该对第一次写的人来说会有很大帮助（如果你看不懂，可能是我写得不清楚 那就没办法了 表达能力有限）</p> <p style="text-indent: 2em">需求：</p> <p style="text-indent: 2em">监控普通磁盘的健康状况（普通磁盘以外还有RAID、阵列的监控是不同方法来做的，这里先不讨论，先从最简单的入手），定期进行检测，并进行报警，报警内容磁盘是否正常，不正常是什么状态。</p> <p style="text-indent: 2em">分析编写过程：</p> <p style="text-indent: 2em">我写脚本的前提都是先从手动成功完成，再到自动化（我想其它人的思路应该都一样的）</p> <p style="text-indent: 2em">1、找到监控磁盘的方法</p> <p style="text-indent: 2em">通过一番查找 smartctl 这个命令是比较不错的&nbsp; centos slackware一般的默认都有这个</p> <p style="text-indent: 2em">smartctl -H /dev/sda&nbsp; 只检测状态</p> <p style="text-indent: 2em">smartctl -i /dev/sda&nbsp;&nbsp; 只检测硬盘信息</p> <p style="text-indent: 2em">smartctl -a /dev/sda 检测所有信息</p> <p style="text-indent: 2em">2、获取检测信息</p> <p style="text-indent: 2em"># smartctl -H /dev/sda</p> <p style="text-indent: 2em">smartctl version 5.38 [x86_64-redhat-linux-gnu] Copyright (C) 2002-8 Bruce Allen</p> <p style="text-indent: 2em">Home page is http://smartmontools.sourceforge.net/</p> <p style="text-indent: 2em">SMART Health Status: OK</p> <p style="text-indent: 2em">关键的最后一行说明磁盘的情况 &nbsp; &nbsp; &nbsp; 截取&nbsp; DISK_HEALTH=`smartctl -H /dev/sda | tail -1 | cut -d: -f2-&nbsp; `</p> <p style="text-indent: 2em">3、 进行关键判断</p> <p style="text-indent: 2em">据我所知道的 smartctl 5.38&nbsp; 是出以上的結果 为OK</p> <p style="text-indent: 2em">而 smartctl 5.39 是出以下結果</p> <p style="text-indent: 2em">=== START OF READ SMART DATA SECTION ===</p> <p style="text-indent: 2em">SMART overall-health self-assessment test result: PASSED</p> <p style="text-indent: 2em">关键词是PASSED</p> <p style="text-indent: 2em">所以要分析判断多种情况</p> <p style="text-indent: 2em">4、脚本编写步骤</p> <p style="text-indent: 2em">1）了解nagios插件编写规范</p> <p style="text-indent: 2em">Nagios的插件可以用脚本（shell、Perl）C编译后的可执行程序，但必须满足以下两件事：</p> <p style="text-indent: 2em">A、既出时有一个返回值</p> <p style="text-indent: 2em">B、至少向标准输出设备（STDOUT）输出一行文件。（但也不能太大，默认是4K，如果想大些，修改源程序吧，方法搜。) </p> <p style="text-indent: 2em">返回值定义：</p> <p style="text-indent: 2em">Plugin Return Code Service State DISK State <br />0 OK OK 或者PASSED <br />1 WARNING 插件警告&nbsp; DISK报警只分OK或者CRITICAL <br />2 CRITICAL&nbsp; DISK检测非OK 或者PASSED <br />3 UNKNOWN&nbsp; 未知状态 </p> <p style="text-indent: 2em">2)插件编写SHELL速成法</p> <p style="text-indent: 2em">在这里我选用我最熟悉的SHELL进行脚本编写 ,</p> <p style="text-indent: 2em">我的速成法就是，直接去nagios exchange 去下比较成熟的比较简单的shell脚本，这样会从一开始借鉴别人好的方法，养成好的习惯，而且只要你有一点SHELL编程经验也可以很快写得像一个老手。（不过不要把自己搞晕了就行）</p> <p style="text-indent: 2em">3）以下是我的check_disk_health.sh</p> <p style="text-indent: 2em">#!/bin/bash<br /># ========================================================================================<br /># disk health&nbsp; plugin for Nagios<br />#<br /># Written by&nbsp;&nbsp;&nbsp; : Ajian<br /># Release&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 1.2.0<br /># Creation date : 2009-07-28<br /># Revision date : 2009-07-30<br /># Description&nbsp;&nbsp; : Nagios plugin (script) to check disk health .<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This script has been designed and written on Linux System.<br />#<br /># USAGE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : ./check_disk_health.sh [-d (disk)]<br />#<br /># Exemple: ./check_cpu_stats.sh<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ./check_cpu_stats.sh -d /dev/sda<br />#<br />#<br /># HISTORY :<br />#&nbsp;&nbsp;&nbsp;&nbsp; Release&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; Authors&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Description<br /># --------------+---------------+----------------------+-----------------------------------<br />#&nbsp; 1.0.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2009-07-28&nbsp;&nbsp;&nbsp;&nbsp; | Ajian&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Create the script<br />#&nbsp; 1.2.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2009-07-30&nbsp;&nbsp;&nbsp; |&nbsp; Ajian&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | modify the script and run well ,fix a bug.<br /># -----------------------------------------------------------------------------------------<br /># NOTICE:<br />#-----------------------------------------------------------------------------------------<br />#&nbsp;&nbsp;&nbsp;&nbsp; You should have the root Permissions ,You can use sudo to realize .<br /># -----------------------------------------------------------------------------------------&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;<br /># Nagios return codes<br />#定义 nagios返回的状态变量<br />STATE_OK=0<br />STATE_WARNING=1<br />STATE_CRITICAL=2<br />STATE_UNKNOWN=3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;<br /># Paths to commands used in this script.&nbsp; These may have to be modified to match your system setup.<br /># 定义关键的核心命令smartctl 路径 如果你的系统不是这个地址，请更改。 以下注释的是调试的信息，是自动获取命令路径的方法。<br />SMARTCTL="/usr/sbin/smartctl"<br />#SMARTCTL=`which smartctl`<br />#if [ $? -ne 0 ]; then<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo " smartctl is found in $SMARTCTL ; Go on ... "<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "smartctl the command cannot find"<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit $STATE_UNKNOWN<br />#fi<br /># Plugin parameters value if not define<br /># 定义默认的检测硬盘<br />CHECK_DISK="/dev/sda"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;<br /># Plugin variable description<br /># 插件描述信息<br />PROGNAME=$(basename $0)<br />RELEASE="Revision 1.2.0"<br />AUTHOR="(c) 2009 Ajian ()"<br />&nbsp;<br /># Functions plugin usage<br /># 插件的使用方法函数<br />print_release() {<br />&nbsp;&nbsp;&nbsp; echo "$RELEASE $AUTHOR"<br />}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;<br />print_usage() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo ""<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "$PROGNAME $RELEASE - Disk health check script for Nagios"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo ""<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "Usage: check_disk_health.sh -d /dev/sdb"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo ""<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "&nbsp; -d&nbsp; the disk (/dev/sda) "<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; not the Hard disk partition(sda2 is wrong)"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "&nbsp; -v&nbsp; check the version"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "&nbsp; -h&nbsp; Show this page"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo ""<br />&nbsp;&nbsp;&nbsp; echo "Usage: $PROGNAME"<br />&nbsp;&nbsp;&nbsp; echo "Usage: $PROGNAME --help"<br />&nbsp;&nbsp;&nbsp; echo ""<br />&nbsp;&nbsp;&nbsp; exit 0<br />}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;<br />print_help() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print_usage<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo ""<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "This plugin will check disk health&nbsp; "<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo ""<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit 0<br />}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;<br /># Parse parameters<br /># 传递参数<br />while [ $# -gt 0 ]; do<br />&nbsp;&nbsp;&nbsp; case "$1" in<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -h | --help)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print_help<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit $STATE_OK<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -v | --version)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print_release<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit $STATE_OK<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -d | --disk)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shift<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CHECK_DISK=$1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #判断磁盘是否存在<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if [ ! -b $CHECK_DISK ];then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "$CHECK_DISK is no exsit,Please change it "<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit $STATE_CRITICAL<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *)&nbsp; echo "Unknown argument: $1"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print_usage<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit $STATE_UNKNOWN<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; esac<br />shift<br />done<br />&nbsp;<br />＃根据不同的操作进行不同的操作，这里暂时只支持Linux<br />case `uname` in<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Linux )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #最核心的部分 前面都是些脚本的基本功能 一个框架 因为第一个脚本牵扯到了很多东西，虽然功能很简单，<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #但折腾了我不少，在后面的分析中会具体说到 总之注意sudo用法 脚本一开始就有说哦<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DISK_HEALTH=`$SMARTCTL&nbsp; -H $CHECK_DISK | tail -1 | cut -d: -f2- `<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #DISK_HEALTH="OK"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DISK_INFO=`/usr/bin/sudo $SMARTCTL -i $CHECK_DISK | grep "Device:"`<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if [ "$DISK_HEALTH" = " OK" ]|| [&nbsp; "$DISK_HEALTH" = " PASSED" ];then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "OK - $CHECK_DISK status is $DISK_HEALTH "<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #echo "OK - $CHECK_DISK status is $DISK_HEALTH | $DISK_INFO"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit $STATE_OK<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "CRITICAL - $CHECK_DISK status is $DISK_HEALTH "<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #echo "CRITICAL - $CHECK_DISK status is $DISK_HEALTH | $DISK_INFO"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit $STATE_CRITICAL<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "UNKNOWN: `uname` not yet supported by this plugin. Coming soon !"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit $STATE_UNKNOWN<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; esac4)运行脚本</p> <p style="text-indent: 2em">（注意：在最开始自己写的脚本是没有sudo的，以上脚本是已经调试过后的，还需要配置一些其它的东西，慢慢看吧）<br />给与脚本执行权限，手动执行</p> <p style="text-indent: 2em"># ./check_disk_health.sh<br />OK &#8211; /dev/sda status is&nbsp; OK</p> <p style="text-indent: 2em">結果正确了，其实这个时候，高兴得太早了。 我先不说问题、继续正常的一般流程。</p> <p style="text-indent: 2em">5、配置Nagios 调用插件</p> <p style="text-indent: 2em">1）在远程NRPE 被监控服务器上修改nrpe.conf<br /># vim /usr/local/nagios/etc/nrpe.cfg<br />添加 command[check_sda_health]=/usr/local/nagios/libexec/check_disk_health.sh -d /dev/sda<br />（注意这里了，先提醒下，这里是错误的，一般是正确的，是这个脚本的特殊性造成的）</p> <p style="text-indent: 2em">2）在Nagios 监控服务器上添加一些配置</p> <p style="text-indent: 2em">定义服务</p> <p style="text-indent: 2em">define service{<br />use&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Disk-Health<br />host_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DB-56<br />servicegroups&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Disk-Health<br />service_description&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; check sda disk health<br />contact_groups&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; admins<br />check_command&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; check_nrpe!check_sda_health<br />}<br />如果像上面定义一个服务 那么就要注意相关的定义了 ，<br />定义Disk-Health 模版&nbsp; 把硬盘检测定义一个模版会比较好控制，因为硬盘的检测不像其它服务一样需要准确的及时性反正检测得太多可能会造成压力，一般一天检测几次就够了。<br />定义DB-56 主机需要定义<br />定义组 admins<br />以上这些只要安装过nagios 一般都知道的了 只是强调下模版的单独定义</p> <p style="text-indent: 2em">3)通过WEB控制检测 查看結果</p> <p style="text-indent: 2em">結果是失败 报警CRITCTL 但是状态里面的信息都是空的&nbsp; CRITCTL &#8211; /dev/sda status is</p> <p style="text-indent: 2em">6、调试</p> <p style="text-indent: 2em">从Nagios的远程监控来看是失败的，并且没有获取到任务有用的信息。</p> <p style="text-indent: 2em">分析可以看到，说明nrpe调用&nbsp; 这个变量获取到的是为空的信息<br />DISK_HEALTH=`$SMARTCTL -H $CHECK_DISK | tail -1 | cut -d: -f2- `<br />即是空的 只有一个原因，肯定是没有执行 如果执行了 肯定会有字段 不管这个字段是否相符。<br />但是手动执行是没有问题。<br />经过对smartctl的查看 原来这个命令是只允许root进行调用的。<br />现在需要解决的问题是：非root 用户 如何远程调用含有需要有root权限命令的脚本进行监控。<br />（不要小看这一句话，每一个词都是一个需要攻克的地方）<br />以下是调试步骤：<br />1）非root用户<br />NRPE插件是用nagios这个用户来执行的 所以要得到真实的情况需要<br />A： su nagios&nbsp;&nbsp; 再执行脚本 (这个方法比较好)<br />B： sudo -u nagios ./check_disk_health.sh<br />結果：</p> <p style="text-indent: 2em">sudo -u nagios ./check_disk_health.sh<br />CRITICAL &#8211; /dev/sda status is<br />跟远程的結果是一样的了 没有信息<br />2）需要有root权限<br />需要root权限只有一个办法就是用sudo<br />将DISK_HEALTH=`$SMARTCTL -H $CHECK_DISK | tail -1 | cut -d: -f2- `<br />改为DISK_HEALTH=`/usr/bin/sudo $SMARTCTL -H $CHECK_DISK | tail -1 | cut -d: -f2- `<br />（最后发现这时加sudo 并不是关键 关键是很行脚本时用sudo ）<br />結果：sudo -u nagios ./check_disk_health.sh<br />Password:<br />需要输入密码&nbsp; sudo不用输入密码的方法<br />修改sudo配置文件<br />执行 visudo<br />添加<br />nagios ALL=(ALL) NOPASSWD:/usr/local/nagios/libexec/check_disk_health.sh<br />建议：最好进行sudo的一些控制，很多网方法就是nagios ALL=NOPASSWD:ALL<br />结果：<br />su nagios<br />/usr/bin/sudo check_disk_health.sh<br />OK &#8211; /dev/sda status is OK<br />那么在nrpe.conf配置文件中需要添加sudo<br />command[check_sda_health]=/usr/bin/sudo /usr/local/nagios/libexec/check_disk_health.sh<br />最开始那个是错误的 注意啊 这个是需要添加/usr/bin/sudo 就是说只要脚本中涉及到提升到root权限的命令那么就要用这个<br />3）远程调用<br />远程调用方法：./check_nrpe -H 192.168.0.56 -c check_sda_health<br />同上如果想模拟真实环境请切换到相应的执行用户 su nagios 再执行以上操作<br />结果：&nbsp;&nbsp; NRPE: Unable to read output<br />这个错误的原因一定要明白，之所以报这个错意思是说NRPE没有获取到任何信息，也说是写脚本之前说的其中第二条规范<br />问题：在没有任何信息的情况下怎么来获取NRPE执行的日志呢<br />就是要确定问题在哪，经过一大番的查找眼睛偶尔看到一个有趣的小方法<br />修复nrpe.conf配置文件 在要检查的命令后面添加&gt;&gt;/tmp/output 2&gt;&amp;1 将错误导出到文件中进行查看<br />command[check_sda_health]=/usr/bin/sudo  /usr/local/nagios/libexec/check_disk_health.sh -d /dev/sda  &gt;&gt;/tmp/output 2&gt;&amp;1<br />重记nrpe服务<br />远程调用 结果当然还是NRPE: Unable to read output<br />查看/tmp/output<br />sudo: sorry, you must have a tty to run sudo<br />有错误就简单了&nbsp; 原来这个是默认不允许sudo 在后端进行<br />visudo<br />注释Defaults requiretty 就OK了<br />结果通过WEB查看也正确了。<br />(注意：注释后 检测仍然会是Unable 不过看/tmp/output就会有正确的結果，所以有正确的結果后，一定要去掉 &gt;&gt;/tmp/outpt 2&gt;&amp;1 信息都导到文件中了 nagios还是得不到任何消息。)</p> <p style="text-indent: 2em">一个脚本执行成功后，就是大批量应用，用生产环境验证，出现问题继续调试。</p> 以上为所有的分析调试方法。如果你看到最后一步了，说明你很有耐心，你也一定会成功的，至于写得好与坏、对与错请尽管说，这不会影响你的成功。呵呵。</div>转自:<div>http://blog.chinaunix.net/uid-20592013-id-2436813.html</div><img src ="http://www.cppblog.com/guojingjia2006/aggbug/202981.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guojingjia2006/" target="_blank">小果子</a> 2013-09-03 09:39 <a href="http://www.cppblog.com/guojingjia2006/archive/2013/09/03/202981.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux下Nagios的安装与配置</title><link>http://www.cppblog.com/guojingjia2006/archive/2013/09/02/202946.html</link><dc:creator>小果子</dc:creator><author>小果子</author><pubDate>Mon, 02 Sep 2013 06:26:00 GMT</pubDate><guid>http://www.cppblog.com/guojingjia2006/archive/2013/09/02/202946.html</guid><wfw:comment>http://www.cppblog.com/guojingjia2006/comments/202946.html</wfw:comment><comments>http://www.cppblog.com/guojingjia2006/archive/2013/09/02/202946.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guojingjia2006/comments/commentRss/202946.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guojingjia2006/services/trackbacks/202946.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 一、Nagios简介  　　Nagios是一款开源的电脑系统和网络监视工具，能有效监控Windows、Linux和Unix的主机状态，交换机路由器等网络设置，打印机等。在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员，在状态恢复后发出正常的邮件或短信通知。 　　Nagios原名为NetSaint，由Ethan Galstad开发并维护至今。NAGIOS是一个缩写形式: "Nagio...&nbsp;&nbsp;<a href='http://www.cppblog.com/guojingjia2006/archive/2013/09/02/202946.html'>阅读全文</a><img src ="http://www.cppblog.com/guojingjia2006/aggbug/202946.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guojingjia2006/" target="_blank">小果子</a> 2013-09-02 14:26 <a href="http://www.cppblog.com/guojingjia2006/archive/2013/09/02/202946.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>