??xml version="1.0" encoding="utf-8" standalone="yes"?>久久亚洲精品专区蓝色区,综合偷自拍亚洲乱中文字幕,亚洲日本天堂在线http://www.tkk7.com/agapple/zh-cnMon, 12 May 2025 18:14:06 GMTMon, 12 May 2025 18:14:06 GMT60cglib源码学习交流http://www.tkk7.com/agapple/archive/2010/11/01/336730.htmlagappleagappleMon, 01 Nov 2010 14:24:00 GMThttp://www.tkk7.com/agapple/archive/2010/11/01/336730.htmlhttp://www.tkk7.com/agapple/comments/336730.htmlhttp://www.tkk7.com/agapple/archive/2010/11/01/336730.html#Feedback0http://www.tkk7.com/agapple/comments/commentRss/336730.htmlhttp://www.tkk7.com/agapple/services/trackbacks/336730.html阅读全文

agapple 2010-11-01 22:24 发表评论
]]>
解读dbcp自动重连那些?/title><link>http://www.tkk7.com/agapple/archive/2010/10/23/335936.html</link><dc:creator>agapple</dc:creator><author>agapple</author><pubDate>Fri, 22 Oct 2010 17:01:00 GMT</pubDate><guid>http://www.tkk7.com/agapple/archive/2010/10/23/335936.html</guid><wfw:comment>http://www.tkk7.com/agapple/comments/335936.html</wfw:comment><comments>http://www.tkk7.com/agapple/archive/2010/10/23/335936.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/agapple/comments/commentRss/335936.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/agapple/services/trackbacks/335936.html</trackback:ping><description><![CDATA[<div> <div><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">   最q在?/span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">offerdetail</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">优化Ӟ替换了数据库驱动Q从</span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">c3p0 0.9.1 -> dbcp 1.4</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">Q?/span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">Z研究了下</span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">dbcp</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">的自动重q的一套机Ӟ也做一下分享,大家周知一下?/span></font> <p><font face="Times New Roman" color="navy" size="2"> </font></p> <div style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); padding-bottom: 0cm; border-left: medium none; padding-top: 0cm; border-bottom: 1pt solid; moz-background-inline-policy: continuous"> <p style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); margin-bottom: 7.5pt; padding-bottom: 0cm; border-left: medium none; line-height: 200%; padding-top: 0cm; border-bottom: medium none; moz-background-inline-policy: continuous"><strong><font face="宋体" color="#003366" size="4"><span style="font-weight: bold; font-size: 15pt; color: rgb(0,51,102); line-height: 200%; font-family: 宋体">数据库链接 常见的问题:</span></font></strong></p> </div> <p><font face="Times New Roman" color="navy" size="3"><span style="font-size: 12pt; color: navy">1. </span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">数据库意外重启后Q原先的数据库连接池能自动废弃老的无用的链接,建立新的数据库链?/span></font></p> <p><font face="Times New Roman" color="navy" size="3"><span style="font-size: 12pt; color: navy">2. </span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">|络异常中断后,原先的徏立的</span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">tcp</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">链接Q应该能q行自动切换。比如网站演习中的交换机重启会导致网l瞬?/span></font></p> <p><font face="Times New Roman" color="navy" size="3"><span style="font-size: 12pt; color: navy">3. </span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">分布式数据库中间Ӟ比如</span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">cobar</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">会定时的空闲链接异常关闭,客户端会出现半开的空闲链接?/span></font></p> <p><font face="Times New Roman" color="navy" size="3"> </font></p> <div style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); padding-bottom: 0cm; border-left: medium none; padding-top: 0cm; border-bottom: 1pt solid; moz-background-inline-policy: continuous"> <p style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); margin-bottom: 7.5pt; padding-bottom: 0cm; border-left: medium none; line-height: 200%; padding-top: 0cm; border-bottom: medium none; moz-background-inline-policy: continuous"><strong><font face="宋体" color="#003366" size="4"><span style="font-weight: bold; font-size: 15pt; color: rgb(0,51,102); line-height: 200%; font-family: 宋体">大致思考解x\Q?/span></font></strong></p> </div> <p style="margin-left: 18pt; text-indent: -18pt"><font face="Times New Roman" color="navy" size="3"><span style="font-size: 12pt; color: navy"><span>1.<font face="Times New Roman" size="1"><span style="font: 7pt 'Times New Roman'">      </span></font></span></span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">sql</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">心蟩?/span></font><font color="red" size="3"><span style="font-size: 12pt; color: red">(</span></font><font face="宋体" color="red" size="3"><span style="font-size: 12pt; color: red; font-family: 宋体">d?/span></font><font color="red" size="3"><span style="font-size: 12pt; color: red">)</span></font></p> <p style="margin-left: 18pt; text-indent: -18pt"><font face="Times New Roman" color="navy" size="3"><span style="font-size: 12pt; color: navy"><span>2.<font face="Times New Roman" size="1"><span style="font: 7pt 'Times New Roman'">      </span></font></span></span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">拉K接尝试一下,发现处理p|丢弃链接Q探Lh会失败几个 </span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">(</span></font><font face="宋体" color="red" size="3"><span style="font-size: 12pt; color: red; font-family: 宋体">牺牲我Q完成大我的_</span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">)</span></font></p> <p style="margin-left: 18pt; text-indent: -18pt"><font face="Times New Roman" color="navy" size="3"><span style="font-size: 12pt; color: navy"><span>3.<font face="Times New Roman" size="1"><span style="font: 7pt 'Times New Roman'">      </span></font></span></span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">讄合理的空闲链接的时旉Q避免半开链接</span></font><font color="red" size="3"><span style="font-size: 12pt; color: red">(</span></font><font face="宋体" color="red" size="3"><span style="font-size: 12pt; color: red; font-family: 宋体">懒模式,解决半开链接</span></font><font color="red" size="3"><span style="font-size: 12pt; color: red">)</span></font></p> <p><font face="Times New Roman" color="red" size="3"> </font></p> <p><font face="Times New Roman" color="red" size="3"> </font></p> <p><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">下面我们来看看,?/span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">dbcp</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">中是如何实现?/span></font></p> <p style="margin-left: 18pt; text-indent: -18pt"><font color="red" size="5"><span style="font-size: 18pt; color: red">sql</span></font><font face="宋体" color="red" size="5"><span style="font-size: 18pt; color: red; font-family: 宋体">心蟩?/span></font></p> <div style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); padding-bottom: 0cm; border-left: medium none; padding-top: 0cm; border-bottom: 1pt solid; moz-background-inline-policy: continuous"> <p style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); margin-bottom: 7.5pt; padding-bottom: 0cm; border-left: medium none; line-height: 200%; padding-top: 0cm; border-bottom: medium none; moz-background-inline-policy: continuous"><strong><font face="Arial" color="#003366" size="4"><span style="font-weight: bold; font-size: 15pt; color: rgb(0,51,102); line-height: 200%; font-family: Arial">sql validate</span></font></strong><strong><font face="宋体" color="#003366" size="4"><span style="font-weight: bold; font-size: 15pt; color: rgb(0,51,102); line-height: 200%; font-family: 宋体">配置</span></font></strong></p> </div> <p style="margin-bottom: 3.75pt; margin-left: 11.25pt; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体"><property name=</span></font><font face="宋体" color="#009100"><span style="color: rgb(0,145,0); font-family: 宋体">"testWhileIdle"</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">><value></span></font><font face="宋体" color="#000091"><span style="color: rgb(0,0,145); font-family: 宋体">true</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体"></value></property></span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 11.25pt; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体"><property name=</span></font><font face="宋体" color="#009100"><span style="color: rgb(0,145,0); font-family: 宋体">"testOnBorrow"</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">><value></span></font><font face="宋体" color="#000091"><span style="color: rgb(0,0,145); font-family: 宋体">false</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体"></value></property></span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 11.25pt; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体"><property name=</span></font><font face="宋体" color="#009100"><span style="color: rgb(0,145,0); font-family: 宋体">"testOnReturn"</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">><value></span></font><font face="宋体" color="#000091"><span style="color: rgb(0,0,145); font-family: 宋体">false</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体"></value></property></span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 11.25pt; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体"><property name=</span></font><font face="宋体" color="#009100"><span style="color: rgb(0,145,0); font-family: 宋体">"validationQuery"</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">><value>select sysdate from dual</value></property></span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 11.25pt; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体"><property name=</span></font><font face="宋体" color="#009100"><span style="color: rgb(0,145,0); font-family: 宋体">"validationQueryTimeout"</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">><value>1</value></property> </span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 11.25pt; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体"><property name=</span></font><font face="宋体" color="#009100"><span style="color: rgb(0,145,0); font-family: 宋体">"timeBetweenEvictionRunsMillis"</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">><value>30000</value></property></span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 11.25pt; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体"><property name=</span></font><font face="宋体" color="#009100"><span style="color: rgb(0,145,0); font-family: 宋体">"numTestsPerEvictionRun"</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">><value>16</value></property></span></font></p> <div style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); padding-bottom: 0cm; border-left: medium none; padding-top: 0cm; border-bottom: 1pt solid; moz-background-inline-policy: continuous"> <p style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); margin-bottom: 7.5pt; padding-bottom: 0cm; border-left: medium none; line-height: 200%; padding-top: 0cm; border-bottom: medium none; moz-background-inline-policy: continuous"><strong><font face="宋体" color="#003366" size="4"><span style="font-weight: bold; font-size: 15pt; color: rgb(0,51,102); line-height: 200%; font-family: 宋体">参数说明</span></font></strong></p> </div> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">   </span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">   </span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">dbcp</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">是采用了</span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">commons-pool</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">做ؓ其连接池理Q?/span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">testOnBorrow,testOnReturn, testWhileIdle</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">?/span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">pool</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">是提供的几种校验机制Q通过外部钩子的方式回?/span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">dbcp</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">的相x据库链接</span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">(validationQuery)</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">校验</span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">, dbcp</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">相关外部钩子c:</span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">PoolableConnectionFactory,</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">l承?/span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">common-pool PoolableObjectFactory , dbcp</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">通过</span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">GenericObjectPool</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">q一入口Q进行连接池?/span></font><font color="navy" size="3"><span style="font-size: 12pt; color: navy">borrow,return</span></font><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">处理?/span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="navy" size="3"><span style="font-size: 12pt; color: navy; font-family: 宋体">具体参数描述Q?/span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">   1. testOnBorrow : </span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">明思义Q就是在q行borrowObjectq行处理ӞҎ到的connectionq行validateObject校验</span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">   2. testOnReturn : </span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">明思义Q就是在q行returnObject对返回的connectionq行validateObject校验Q个得对数据库连接池的管理意义不?/span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">   3. testWhileIdle : </span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">x的重点,GenericObjectPool中针对pool理Qv了一?/span></font><font face="宋体" color="red"><span style="color: red; font-family: 宋体">异步Evict的TimerTask定时U程q行控制</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">(</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">可通过讄参数<span> timeBetweenEvictionRunsMillis>0),</span>定时对线E池中的链接q行validateObject校验Q对无效的链接进行关闭后Q会调用ensureMinIdleQ适当建立链接保证最的minIdleq接数?/span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">   4. timeBetweenEvictionRunsMillis,</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">讄的EvictU程的时_单位msQ大?才会开启evict查线E?/span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">   5. validateQuery</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">Q?代表查的sql</span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">   6. validateQueryTimeout</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">Q?代表在执行检查时Q通过statement讄Qstatement.setQueryTimeout(validationQueryTimeout)</span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">   7. numTestsPerEvictionRun</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">Q代表每ơ检查链接的数量Q徏议设|和maxActive一样大Q这hơ可以有效检查所有的链接.</span></font></p> <div style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); padding-bottom: 0cm; border-left: medium none; padding-top: 0cm; border-bottom: 1pt solid; moz-background-inline-policy: continuous"> <p style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); margin-bottom: 7.5pt; padding-bottom: 0cm; border-left: medium none; line-height: 200%; padding-top: 0cm; border-bottom: medium none; moz-background-inline-policy: continuous"><strong><font face="Arial" color="#003366" size="3"><span style="font-weight: bold; font-size: 12pt; color: rgb(0,51,102); line-height: 200%; font-family: Arial">Sql</span></font></strong><strong><font face="宋体" color="#003366" size="3"><span style="font-weight: bold; font-size: 12pt; color: rgb(0,51,102); line-height: 200%; font-family: 宋体">心蟩查几Ҏ考:</span></font></strong></p> </div> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">1.</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">性能问题?/span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; text-indent: 21pt; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">目前|站的应用大部分的瓶颈还是在I/Oq一块,大部分的I/Oq是在数据库的这一层面上,每一个请求可能会调用10来次SQL查询Q如果不C务,一个请求会重复获取链接Q如果每ơ获取链?比如在testOnBorrow都进行validateObjectQ性能开销不是很能接受Q可以假定一ơSQL操作消毫0.5~1ms(一般走了网l请求基本就q数) </span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">2</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">Q成本和收益</span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; text-indent: 21pt; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">|站异常数据库重启,|络异常断开的频率是非常低的Q一般也在数据库升U,演习l护时才会进行,而且一般也是选在晚上Q访问量相对比较低的hQ而且一般会有h员值班xQ所以异步的validateObject是可以接受,但一个前提需要确保能保证在一个合理的旉D内Q数据库能完成自动重联?/span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"> </font></p> <p style="margin-left: 18pt; text-indent: -18pt"><font face="宋体" color="red" size="5"><span style="font-size: 18pt; color: red; font-family: 宋体">h探雷</span></font></p> <div style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); padding-bottom: 0cm; border-left: medium none; padding-top: 0cm; border-bottom: 1pt solid; moz-background-inline-policy: continuous"> <p style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); margin-bottom: 7.5pt; padding-bottom: 0cm; border-left: medium none; line-height: 200%; padding-top: 0cm; border-bottom: medium none; moz-background-inline-policy: continuous"><strong><font face="宋体" color="#003366" size="4"><span style="font-weight: bold; font-size: 15pt; color: rgb(0,51,102); line-height: 200%; font-family: 宋体">相关配置</span></font></strong></p> </div> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">dbcp</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">自n默认支持Q不需要配|?/span></font></p> <div style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); padding-bottom: 0cm; border-left: medium none; padding-top: 0cm; border-bottom: 1pt solid; moz-background-inline-policy: continuous"> <p style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); margin-bottom: 7.5pt; padding-bottom: 0cm; border-left: medium none; line-height: 200%; padding-top: 0cm; border-bottom: medium none; moz-background-inline-policy: continuous"><strong><font face="宋体" color="#003366" size="4"><span style="font-weight: bold; font-size: 15pt; color: rgb(0,51,102); line-height: 200%; font-family: 宋体">原理描述</span></font></strong></p> </div> <p style="margin-bottom: 3.75pt; margin-left: 18pt; text-indent: -18pt; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black"><span style="color: black; font-family: 宋体">common-pools</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">通过borrowObject , returnObject完成q接的获取和释放Q正常的情况是一ơ请求中borrow和return是一对的Q有借就有还?/span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 18pt; text-indent: -18pt; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black"><span style="color: black; font-family: 宋体">但在准备returnObjectӞdbcp会做一件事Q就是看看这个object是否已经是坏了的Q如果坏了就直接丢了Q就直接l丢弃了?/span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"> </font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">代码层面Q?/span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">Q? 在dbcp中PoolingDataSource(实现DataSource接口)调用<span> PoolableConnection(dbcp connnection</span>相关的pool delegate操作)q行相应关闭Ӟ会检?/span></font><font face="宋体" color="red"><span style="color: red; font-family: 宋体">_conn.isClosed()</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">Q针对DataSource如果isClosedq回?true的则不调用returnObjectQ直接丢弃了链接?/span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">Q? _conn.isClosed()是否保险Q从jdk的api描述中:<span> A connection is closed if the method close has been called on it or if certain fatal errors have occurred. </span>里面提供两种情况Q一U就是被调用了closedҎQ另一U就是出C些异常,说的比较含糊?/span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"> </font></p> <p style="margin-left: 18pt; text-indent: -18pt"><font face="宋体" color="red" size="5"><span style="font-size: 18pt; color: red; font-family: 宋体">I闲链接?/span></font></p> <div style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); padding-bottom: 0cm; border-left: medium none; padding-top: 0cm; border-bottom: 1pt solid; moz-background-inline-policy: continuous"> <p style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); margin-bottom: 7.5pt; padding-bottom: 0cm; border-left: medium none; line-height: 200%; padding-top: 0cm; border-bottom: medium none; moz-background-inline-policy: continuous"><strong><font face="宋体" color="#003366" size="4"><span style="font-weight: bold; font-size: 15pt; color: rgb(0,51,102); line-height: 200%; font-family: 宋体">相关配置</span></font></strong></p> </div> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" size="2"><span style="font-size: 10.5pt; font-family: 宋体"><property name="<font color="#009100"><span style="color: rgb(0,145,0)">minEvictableIdleTimeMillis</span></font>"><value>18000000</value></property> </span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" size="2"><span style="font-size: 10.5pt; font-family: 宋体"><property name="<font color="#009100"><span style="color: rgb(0,145,0)">removeAbandoned"</span></font>><value>true</value></property>  </span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" size="2"><span style="font-size: 10.5pt; font-family: 宋体"><property name="<font color="#009100"><span style="color: rgb(0,145,0)">removeAbandonedTimeout</span></font>"><value>180</value></property></span></font></p> <div style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); padding-bottom: 0cm; border-left: medium none; padding-top: 0cm; border-bottom: 1pt solid; moz-background-inline-policy: continuous"> <p style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); margin-bottom: 7.5pt; padding-bottom: 0cm; border-left: medium none; line-height: 200%; padding-top: 0cm; border-bottom: medium none; moz-background-inline-policy: continuous"><strong><font face="宋体" color="#003366" size="4"><span style="font-weight: bold; font-size: 15pt; color: rgb(0,51,102); line-height: 200%; font-family: 宋体">参数说明</span></font></strong></p> </div> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">1.</span></font><font face="宋体"><span style="font-family: 宋体">minEvictableIdleTimeMillis</span></font><font face="宋体"><span style="font-family: 宋体"> dbcp默认?0分,需要开启异步线EEvictQ否则不生效。原理很单,是通过一个异步线E,每次查connnection上一ơ用的旉戻I看看是否已经过q个timeout旉讄?/span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">2. removeAbandoned , removeAbandonedTimeout</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">Q主要是用于在出现链接紧张时候,会扫描一些链接未过removeAbandonedTimeout旉q未被释放,会主动的关闭该链接?/span></font></p> <div style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); padding-bottom: 0cm; border-left: medium none; padding-top: 0cm; border-bottom: 1pt solid; moz-background-inline-policy: continuous"> <p style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); margin-bottom: 7.5pt; padding-bottom: 0cm; border-left: medium none; line-height: 200%; padding-top: 0cm; border-bottom: medium none; moz-background-inline-policy: continuous"><strong><font face="宋体" color="#003366" size="4"><span style="font-weight: bold; font-size: 15pt; color: rgb(0,51,102); line-height: 200%; font-family: 宋体">适用情况</span></font></strong></p> </div> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">1. </span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">我们使用的cobar后端会有定时关闭I闲链接的操作,默认的空闲链接timeout旉?时Q和其他<span>oracle , mysql</span>各不相同Q所以设|好q个I闲链接的timeout旉q是挺重?</span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"> </font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">2. </span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">一般会是几U情况出现需要removeAbandonedQ </span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">* </span></font><font face="宋体" color="red"><span style="color: red; font-family: 宋体">代码未在finally释放connection</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体"> ,</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体"> 不过我们都用sqlmapClientTemplateQ底层都有链接释攄q程 </span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">* </span></font><font face="宋体" color="red"><span style="color: red; font-family: 宋体">遇到数据库死?/span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">。以前遇到过后端存储q程做了锁表操作Q导致前台集中q接池全都被block住,后箋的业务处理因为拿不到链接所有都处理p|了?/span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"> </font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"> </font></p> <div style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); padding-bottom: 0cm; border-left: medium none; padding-top: 0cm; border-bottom: 1pt solid; moz-background-inline-policy: continuous"> <p style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); margin-bottom: 7.5pt; padding-bottom: 0cm; border-left: medium none; line-height: 200%; padding-top: 0cm; border-bottom: medium none; moz-background-inline-policy: continuous"><strong><font face="宋体" color="#003366" size="4"><span style="font-weight: bold; font-size: 15pt; color: rgb(0,51,102); line-height: 200%; font-family: 宋体">聊聊</span></font></strong><strong><font face="Arial" color="#003366" size="4"><span style="font-weight: bold; font-size: 15pt; color: rgb(0,51,102); line-height: 200%; font-family: Arial">c3p0</span></font></strong><strong><font face="宋体" color="#003366" size="4"><span style="font-weight: bold; font-size: 15pt; color: rgb(0,51,102); line-height: 200%; font-family: 宋体">配置</span></font></strong></p> </div> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">q有我们配置的c3p0所谓的自动重连的3个参敎ͼ</span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; text-indent: 21pt; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体"><prop key="acquireRetryAttempts">30</prop></span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">    <prop key="acquireRetryDelay">1000</prop></span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">    <prop key="breakAfterAcquireFailure">false</prop></span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"> </font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="red" size="2"><span style="font-size: 10.5pt; color: red; font-family: 宋体">个h觉得是一个误?/span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">Q这几个配置只是在从q接池获取链接时Q获取失败多试几次Q因为我们从pool从获取链接最多只会等待固定timeout旉?/span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">如果要达到自动重q的效果Q必要c3p0支持h探雷或者是sql心蟩查功能,能自动的剔除无效的链接。 </span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">可见c3p0官方文档描述Q?a >http://www.mchange.com/projects/c3p0/index.html#configuring_recovery</a></span></font></p> <p style="margin-bottom: 3.75pt; margin-left: 0cm; margin-right: 11.25pt; text-align: left" align="left"><font face="宋体" color="black" size="2"> </font></p> <div style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); padding-bottom: 0cm; border-left: medium none; padding-top: 0cm; border-bottom: 1pt solid; moz-background-inline-policy: continuous"> <p style="border-right: medium none; padding-right: 0cm; border-top: medium none; padding-left: 0cm; background: rgb(240,240,240); margin-bottom: 7.5pt; padding-bottom: 0cm; border-left: medium none; line-height: 200%; padding-top: 0cm; border-bottom: medium none; moz-background-inline-policy: continuous"><font face="宋体" color="red" size="5"><span style="font-size: 18pt; color: red; line-height: 200%; font-family: 宋体">最后:</span></font></p> </div> <p><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">Dbcp</span></font><font face="宋体" color="black"><span style="color: black; font-family: 宋体">是我们以后数据库驱动选择的趋势,最后我们如何选择如何自动重连Q这个也得根据我们的应用场景而定。比如只ȝwebpȝQ后C务系l,dpȝ可能处理方式׃同?/span></font></p> <p><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">只读WebpȝQ可采取h探雷的策略,也就p|q接池个数的hQ失败了面h一ơ就好?/span></font></p> <p><font face="宋体" color="black" size="2"><span style="font-size: 10.5pt; color: black; font-family: 宋体">后台业务pȝQ一般业务都涉及数据库的写操作,很多数据不可重入Q一ơ处理失败后只能靠手工q预处理。这时候得考虑是否需要用sql心蟩查,比如testOnBorrow或者testWhileIdle.</span></font></p> </div> </div> <img src ="http://www.tkk7.com/agapple/aggbug/335936.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/agapple/" target="_blank">agapple</a> 2010-10-23 01:01 <a href="http://www.tkk7.com/agapple/archive/2010/10/23/335936.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>事务隔离U别记http://www.tkk7.com/agapple/archive/2009/02/15/254801.htmlagappleagappleSun, 15 Feb 2009 13:47:00 GMThttp://www.tkk7.com/agapple/archive/2009/02/15/254801.htmlhttp://www.tkk7.com/agapple/comments/254801.htmlhttp://www.tkk7.com/agapple/archive/2009/02/15/254801.html#Feedback1http://www.tkk7.com/agapple/comments/commentRss/254801.htmlhttp://www.tkk7.com/agapple/services/trackbacks/254801.html阅读全文

agapple 2009-02-15 21:47 发表评论
]]>
rsync单配|小?/title><link>http://www.tkk7.com/agapple/archive/2009/01/14/251269.html</link><dc:creator>agapple</dc:creator><author>agapple</author><pubDate>Wed, 14 Jan 2009 06:12:00 GMT</pubDate><guid>http://www.tkk7.com/agapple/archive/2009/01/14/251269.html</guid><wfw:comment>http://www.tkk7.com/agapple/comments/251269.html</wfw:comment><comments>http://www.tkk7.com/agapple/archive/2009/01/14/251269.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/agapple/comments/commentRss/251269.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/agapple/services/trackbacks/251269.html</trackback:ping><description><![CDATA[<p>1. 下蝲rsync  (http://rsync.samba.org/)</p> <p>安装: <br /> ./configure <br /> make<br /> make install</p> <p>2. 开启rsync服务Q修?etc/xinetd.d/rsync<br /> disable = no # replace <yes><br /> 重启xinetd 服务<br /> service xinetd restart</p> <p><br /> 3. 配置server端,/etc/rsyncd.conf <br /> # touch rsyncd.conf<br /> # vi rsyncd.conf<br /> uid = ljh  #表示以什么用戯?注意必须保该用hҎ块的d权限<br /> gid = ljh<br /> use chroot = false<br /> max connectionts = 6<br /> read only = no<br /> pid file = /home/ljh/server/rsync/rsynnd.pid<br /> lock file = /home/ljh/server/rsync/rsyncd.lock<br /> log file = /home/ljh/server/rsync/rsyncd.log<br /> [test]<br /> comment = test<br /> path = /home/ljh/server/rsync/data/test<br /> ignore error<br /> list = true<br /> #auth users = ljh<br /> #secrets file = /home/ljh/server/rsync/passwd/rsyncd.passwd</p> <p> </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">配置参数介绍<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />comment<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />l模块指定一个描qͼ该描q连同模块名在客戯接得到模块列表时昄l客戗默认没有描q定义?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />path<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />指定该模块的供备份的目录树\径,该参数是必须指定的?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />use chroot<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />?nbsp;?use chroot"指定为trueQ那么rsync在传输文件以前首先chroot到path参数所指定的目录下。这样做的原因是实现额外的安全防护,但是~点是需要以roots权限Qƈ且不能备份指向外部的W号q接所指向的目录文件。默认情况下chrootgؓtrue?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />uid<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />该选项指定当该模块传输文g时守护进E应该具有的uidQ配合gid选项使用可以定哪些可以讉K怎么L文g权限Q默认值是"nobody"?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />gid<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />该选项指定当该模块传输文g时守护进E应该具有的gid。默认gؓ"nobody"?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />max connections<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />指定该模块的最大ƈ发连接数量以保护服务器,过限制的连接请求将被告知随后再试。默认值是0Q也是没有限制?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />list<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />该选项讑֮当客戯求可以用的模块列表Ӟ该模块是否应该被列出。如果设|该选项为falseQ可以创建隐藏的模块。默认值是true?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />read only<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />该选项讑֮是否允许客户上蝲文g。如果ؓtrue那么M上蝲h都会p|Q如果ؓfalseq且服务器目录读写权限允讔R么上载是允许的。默认gؓtrue?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />exclude<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />?nbsp;来指定多个由I格隔开的多个文件或目录(相对路径)Qƈ其d到exclude列表中。这{同于在客户端命令中使用--exclude来指定模式,一?nbsp;模块只能指定一个exclude选项。但是需要注意的一Ҏ该选项有一定的安全性问题,客户很有可能l过exclude列表Q如果希望确保特定的文g不能 被访问,那就最好结合uid/gid选项一起用?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />exclude from [file]<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />指定一个包含exclude模式的定义的文g名,服务器从该文件中dexclude列表定义?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />include<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />用来指定不排除符合要求的文g或目录。这{同于在客户端命令中使用--include来指定模式,l合include和exclude可以定义复杂的exclude/include规则?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />include from [file]<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />指定一个包含include模式的定义的文g名,服务器从该文件中dinclude列表定义?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />auth users<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />该选项指定q格或逗号分隔的用户名列表Q只有这些用h允许q接该模块。这里的用户和系l用h有Q何关pR如?auth users"被设|,那么客户端发出对该模块的q接h以后会被rsynchchallengedq行验证w䆾q里使用?nbsp;challenge/response认证协议。用L名和密码以明文方式存攑֜"secrets file"选项指定的文件中。默认情况下无需密码可以连接模?也就是匿名方??br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />secrets file<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />该选项指定一个包含定义用户名:密码对的文g。只有在"auth users"被定义时Q该文g才有作用。文件每行包含一个username:passwd寏V一般来说密码最好不要超q?个字W。没有默认的 secures file名,需要限式指定一?例如Q?etc/rsyncd.passwd)。注意:该文件的权限一定要?00Q否则客L不能连接服务器<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />strict modes<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />该选项指定是否监测密码文g的权限,如果该选项gؓtrue那么密码文g只能被rsync服务器运行n份的用户讉KQ其他Q何用户不可以讉K该文件。默认gؓtrue?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />hosts allow<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />该选项指定哪些IP的客户允许连接该模块。客h式定义可以是以下形式Q单个IP地址Q例如:192.167.0.1<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />hosts deny<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />指定不允许连接rsync服务器的机器Q可以用hosts allow的定义方式来q行定义。默认是没有hosts deny定义?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />ignore errors<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />指定rsyncd在判断是否运行传输时的删除操作时忽略server上的IO错误Q一般来说rsync在出现IO错误时将蟩q?-delete操作Q以防止因ؓ暂时的资源不x其它IO错误D的严重问题?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />lock file<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />指定支持max connections参数的锁文gQ默认值是/var/run/rsyncd.lock?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />timeout<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />通过该选项可以覆盖客户指定的IP时旉。通过该选项可以保rsync服务器不会永q等待一个崩溃的客户端。超时单位ؓU钟Q?表示没有时定义Q这也是默认倹{对于匿名rsync服务器来_一个理想的数字?00?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />dont compress<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />用来指定那些不进行压~处理再传输的文Ӟ默认值是*.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span></div> <p> </p> <p>4. 客户端配|?br /> 讉Kremote rsync列表<br /> rsync rsync://10.0.64.162/test<br /> 单的执行同步命o<br /> sync -auv --delete --password-file=/home/admin2/soft/rsync/passwd/rsyncd.passwd ~/rysnc/* ljh@10.0.64.162::test</p> <p>比较实际的例子:<br /> echo "hello" > /tmp/password.txt ;chmod 600 /tmp/password.txt<br /> cp /home/ewalletbops/fatrix/crm/* /home/ewalletbops/fatrix/putxml/search<br /> rsync -azv /home/ewalletbops/bops-daemon/bin/adxml/search/ /home/ewalletbops/fatrix/putxml/search<br /> rsync -auv --delete --password-file=/tmp/password.txt /home/ewalletbops/fatrix/putxml/search <a href="mailto:yangzhen@127.0.0.1::everest/adxml">yangzhen@127.0.0.1::everest/adxml</a><br /> rm /tmp/password.txt</p> <p><br />  </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">选项说明<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-v, --verbose 详细模式输出<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-q, --quiet _输出模式<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-c, --checksum 打开校验开养I强制Ҏ件传输进行校?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-a, --archive 归档模式Q表CZ递归方式传输文gQƈ保持所有文件属性,{于-rlptgoD<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-r, --recursive 对子目录以递归模式处理<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-R, --relative 使用相对路径信息<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-b, --backup 创徏备䆾Q也是对于目的已经存在有同L文g名时Q将老的文g重新命名为~filename。可以?-suffix选项来指定不同的备䆾文g前缀?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--backup-dir 备份文?如~filename)存放在在目录下?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-suffix=SUFFIX 定义备䆾文g前缀<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-u, --update 仅仅q行更新Q也是跌所有已l存在于DSTQƈ且文件时间晚于要备䆾的文件?不覆盖更新的文g)<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-l, --links 保留软链l?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-L, --copy-links 惛_待常规文件一样处理Y铄<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--copy-unsafe-links 仅仅拯指向SRC路径目录树以外的铄<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--safe-links 忽略指向SRC路径目录树以外的铄<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-H, --hard-links 保留链l?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-p, --perms 保持文g权限<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-o, --owner 保持文g属主信息<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-g, --group 保持文g属组信息<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-D, --devices 保持讑֤文g信息<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-t, --times 保持文g旉信息<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-S, --sparse 对稀疏文件进行特D处理以节省DST的空?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-n, --dry-run现实哪些文g被传输<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-W, --whole-file 拯文gQ不q行增量?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-x, --one-file-system 不要跨越文gpȝ边界<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-B, --block-size=SIZE 验算法用的块尺寸,默认?00字节<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-e, --rsh=COMMAND 指定替代rsh的shellE序<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--rsync-path=PATH 指定q程服务器上的rsync命o所在\径信?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-C, --cvs-exclude 使用和CVS一LҎ自动忽略文gQ用来排除那些不希望传输的文?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--existing 仅仅更新那些已经存在于DST的文Ӟ而不备䆾那些新创建的文g<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--delete 删除那些DST中SRC没有的文?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--delete-excluded 同样删除接收端那些被该选项指定排除的文?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--delete-after 传输l束以后再删?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--ignore-errors 及时出现IO错误也进行删?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--max-delete=NUM 最多删除NUM个文?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--partial 保留那些因故没有完全传输的文Ӟ以是加快随后的再ơ传?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--force 强制删除目录Q即使不为空<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--numeric-ids 不将数字的用户和lID匚w为用户名和组?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--timeout=TIME IP时旉Q单位ؓU?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-I, --ignore-times 不蟩q那些有同样的时间和长度的文?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--size-only 当决定是否要备䆾文gӞ仅仅察看文g大小而不考虑文g旉<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--modify-window=NUM 军_文g是否旉相同时用的旉戳窗口,默认?<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-T --temp-dir=DIR 在DIR中创Z时文?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--compare-dest=DIR 同样比较DIR中的文g来决定是否需要备?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-P {同?nbsp;--partial<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--progress 昄备䆾q程<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-z, --compress 对备份的文g在传输时q行压羃处理<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--exclude=PATTERN 指定排除不需要传输的文g模式<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--include=PATTERN 指定不排除而需要传输的文g模式<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--exclude-from=FILE 排除FILE中指定模式的文g<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--include-from=FILE 不排除FILE指定模式匚w的文?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--version 打印版本信息<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--address l定到特定的地址<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--config=FILE 指定其他的配|文Ӟ不用默认的rsyncd.conf文g<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--port=PORT 指定其他的rsync服务端口<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--blocking-io 对远Eshell使用dIO<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--stats l出某些文g的传输状?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--progress 在传输时现实传输q程<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--log-format=formAT 指定日志文g格式<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--password-file=FILE 从FILE中得到密?br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />--bwlimit=KBPS 限制I/O带宽QKBytes per second<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />-h, --help 昄帮助信息<br /> <img alt="" src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span></div> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <img src ="http://www.tkk7.com/agapple/aggbug/251269.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/agapple/" target="_blank">agapple</a> 2009-01-14 14:12 <a href="http://www.tkk7.com/agapple/archive/2009/01/14/251269.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>nginx使用记http://www.tkk7.com/agapple/archive/2008/11/07/239327.htmlagappleagappleFri, 07 Nov 2008 12:48:00 GMThttp://www.tkk7.com/agapple/archive/2008/11/07/239327.htmlhttp://www.tkk7.com/agapple/comments/239327.htmlhttp://www.tkk7.com/agapple/archive/2008/11/07/239327.html#Feedback0http://www.tkk7.com/agapple/comments/commentRss/239327.htmlhttp://www.tkk7.com/agapple/services/trackbacks/239327.html阅读全文

agapple 2008-11-07 20:48 发表评论
]]>
vi 命o记http://www.tkk7.com/agapple/archive/2008/11/03/238423.htmlagappleagappleMon, 03 Nov 2008 12:13:00 GMThttp://www.tkk7.com/agapple/archive/2008/11/03/238423.htmlhttp://www.tkk7.com/agapple/comments/238423.htmlhttp://www.tkk7.com/agapple/archive/2008/11/03/238423.html#Feedback0http://www.tkk7.com/agapple/comments/commentRss/238423.htmlhttp://www.tkk7.com/agapple/services/trackbacks/238423.html阅读全文

agapple 2008-11-03 20:13 发表评论
]]>
linux下javaH口Q正显CZ?http://www.tkk7.com/agapple/archive/2008/10/31/237838.htmlagappleagappleFri, 31 Oct 2008 08:31:00 GMThttp://www.tkk7.com/agapple/archive/2008/10/31/237838.htmlhttp://www.tkk7.com/agapple/comments/237838.htmlhttp://www.tkk7.com/agapple/archive/2008/10/31/237838.html#Feedback0http://www.tkk7.com/agapple/comments/commentRss/237838.htmlhttp://www.tkk7.com/agapple/services/trackbacks/237838.htmlTip1

1.?JAVA_HOME/jre/lib/fonts/ 下徏立个目录 fallback
2.?fallback 里弄个中文字体最单ln一下就好了
比如Q?/p>

ln -s /usr/share/fonts/truetype/arphic/uming.ttf  $JAVA_HOME/jre/lib/fonts/fallback/

Tip2

问题描述QJava 应用E序的中文无法显C,呈现方块状?/p>

  原因分析QJava 应用E序无法扑ֈ可供昄中文的字体?/p>

  解决ҎQ首先,保pȝ里安装了 JDK 1.5.0_06Q如果安装的?JRE 1.5.0_06Q那么卸?JREQ再安装 JDK。然后下?fireflysung 1.3.0Q?解压后将其中?ttf 文g丢到pȝ字体目录/usr/share/fontsQ再?fc-cache -f -v 跑一遍,让系l知道这个字体。最后,是转到 JDK 安装目录的jre/lib/fonts 中,使用下面的命令来完成?/p>

  mkdir fallback
  cd fallback
  ln -s /usr/share/fonts/fireflysung.ttf
  mkfontdir
  mkfontscale


agapple 2008-10-31 16:31 发表评论
]]>
(?suid和sgid介绍http://www.tkk7.com/agapple/archive/2008/10/31/237835.htmlagappleagappleFri, 31 Oct 2008 08:22:00 GMThttp://www.tkk7.com/agapple/archive/2008/10/31/237835.htmlhttp://www.tkk7.com/agapple/comments/237835.htmlhttp://www.tkk7.com/agapple/archive/2008/10/31/237835.html#Feedback0http://www.tkk7.com/agapple/comments/commentRss/237835.htmlhttp://www.tkk7.com/agapple/services/trackbacks/237835.html  一、UNIX下关于文件权限的表示Ҏ和解?/p>

  SUID ?Set User ID, SGID ?Set Group ID的意思?/p>

  UNIX下可以用ls -l 命o来看到文件的权限。用ls命o所得到的表C法的格式是cMq样的:-rwxr-xr-x 。下面解析一下格式所表示的意思。这U表C方法一共有十位Q?/p>

  9 8 7 6 5 4 3 2 1 0

  - r w x r - x r - x

  W?位表C文件类?可以为p、d、l、s、c、b?Q?/p>

  p表示命名道文g

  d表示目录文g

  l表示W号q接文g

  -表示普通文?/p>

  s表示socket文g

  c表示字符讑֤文g

  b表示块设备文?/p>

  W?-6位?-3位?-0位分别表C文件所有者的权限Q同l用L权限Q其他用L权限Q其形式为rwxQ?/p>

  r表示可读Q可以读出文件的内容

  w表示可写Q可以修Ҏ件的内容

  x表示可执行,可运行这个程?/p>

  没有权限的位|用-表示

  例子Q?/p>

  ls -l myfile昄为:

  rwxr-x-- 1 foo staff 7734 Apr 05 17:07 myfile

  表示文gmyfile是普通文Ӟ文g的所有者是foo用户Q而foo用户属于staffl,文g只有1个硬q接Q长度是7734个字节,最后修Ҏ???7:07?/p>

  所有者fooҎ件有d执行权限Qstaffl的成员Ҏ件有d执行权限Q其他的用户对这个文件没有权限?/p>

  如果一个文件被讄了SUID或SGID位,会分别表现在所有者或同组用户的权限的可执行位上。例如:

  1?rwsr-xr-x 表示SUID和所有者权限中可执行位被设|?/p>

  2?del>rwSrr- 表示SUID被设|,但所有者权限中可执行位没有被设|?/p>

  3?rwxr-sr-x 表示SGID和同l用h限中可执行位被设|?/p>

  4?del>rw-r-Sr- 表示SGID被设|,但同l用h限中可执行位没有被社

  其实在UNIX的实CQ文件权限用12个二q制位表C,如果该位|上的值是

  1Q表C有相应的权限:

  11 10 9 8 7 6 5 4 3 2 1 0

  S G T r w x r w x r w x

  W?1位ؓSUID位,W?0位ؓSGID位,W?位ؓsticky位,W?-0位对应于上面的三lrwx位?/p>

  11 10 9 8 7 6 5 4 3 2 1 0

  上面?rwsr-xr-x的gؓQ?1 0 0 1 1 1 1 0 1 1 0 1

  rw-r-Sr-的gؓQ?0 1 0 1 1 0 1 0 0 1 0 0

  l文件加SUID和SUID的命令如下:

  chmod u+s filename 讄SUID?/p>

  chmod u-s filename LSUID讄

  chmod g+s filename 讄SGID?/p>

  chmod g-s filename LSGID讄

  另外一U方法是chmod命o用八q制表示Ҏ的设|。如果明白了前面?2位权限表C法也很单?/p>

  二、SUID和SGID的详l解?/p>

  ׃SUID和SGID是在执行E序Q程序的可执行位被设|)时v作用Q而可执行位只Ҏ通文件和目录文g有意义,所以设|其他种cL件的SUID和SGID位是没有多大意义的?/p>

  首先讲普通文件的SUID和SGID的作用。例子:

  如果普通文件myfile是属于foo用户的,是可执行的,现在没设SUID位,ls命o昄如下Q?/p>

  -rwxr-xr-x 1 foo staff 7734 Apr 05 17:07 myfileM用户都可以执行这个程序。UNIX的内核是Ҏ什么来定一个进E对资源的访问权限的呢?是这个进E的q行用户的(有效QIDQ包?user id和group id。用户可以用id命o来查到自q或其他用Luser id和group id?/p>

  除了一般的user id 和group id外,q有两个UC为effective 的idQ就是有效idQ上面的四个id表示为:uidQgidQeuidQegid。内怸要是Ҏeuid和egid来确定进E对资源的访问权限?/p>

  一个进E如果没有SUID或SGID位,则euid=uid egid=gidQ分别是q行q个E序的用Luid和gid。例如kevin用户的uid和gid分别?04?02Qfoo用户的uid和gid?200Q?01Qkevinq行myfileE序形成的进E的euid=uid=204Qegid=gid=202Q内核根据这些值来判断q程对资源访?的限Ӟ其实是kevin用户对资源访问的权限Q和foo没关pR?/p>

  如果一个程序设|了SUIDQ则euid和egid变成被运行的E序的所有者的uid和gidQ例如kevin用户q行myfileQeuid=200Qegid=201Quid=204Qgid=202Q则q个q程h它的属主foo的资源访问权限?/p>

  SUID的作用就是这P让本来没有相应权限的用户q行q个E序Ӟ可以讉K他没有权限访问的资源。passwd是一个很鲜明的例子?/p>

  SUID的优先比SGID高,当一个可执行E序讄了SUIDQ则SGID会自动变成相应的egid?/p>

  下面讨论一个例子:

  UNIXpȝ有一?dev/kmem的设备文Ӟ是一个字W设备文Ӟ里面存储了核心程序要讉K的数据,包括用户的口令。所以这个文件不能给一般的用户dQ权限设为:cr-r---- 1 root system 2, 1 May 25 1998 kmem

  但ps{程序要读这个文Ӟ而ps的权限设|如下:

  -r-xr-sr-x 1 bin system 59346 Apr 05 1998 ps

  q是一个设|了SGID的程序,而ps的用hbinQ不是rootQ所以不能设|SUID来访问kmemQ但大家注意了,bin和root 都属于systeml,而且ps讄了SGIDQ一般用h行psQ就会获得systeml用L权限Q而文件kmem的同l用L权限是可读,所以一?用户执行ps没问题了。但有些Qؓ什么不把psE序讄为root用户的程序,然后讄SUID位,不也行吗Q这的确可以解决问题Q但实际中ؓ什?不这样做呢?因ؓSGID的风险比SUID得多,所以出于系l安全的考虑Q应该尽量用SGID代替SUID的程序,如果可能的话。下面来说明一?SGID对目录的影响。SUID对目录没有媄响。如果一个目录设|了SGID位,那么如果M一个用户对q个目录有写权限的话Q他在这个目录所建立的文?的组都会自动转ؓq个目录的属L在的l,而文件所有者不变,q是属于建立q个文g的用戗?/p>

  三、关于SUID和SGID的编E?/p>

  和SUID和SGID~程比较密切相关的有以下的头文g和函敎ͼ

  #include

  #include

  uid_t getuid(void);

  uid_t geteuid(void);

  gid_t getgid (void);

  gid_t getegid (void);

  int setuid (uid_t UID);

  int setruid (uid_t RUID);

  int seteuid (uid_t EUID);

  int setreuid (uid_t RUID,uid_t EUID);

  int setgid (gid_t GID);

  int setrgid (gid_t RGID);

  int setegid (git_t EGID);

  int setregid (gid_t RGID, gid_t EGID);

  具体q些函数的说明在q里׃详细列出来了,要用到的可以用man查?/p>

  SUID/SGID :

  假如你有文ga.txt

  #ls -l a.txt

  -rwxrwxrwx

  #chmod 4777 a.txt

  -rwsrwxrwx ======>注意s位置

  #chmod 2777 a.txt

  -rwxrwsrwx ======>注意s位置

  #chmod 7777 a.txt

  -rwsrwxswt ======>出现了t,t的作用在内存中尽量保存a.txt,节省pȝ再加载的旉.

  现在再看前面讄 SUID/SGID作用:

  #cd /sbin

  #./lsusb

  ...

  #su aaa(普通用?

  $./lsusb

  ...

  是不是现在显C出错?

  $su

  #chmod 4755 lsusb

  #su aaa

  $./lsusb

  ... 现在明白了吗Q本来是只有root用户才能执行的命令,加了SUID?普通用户就可以像root一L用,权限提升了。上面是对于文g来说的,对于目录也差不多Q?/p>

  目录的S属性得在该目录下创徏的Q何文件及子目录属于该目录所拥有的组Q目录的T属性得该目录的所有者及root才能删除该目录。还有对 于s与SQ设|SUID/SGID需要有q行权限Q否则用ls -l后就会看到S,证明你所讄的SUID/SGID没有起作用?/p>

  Why we need suid,how do we use suid?

  r -- 读访?/p>

  w -- 写访?/p>

  x -- 执行许可

  s -- SUID/SGID

  t -- sticky?/p>

  那么 suid/sgid是做什么的Q?Z么会有suid位呢Q?/p>

  要想明白q个Q先让我们看个问题:如果让每个用h改自q密码Q?/p>

  用户修改密码Q是通过q行命opasswd来实现的。最l必要修改/etc/passwd文gQ而passwd的文件的属性是Q?/p>

  #ls -l /etc/passwd

  rw-rr- 1 root root 2520 Jul 12 18:25 passwd

  我们可以看到passwd文g只有对于root用户是可写的Q而对于所有的他用h说都是没有写权限的?那么一个普通的用户如何能够通过q行passwd命o修改q个passwd文g呢?

  Z解决q个问题QSUID/SGID便应q而生。而且AT&T对它甌了专利?呵呵?/p>

  SUID和SGID是如何解册个问题呢Q?/p>

  首先Q我们要知道一点:q程在运行的时候,有一些属性,其中包括 实际用户ID,实际lID,有效用户ID,有效lID{?实际用户ID和实际组ID标识我们是谁Q谁在运行这个程?一般这2个字D在登陆时决定,在一个登陆会话期_ q些值基本上不改变?/p>

  而有效用户ID和有效组ID则决定了q程在运行时的权限。内核在军_q程是否有文件存取权限时Q是采用了进E的有效用户ID来进行判断的?/p>

  知道了这点,我们来看看SUID的解决途径Q?/p>

  当一个程序设|了为SUID位时Q内核就知道了运行这个程序的时候,应该认ؓ是文件的所有者在q行q个E序。即该程序运行的时候,有效用户ID是该E序的所有者。D个例子:

  [root@sgrid5 bin]# ls -l passwd

  -r-s-s-x 1 root root 16336 Feb 14 2003 passwd

  虽然你以test登陆pȝQ但是当你输入passwd命o来更改密码的时候,׃passwd讄了SUID位,因此虽然q程的实际用户ID 是test对应的IDQ但是进E的有效用户ID则是passwd文g的所有者root的ID,因此可以修改/etc/passwd文g?/p>

  让我们看另外一个例子?/p>

  ping命o应用q泛Q可以测试网l是否连接正常。ping在运行中是采用了ICMP协议Q需要发送ICMP报文。但是只有root用户才能建立ICMP报文Q如何解册个问题呢Q同P也是通过SUID位来解决?/p>

  [root@sgrid5 bin]# ls -l /bin/ping

  -rwsr-sr-x 1 root root 28628 Jan 25 2003 /bin/ping

  我们可以试一下,如果Lping的SUID位,再用普通用户去q行命oQ看会怎么栗?/p>

  [root@sgrid5 bin]#chmod u-s /bin/ping

  [root@sgrid5 bin]# ls -l ping

  -rwxr-xr-x 1 root root 28628 Jan 25 2003 ping

  [root@sgrid5 bin]#su test

  [test@sgrid5 bin]$ ping byhh.net

  ping: icmp open socket: Operation not permitted

  SUID虽然很好了解决了一些问题,但是同时也会带来一些安全隐患?/p>

  因ؓ讄?SUID 位的E序如果被攻?通过~冲区溢出等斚w),那么hacker可以拿到root权限?/p>

  因此在安全方面特别要注意那些讄了SUID的程序?/p>

  通过以下的命令可以找到系l上所有的讄了suid的文Ӟ

  [root@sgrid5 /]# find / -perm -04000 -type f -ls

  对于q里Z么是4000Q大家可以看一下前面的st_mode的各bit的意义就明白了?/p>

  在这些设|了suid的程序里Q如果用不上的,最好取消该E序的suid位?/p>
ȝQ?/span>
1QSet UIDQ当文gpȝ?所有者权限组?的可执行位被s(即rws------)取代Ӟ构成Ҏ权限规定Set UIDQ简USUID。仅对系l中的二q制可执行文件设|有效,而且不可对Shell Script施加讄?br /> 2QSet GIDQ当所有者所在的用户l?group)的权限组合中可执行位被s所取代?例如--rws--)Q便构成Set GID的权限设|。SGID可以针对二进制文件或目录q行讄?br /> 3QSticky BitQ当文gpȝ"其他(others)"的权限组合中可执行位被t所取代?例如------rwt)Q便构成Sticky Bit的权限设|。它只对目录有效?

SUID和SGIDQ主要作用是用于当非某个文g的所有?或组)执行(或操作目?文gӞ可以暂时获得该文件所有者的权限?br /> SBIT的作用在于访问控Ӟ当它Ҏ个目录设|此属性后Q该目录下的所有文Ӟ即其它人有w属性,都不得对其更名、移动、删除?/p>

讄ҎQ?br /> 如果你已l掌握了?八进?数字来表C权限的规则Q再l合chmod命oq行讄很单了。以下是SUID/SGID/Sticky BitU定对应的八q制数|
SUID Q?4
SGID Q?2
SBIT Q?1
讄时我们把表示Ҏ权限的数字放在其他三位数字权限的前面?/p>

agapple 2008-10-31 16:22 发表评论
]]>
jar包的service Provider机制http://www.tkk7.com/agapple/archive/2008/10/31/237770.htmlagappleagappleFri, 31 Oct 2008 03:32:00 GMThttp://www.tkk7.com/agapple/archive/2008/10/31/237770.htmlhttp://www.tkk7.com/agapple/comments/237770.htmlhttp://www.tkk7.com/agapple/archive/2008/10/31/237770.html#Feedback0http://www.tkk7.com/agapple/comments/commentRss/237770.htmlhttp://www.tkk7.com/agapple/services/trackbacks/237770.html官方描述Qhttp://java.sun.com/j2se/1.3/docs/guide/jar/jar.html

The META-INF directory

The following files/directories in the META-INF directory are recognized and interpreted by the Java 2 Platform to configure applications, extensions, class loaders and services:
  • MANIFEST.MF
The manifest file that is used to define extension and package related data.
  • INDEX.LIST
This file is generated by the new "-i" option of the jar tool, which contains location information for packages defined in an application or extension.  It is part of the JarIndex implementation and used by class loaders to speed up their class loading process.
  • x.SF
The signature file for the JAR file.  'x' stands for the base file name.
  • x.DSA
The signature block file associated with the signature file with the same base file name. This file stores the digital signature of the corresponding signature file.
  • services/
This directory stores all the service provider configuration files.

q里指出了jar包的典型的目录结构。简单翻?

META-INF目录中的下列文g和目录获得Java 2q_的认可与解释Q用来配|应用程序、扩展程序、类加蝲器和服务Q?br /> • MANIFEST.MFQ清单文Ӟ用来定义与扩展和数据包相关的数据?
• INDEX.LISTQ这个文件由JAR工具的新“-i”选项生成Q其中包含在一个应用程序或扩展中定义的数据包的地址信息。它是JarIndex的一部分Q被cd载器用来加速类加蝲q程?
• x.SFQJAR文g的签名文件。x代表基础文g名?
• x.DSAQ这个签名块文g与同名基{֐文g有关。此文g存储对应{֐文g的数字签名?
• services/Q这个目录存储所有服务提供程序配|文件?

Service Provider

Overview

Files in the META-INF/services directory are service provider configuration files. A service is a well-known set of interfaces and (usually abstract) classes. A service provider is a specific implementation of a service. The classes in a provider typically implement the interfaces and subclass the classes defined in the service itself. Service providers may be installed in an implementation of the Java platform in the form of extensions, that is, jar files placed into any of the usual extension directories. Providers may also be made available by adding them to the applet or application class path or by some other platform-specific means.

A service is represented by an abstract class. A provider of a given service contains one or more concrete classes that extend this service class with data and code specific to the provider. This provider class will typically not be the entire provider itself but rather a proxy that contains enough information to decide whether the provider is able to satisfy a particular request together with code that can create the actual provider on demand. The details of provider classes tend to be highly service-specific; no single class or interface could possibly unify them, so no such class has been defined. The only requirement enforced here is that provider classes must have a zero-argument constructor so that they may be instantiated during lookup.
 

Provider-Configuration File

A service provider identifies itself by placing a provider-configuration file in the resource directory META-INF/services. The file's name should consist of the fully-qualified name of the abstract service class. The file should contain a newline-separated list of unique concrete provider-class names. Space and tab characters, as well as blank lines, are ignored. The comment character is '#' (0x23); on each line all characters following the first comment character are ignored. The file must be encoded in UTF-8.
 

Example

Suppose we have a service class named java.io.spi.CharCodec. It has two abstract methods:

    public abstract CharEncoder getEncoder(String encodingName);
  public abstract CharDecoder getDecoder(String encodingName);

Each method returns an appropriate object or null if it cannot translate the given encoding. Typical CharCodec providers will support more than one encoding.

If sun.io.StandardCodec is a provider of the CharCodec service then its jar file would contain the file META-INF/services/java.io.spi.CharCodec. This file would contain the single line:

   sun.io.StandardCodec    # Standard codecs for the platform

To locate an encoder for a given encoding name, the internal I/O code would do something like this:

   CharEncoder getEncoder(String encodingName) {
       Iterator ps = Service.providers(CharCodec.class);
       while (ps.hasNext()) {
           CharCodec cc = (CharCodec)ps.next();
           CharEncoder ce = cc.getEncoder(encodingName);
           if (ce != null)
               return ce;
       }
       return null;
   }
 

The provider-lookup mechanism always executes in the security context of the caller. Trusted system code should typically invoke the methods in this class from within a privileged security context.


介绍Q?/p>

在META-INF/services目录下保存的是service provider的配|文件?服务在应用中会是一个接?更多的是抽象c??br /> 一个类服务器提供者实C一个服务类。这cȝ服务提供cd以以扩展的Ş式发布到q_上。所以,jar文g引入了扩展目录,同样你也可以服务提供者加入classpath提供讉K?/p>

服务都是表现Z个积累,而一个服务提供者通常是集成或实现了服务定义类。服务提供类通常不会像代理类一样ؓ了正常提供服务而包含了h者的许多信息。服务提供类一般們֐于高集成?br /> 对这cL务提供类的唯一强制性要求就是必L一个无参的构造函数?/p>

provider 配置文g
META-INF/services目录作ؓprovider配置文g的存放\径。provider配置文g中必L全类?包含package)。配|文件可以存在space tab 换行{字W?#作ؓ注释?br /> 注意Qprovider配置文g必须是以UTF-8~码?/p>

 


ȝQ?br />       service provider机制为程序的动态扩展提供了契机Q在应用中你可以针对接口~程Q通过RTTI技术可以比较完的解决E序之间的耦合性。相比于spring DIP机制Q这也是一个不错的试Q至它不需要耦合spring包?

agapple 2008-10-31 11:32 发表评论
]]>
fstab文g解释 记http://www.tkk7.com/agapple/archive/2008/10/30/237552.htmlagappleagappleThu, 30 Oct 2008 03:23:00 GMThttp://www.tkk7.com/agapple/archive/2008/10/30/237552.htmlhttp://www.tkk7.com/agapple/comments/237552.htmlhttp://www.tkk7.com/agapple/archive/2008/10/30/237552.html#Feedback0http://www.tkk7.com/agapple/comments/commentRss/237552.htmlhttp://www.tkk7.com/agapple/services/trackbacks/237552.htmlTitleLABEL=/                 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
none                    /dev/pts                devpts  gid=5,mode=620  0 0
LABEL=/home             /home                   ext3    defaults        1 2
none                    /proc                   proc    defaults        0 0
none                    /dev/shm                tmpfs   defaults        0 0
LABEL=/tmp              /tmp                    ext3    defaults        1 2
LABEL=/usr              /usr                    ext3    defaults        1 2
LABEL=/var              /var                    ext3    defaults        1 2
/dev/sda6               swap                    swap    defaults        0 0
/dev/cdrom              /mnt/cdrom              udf,iso9660 noauto,owner,kudzu,ro 0 0
/dev/fd0                /mnt/floppy             auto    noauto,owner,kudzu 0 0
fstab中存放了与分区有关的重要信息Q其中每一行ؓ一个分录,每一行又可分为六个部份:
1. W一Ҏ您想要mount的储存装|的实体位置Q如/dev/sda6分区 (分区或卷标名)
2. W二就是您惌其加入臛_个目录位|,?home?, (挂蝲?nbsp;)
3. W三就是所谓的local filesystemQ其包含了以下格式:如ext、ext2、msdos、iso9660、nfs、swap{,或如ext2  (文gpȝ)
4. W四就是您mountӞ所要设定的状态,如roQ只读)或defaultsQ包括了其它参数如rw、suid、exec、auto、nouser、asyncQ,可以参见「mount nfs」?Q读写状态)
5. W五Ҏ提供DUMP功能Q在pȝDUMP时是否需要BACKUP的标志位Q其内定值是0?span style="color: red">  Q?font face="Times New Roman">0Z备䆾Q?font face="Times New Roman">1备䆾Q一般根分区要备份)               
6. W六Ҏ讑֮是否要在开机时做check的动作,除了其必要的check?之外Q其它皆可视需要设定,内定值是0?(0Z自检Q?font face="Times New Roman">1或?font face="Times New Roman">2自检Q如果是根分设ؓ1Q其他分区只能是2)


agapple 2008-10-30 11:23 发表评论
]]>
վ֩ģ壺 ĻƷ| þþƷһ | ŷһ| þþѸӰԺ| þþžžþƷֱ| þþƷһ| ߹ۿվ| aëƬƵѿ| ޾Ʒ1ҳ| ֻùۿ| þóѵӰ| ޾Ʒavɫ| պƷAƬ| ¼Ƶѿ| Ůվѹۿ| ɫʮʮɫ| ҹƵվ| ĻmvѸ | ޾Ʒһ23Ŀ| ˳һ| ѹۿƵ㶮| ˾Ʒѿ| ޳߲va| ޾߹ۿ| ͵͵ͼƬ| Ƶ69½| 99þùĻ| ҹѹѵ| ޾Ʒ˳߲ӰԺ| Ʒۺߵһ| һ| ˳߹ۿ69ʽСƵ| ѻɫƵ| պһƷ侫| ޾ƷպĻþþ| ޹һ߹ۿ| ޾Ʒһ| Ƶۿ| þþƷƵѿ| ߹ۿʮ| ѹۿĻƷ|