﻿<?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>BlogJava-The NoteBook of EricKong-随笔分类-Linux</title><link>http://www.blogjava.net/jjshcc/category/53116.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 29 Jul 2015 10:53:29 GMT</lastBuildDate><pubDate>Wed, 29 Jul 2015 10:53:29 GMT</pubDate><ttl>60</ttl><item><title>Linux iostat监测IO状态</title><link>http://www.blogjava.net/jjshcc/archive/2015/07/29/426481.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Wed, 29 Jul 2015 02:54:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/07/29/426481.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/426481.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/07/29/426481.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/426481.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/426481.html</trackback:ping><description><![CDATA[<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">Linux系统出现了性能问题，一般我们可以通过top、iostat、free、vmstat等命令来查看初步定位问题。其中iostat可以给我们提供丰富的IO状态数据。</p>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="red">1. 基本使用</font></p><pre style="padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><div style="border-left: rgb(22,100,217) 6px solid; padding-bottom: 10px; background-color: rgb(34,34,34); margin: 0px 0px 12px; padding-left: 10px; width: 724px; padding-right: 10px; display: block; font: 1em Fixedsys, 'Courier New', Courier, monospace; color: rgb(0,204,0); overflow: scroll; padding-top: 10px" class="mycode">$iostat -d -k 1 10</div></pre>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">参数 -d 表示，显示设备（磁盘）使用状态；-k某些使用block为单位的列强制使用Kilobytes为单位；1 10表示，数据显示每隔1秒刷新一次，共显示10次。<span style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" id="more-1228"></span></p><pre style="padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><div style="border-left: rgb(22,100,217) 6px solid; padding-bottom: 10px; background-color: rgb(34,34,34); margin: 0px 0px 12px; padding-left: 10px; width: 724px; padding-right: 10px; display: block; font: 1em Fixedsys, 'Courier New', Courier, monospace; color: rgb(0,204,0); overflow: scroll; padding-top: 10px" class="mycode">$iostat -d -k 1 10
Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda              39.29        21.14         1.44  441339807   29990031
sda1              0.00         0.00         0.00       1623        523
sda2              1.32         1.43         4.54   29834273   94827104
sda3              6.30         0.85        24.95   17816289  520725244
sda5              0.85         0.46         3.40    9543503   70970116
sda6              0.00         0.00         0.00        550        236
sda7              0.00         0.00         0.00        406          0
sda8              0.00         0.00         0.00        406          0
sda9              0.00         0.00         0.00        406          0
sda10            60.68        18.35        71.43  383002263 1490928140

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda             327.55      5159.18       102.04       5056        100
sda1              0.00         0.00         0.00          0          0
</div></pre>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="blue">tps</font>：该设备每秒的传输次数（Indicate the number of transfers per second that were issued to the device.）。&#8220;一次传输&#8221;意思是&#8220;一次I/O请求&#8221;。多个逻辑请求可能会被合并为&#8220;一次I/O请求&#8221;。&#8220;一次传输&#8221;请求的大小是未知的。</p>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="blue">kB_read/s</font>：每秒从设备（drive expressed）读取的数据量；<font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="blue">kB_wrtn/s</font>：每秒向设备（drive expressed）写入的数据量；<font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="blue">kB_read</font>：读取的总数据量；<font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="blue">kB_wrtn</font>：写入的总数量数据量；这些单位都为Kilobytes。</p>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">上面的例子中，我们可以看到磁盘sda以及它的各个分区的统计数据，当时统计的磁盘总TPS是39.29，下面是各个分区的TPS。（因为是瞬间值，所以总TPS并不严格等于各个分区TPS的总和）</p>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="red">2. -x 参数</font></p>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">使用-x参数我们可以获得更多统计信息。</p><pre style="padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><div style="border-left: rgb(22,100,217) 6px solid; padding-bottom: 10px; background-color: rgb(34,34,34); margin: 0px 0px 12px; padding-left: 10px; width: 724px; padding-right: 10px; display: block; font: 1em Fixedsys, 'Courier New', Courier, monospace; color: rgb(0,204,0); overflow: scroll; padding-top: 10px" class="mycode">iostat -d -x -k 1 10
Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
sda          1.56  28.31  7.80 31.49   42.51    2.92    21.26     1.46     1.16     0.03    0.79   2.62  10.28
Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
sda          2.00  20.00 381.00  7.00 12320.00  216.00  6160.00   108.00    32.31     1.75    4.50   2.17  84.20
</div></pre>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="blue">rrqm/s</font>：每秒这个设备相关的读取请求有多少被Merge了（当系统调用需要读取数据的时候，VFS将请求发到各个FS，如果FS发现不同的读取请求读取的是相同Block的数据，FS会将这个请求合并Merge）；wrqm/s：每秒这个设备相关的写入请求有多少被Merge了。</p>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="blue">rsec/s</font>：每秒读取的扇区数；<font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="blue">wsec/</font>：每秒写入的扇区数。<font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="blue">r/s</font>：The number of read requests that were issued to the device per second；<font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="blue">w/s</font>：The number of write requests that were issued to the device per second；</p>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="blue">await</font>：每一个IO请求的处理的平均时间（单位是<del style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" datetime="2011-03-01T08:00:29+00:00">微秒</del>毫秒）。这里可以理解为IO的响应时间，一般地系统IO响应时间应该低于5ms，如果大于10ms就比较大了。</p>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="blue">%util</font>：在统计时间内所有处理IO时间，除以总共统计时间。例如，如果统计间隔1秒，该设备有0.8秒在处理IO，而0.2秒闲置，那么该设备的%util = 0.8/1 = 80%，所以该参数暗示了设备的繁忙程度。一般地，如果该参数是100%表示设备已经接近满负荷运行了（当然如果是多磁盘，即使%util是100%，因为磁盘的并发能力，所以磁盘使用未必就到了瓶颈）。</p>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="red">3. -c 参数</font></p>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">iostat还可以用来获取cpu部分状态值：</p><pre style="padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><div style="border-left: rgb(22,100,217) 6px solid; padding-bottom: 10px; background-color: rgb(34,34,34); margin: 0px 0px 12px; padding-left: 10px; width: 724px; padding-right: 10px; display: block; font: 1em Fixedsys, 'Courier New', Courier, monospace; color: rgb(0,204,0); overflow: scroll; padding-top: 10px" class="mycode"><strong style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px">iostat -c 1 10</strong>
avg-cpu:  %user   %nice    %sys %iowait   %idle
           1.98    0.00    0.35   11.45   86.22
avg-cpu:  %user   %nice    %sys %iowait   %idle
           1.62    0.00    0.25   34.46   63.67</div></pre>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="red">4. 常见用法</font></p><pre style="padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><div style="border-left: rgb(22,100,217) 6px solid; padding-bottom: 10px; background-color: rgb(34,34,34); margin: 0px 0px 12px; padding-left: 10px; width: 724px; padding-right: 10px; display: block; font: 1em Fixedsys, 'Courier New', Courier, monospace; color: rgb(0,204,0); overflow: scroll; padding-top: 10px" class="mycode">$iostat -d -k 1 10        #查看TPS和吞吐量信息
iostat -d -x -k 1 10      #查看设备使用率（%util）、响应时间（await）
iostat -c 1 10            #查看cpu状态
</div></pre>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><font style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px" color="red">5. 实例分析</font></p><pre style="padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><div style="border-left: rgb(22,100,217) 6px solid; padding-bottom: 10px; background-color: rgb(34,34,34); margin: 0px 0px 12px; padding-left: 10px; width: 724px; padding-right: 10px; display: block; font: 1em Fixedsys, 'Courier New', Courier, monospace; color: rgb(0,204,0); overflow: scroll; padding-top: 10px" class="mycode">$$iostat -d -k 1 |grep sda10
Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn   
sda10            60.72        18.95        71.53  395637647 1493241908
sda10           299.02      4266.67       129.41       4352        132
sda10           483.84      4589.90      4117.17       4544       4076
sda10           218.00      3360.00       100.00       3360        100
sda10           546.00      8784.00       124.00       8784        124
sda10           827.00     13232.00       136.00      13232        136</div></pre>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">上面看到，磁盘每秒传输次数平均约400；每秒磁盘读取约5MB，写入约1MB。</p><pre style="padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><div style="border-left: rgb(22,100,217) 6px solid; padding-bottom: 10px; background-color: rgb(34,34,34); margin: 0px 0px 12px; padding-left: 10px; width: 724px; padding-right: 10px; display: block; font: 1em Fixedsys, 'Courier New', Courier, monospace; color: rgb(0,204,0); overflow: scroll; padding-top: 10px" class="mycode">iostat -d -x -k 1
Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
sda          1.56  28.31  7.84 31.50   43.65    3.16    21.82     1.58     1.19     0.03    0.80   2.61  10.29
sda          1.98  24.75 419.80  6.93 13465.35  253.47  6732.67   126.73    32.15     2.00    4.70   2.00  85.25
sda          3.06  41.84 444.90 54.08 14204.08 2048.98  7102.04  1024.49    32.57     2.10    4.21   1.85  92.24</div></pre>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">可以看到磁盘的平均响应时间&lt;5ms，磁盘使用率&gt;80。磁盘响应正常，但是已经很繁忙了。</p>
<p style="text-align: justify; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 28px; margin: 0px 0px 12px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">参考文献：</p>
<ol style="padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px 0px 0px 55px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px Arial, Helvetica, sans-serif; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><li style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px">Linux man iostat</li><li style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px"><a style="padding-bottom: 0px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; color: rgb(0,84,179); text-decoration: underline; padding-top: 0px" href="http://www.xaprb.com/blog/2010/01/09/how-linux-iostat-computes-its-results/">How Linux iostat computes its results</a></li><li style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; padding-top: 0px"><a style="padding-bottom: 0px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; color: rgb(0,84,179); text-decoration: underline; padding-top: 0px" href="http://www.mjmwired.net/kernel/Documentation/iostats.txt">Linux iostat</a></li></ol><img src ="http://www.blogjava.net/jjshcc/aggbug/426481.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-07-29 10:54 <a href="http://www.blogjava.net/jjshcc/archive/2015/07/29/426481.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Nginx/LVS/HAProxy负载均衡软件的优缺点详解</title><link>http://www.blogjava.net/jjshcc/archive/2015/07/27/426446.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Mon, 27 Jul 2015 07:37:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/07/27/426446.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/426446.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/07/27/426446.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/426446.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/426446.html</trackback:ping><description><![CDATA[<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><strong style="text-align: center; font-weight: bold"></p>
<div style="border-bottom-style: none; border-left: rgb(216,217,217) 1px solid; padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); margin-top: 10px; text-indent: 0px; padding-left: 18px; width: 597px; letter-spacing: normal; padding-right: 18px; font: 12px/18px 宋体; white-space: normal; color: rgb(51,51,51); border-top: rgb(216,217,217) 1px solid; border-right: rgb(216,217,217) 1px solid; word-spacing: 0px; padding-top: 12px; -webkit-text-stroke-width: 0px" class="brief bgF8F8F8">
<div style="border-bottom: rgb(115,160,207) 1px dashed; border-left: rgb(115,160,207) 1px dashed; padding-bottom: 8px; line-height: 26px; background-color: rgb(255,255,255); padding-left: 12px; padding-right: 12px; border-top: rgb(115,160,207) 1px dashed; border-right: rgb(115,160,207) 1px dashed; padding-top: 8px" class="brieftext">
<p style="padding-bottom: 0px; background-color: transparent; margin: 0px; padding-left: 0px; padding-right: 0px; color: rgb(0,102,0); font-size: 14px; padding-top: 0px" class="f14 green">一般对负载均衡的使用是随着网站规模的提升根据不同的阶段来使用不同的技术。具体的应用需求还得具体分析，如果是中小型的Web应用，比如日PV小于1000万，用Nginx就完全可以了；如果机器不少，可以用DNS轮询，LVS所耗费的机器还是比较多的；大型网站或重要的服务，且服务器比较多时，可以考虑用LVS。</p>
<p style="text-align: right; padding-bottom: 0px; background-color: transparent; margin: 0px; padding-left: 0px; padding-right: 0px; color: rgb(51,51,51); padding-top: 0px" class="ad">AD：</p></div></div>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"></p>
<div style="border-bottom: rgb(216,217,217) 1px solid; position: relative; border-left: rgb(216,217,217) 1px solid; padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 0px; min-height: 500px; padding-left: 18px; letter-spacing: normal; padding-right: 18px; font: 14px/28px 宋体; white-space: normal; border-top-style: none; margin-bottom: 10px; color: rgb(51,51,51); overflow: hidden; border-right: rgb(216,217,217) 1px solid; word-spacing: 0px; padding-top: 12px; -webkit-text-stroke-width: 0px" class="content bgF8F8F8 f14"><a style="color: rgb(0,66,118); text-decoration: underline" href="http://s9.51cto.com/wyfs02/M02/44/FB/wKioL1PjTDKSygdPAACXQcBszHI903.png" target="_blank">
<div align="center"><img style="border-bottom: 0px; text-align: center; border-left: 0px; width: 482px; height: 216px; border-top: 0px; border-right: 0px" onload="javascript:if(this.width>498)this.width=498;" class=fit-image onmousewheel="javascript:return big(this)" border=0 alt="" src="http://s9.51cto.com/wyfs02/M02/44/FB/wKioL1PjTDKSygdPAACXQcBszHI903.png" width=752 height=302></div></a>
<div id="content">
<p style="padding-bottom: 0px; background-color: transparent; text-indent: 28px; margin: 10px 0px; padding-left: 0px; padding-right: 0px; color: rgb(51,51,51); padding-top: 0px"></p>
<p style="text-align: center; padding-bottom: 0px; background-color: transparent; text-indent: 28px; margin: 10px 0px; padding-left: 0px; padding-right: 0px; color: rgb(51,51,51); padding-top: 0px"><a style="color: rgb(0,66,118); text-decoration: underline" href="http://s9.51cto.com/wyfs02/M02/44/FB/wKioL1PjTDKSygdPAACXQcBszHI903.png" target="_blank"></a></p></div></div>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><br />PS：<a style="color: rgb(0,66,118); text-decoration: underline" title="Nginx" href="http://www.ha97.com/category/web-server/nginx">Nginx</a>/LVS/<a style="color: rgb(0,66,118); text-decoration: underline" title="HAProxy" href="http://www.ha97.com/tag/haproxy">HAProxy</a>是目前使用最广泛的三种负载均衡软件，本人都在多个项目中实施过，参考了一些资料，结合自己的一些使用经验，总结一下。</strong></p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">一般对负载均衡的使用是随着网站规模的提升根据不同的阶段来使用不同的技术。具体的应用需求还得具体分析，如果是中小型的Web应用，比如日PV小于1000万，用Nginx就完全可以了；如果机器不少，可以用DNS轮询，LVS所耗费的机器还是比较多的；大型网站或重要的服务，且服务器比较多时，可以考虑用LVS。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">一种是通过硬件来进行进行，常见的硬件有比较昂贵的F5和Array等商用的负载均衡器，它的优点就是有专业的维护团队来对这些服务进行维护、缺点就是花销太大，所以对于规模较小的网络服务来说暂时还没有需要使用；另外一种就是类似于Nginx/LVS/HAProxy的基于<a style="color: rgb(0,66,118); text-decoration: underline" title="Linux" href="http://www.ha97.com/category/linux">Linux</a>的开源免费的负载均衡软件，这些都是通过软件级别来实现，所以费用非常低廉。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">目前关于网站架构一般比较合理流行的架构方案：Web前端采用Nginx/HAProxy+<span style="color: rgb(255,0,0)"><a style="color: rgb(0,66,118); text-decoration: underline" title="Keepalived" href="http://www.ha97.com/tag/keepalived">Keepalived</a></span>作负载均衡器；后端采用<span style="color: rgb(255,0,0)"><a style="color: rgb(0,66,118); text-decoration: underline" title="MySQL" href="http://www.ha97.com/category/database/mysql-database">MySQL</a></span>数据库一主多从和读写分离，采用LVS+Keepalived的架构。当然要根据项目具体需求制定方案。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">下面说说各自的特点和适用场合。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><strong style="text-align: center; font-weight: bold">Nginx的优点是：</strong></p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">1、工作在网络的7层之上，可以针对http应用做一些分流的策略，比如针对域名、目录结构，它的正则规则比HAProxy更为强大和灵活，这也是它目前广泛流行的主要原因之一，Nginx单凭这点可利用的场合就远多于LVS了。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">2、Nginx对网络稳定性的依赖非常小，理论上能ping通就就能进行负载功能，这个也是它的优势之一；相反LVS对网络稳定性依赖比较大，这点本人深有体会；</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">3、Nginx安装和配置比较简单，测试起来比较方便，它基本能把错误用日志打印出来。LVS的配置、测试就要花比较长的时间了，LVS对网络依赖比较大。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">3、可以承担高负载压力且稳定，在硬件不差的情况下一般能支撑几万次的并发量，负载度比LVS相对小些。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">4、Nginx可以通过端口检测到服务器内部的故障，比如根据服务器处理网页返回的状态码、超时等等，并且会把返回错误的请求重新提交到另一个节点，不过其中缺点就是不支持url来检测。比如用户正在上传一个文件，而处理该上传的节点刚好在上传过程中出现故障，Nginx会把上传切到另一台服务器重新处理，而LVS就直接断掉了，如果是上传一个很大的文件或者很重要的文件的话，用户可能会因此而不满。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">5、Nginx不仅仅是一款优秀的负载均衡器/反向代理软件，它同时也是功能强大的Web应用服务器。LNMP也是近几年非常流行的web架构，在高流量的环境中稳定性也很好。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">6、Nginx现在作为Web反向加速缓存越来越成熟了，速度比传统的Squid服务器更快，可以考虑用其作为反向代理加速器。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">7、Nginx可作为中层反向代理使用，这一层面Nginx基本上无对手，唯一可以对比Nginx的就只有<a style="color: rgb(0,66,118); text-decoration: underline" title="lighttpd" href="http://www.ha97.com/category/web-server/lighttpd">lighttpd</a>了，不过<a style="color: rgb(0,66,118); text-decoration: underline" title="lighttpd" href="http://www.ha97.com/tag/lighttpd">lighttpd</a>目前还没有做到Nginx完全的功能，配置也不那么清晰易读，社区资料也远远没Nginx活跃。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">8、Nginx也可作为静态网页和图片服务器，这方面的性能也无对手。还有Nginx社区非常活跃，第三方模块也很多。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><strong style="text-align: center; font-weight: bold">Nginx的缺点是：</strong></p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">1、Nginx仅能支持http、https和Email协议，这样就在适用范围上面小些，这个是它的缺点。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">2、对后端服务器的健康检查，只支持通过端口来检测，不支持通过url来检测。不支持Session的直接保持，但能通过ip_hash来解决。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><strong style="text-align: center; font-weight: bold">LVS</strong>：使用Linux内核集群实现一个高性能、高可用的负载均衡服务器，它具有很好的可伸缩性（Scalability)、可靠性（Reliability)和可管理性（Manageability)。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><strong style="text-align: center; font-weight: bold">LVS的优点是：</strong></p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">1、抗负载能力强、是工作在网络4层之上仅作分发之用，没有流量的产生，这个特点也决定了它在负载均衡软件里的性能最强的，对内存和cpu资源消耗比较低。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">2、配置性比较低，这是一个缺点也是一个优点，因为没有可太多配置的东西，所以并不需要太多接触，大大减少了人为出错的几率。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">3、工作稳定，因为其本身抗负载能力很强，自身有完整的双机热备方案，如LVS+Keepalived，不过我们在项目实施中用得最多的还是LVS/DR+Keepalived。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">4、无流量，LVS只分发请求，而流量并不从它本身出去，这点保证了均衡器IO的性能不会收到大流量的影响。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">5、应用范围比较广，因为LVS工作在4层，所以它几乎可以对所有应用做负载均衡，包括http、数据库、在线聊天室等等。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><strong style="text-align: center; font-weight: bold">LVS的缺点是：</strong></p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">1、软件本身不支持正则表达式处理，不能做动静分离；而现在许多网站在这方面都有较强的需求，这个是Nginx/HAProxy+Keepalived的优势所在。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">2、如果是网站应用比较庞大的话，LVS/DR+Keepalived实施起来就比较复杂了，特别后面有<a style="color: rgb(0,66,118); text-decoration: underline" title="Windows" href="http://www.ha97.com/category/microsoft/windows">Windows</a><span class="Apple-converted-space">&nbsp;</span>Server的机器的话，如果实施及配置还有维护过程就比较复杂了，相对而言，Nginx/HAProxy+Keepalived就简单多了。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><strong style="text-align: center; font-weight: bold">HAProxy的特点是：</strong></p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">1、HAProxy也是支持虚拟主机的。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">2、HAProxy的优点能够补充Nginx的一些缺点，比如支持Session的保持，Cookie的引导；同时支持通过获取指定的url来检测后端服务器的状态。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">3、HAProxy跟LVS类似，本身就只是一款负载均衡软件；单纯从效率上来讲HAProxy会比Nginx有更出色的负载均衡速度，在并发处理上也是优于Nginx的。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">4、HAProxy支持TCP协议的负载均衡转发，可以对MySQL读进行负载均衡，对后端的MySQL节点进行检测和负载均衡，大家可以用LVS+Keepalived对MySQL主从做负载均衡。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">5、HAProxy负载均衡策略非常多，HAProxy的负载均衡算法现在具体有如下8种：</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&#9312; roundrobin，表示简单的轮询，这个不多说，这个是负载均衡基本都具备的；</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&#9313; static-rr，表示根据权重，建议关注；</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&#9314; leastconn，表示最少连接者先处理，建议关注；</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&#9315; source，表示根据请求源IP，这个跟Nginx的IP_hash机制类似，我们用其作为解决session问题的一种方法，建议关注；</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&#9316; ri，表示根据请求的URI；</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&#9317; rl_param，表示根据请求的URl参数&#8217;balance url_param&#8217; requires an URL parameter name；</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&#9318; hdr(name)，表示根据HTTP请求头来锁定每一次HTTP请求；</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&#9319; rdp-cookie(name)，表示根据据cookie(name)来锁定并哈希每一次TCP请求。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><strong style="text-align: center; font-weight: bold">Nginx和LVS对比的总结：</strong></p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">1、Nginx工作在网络的7层，所以它可以针对http应用本身来做分流策略，比如针对域名、目录结构等，相比之下LVS并不具备这样的功能，所以Nginx单凭这点可利用的场合就远多于LVS了；但Nginx有用的这些功能使其可调整度要高于LVS，所以经常要去触碰触碰，触碰多了，人为出问题的几率也就会大。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">2、Nginx对网络稳定性的依赖较小，理论上只要ping得通，网页访问正常，Nginx就能连得通，这是Nginx的一大优势！Nginx同时还能区分内外网，如果是同时拥有内外网的节点，就相当于单机拥有了备份线路；LVS就比较依赖于网络环境，目前来看服务器在同一网段内并且LVS使用direct方式分流，效果较能得到保证。另外注意，LVS需要向托管商至少申请多一个ip来做Visual IP，貌似是不能用本身的IP来做VIP的。要做好LVS管理员，确实得跟进学习很多有关网络通信方面的知识，就不再是一个HTTP那么简单了。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">3、Nginx安装和配置比较简单，测试起来也很方便，因为它基本能把错误用日志打印出来。LVS的安装和配置、测试就要花比较长的时间了；LVS对网络依赖比较大，很多时候不能配置成功都是因为网络问题而不是配置问题，出了问题要解决也相应的会麻烦得多。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">4、Nginx也同样能承受很高负载且稳定，但负载度和稳定度差LVS还有几个等级：Nginx处理所有流量所以受限于机器IO和配置；本身的bug也还是难以避免的。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">5、Nginx可以检测到服务器内部的故障，比如根据服务器处理网页返回的状态码、超时等等，并且会把返回错误的请求重新提交到另一个节点。目前LVS中 ldirectd也能支持针对服务器内部的情况来监控，但LVS的原理使其不能重发请求。比如用户正在上传一个文件，而处理该上传的节点刚好在上传过程中出现故障，Nginx会把上传切到另一台服务器重新处理，而LVS就直接断掉了，如果是上传一个很大的文件或者很重要的文件的话，用户可能会因此而恼火。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">6、Nginx对请求的异步处理可以帮助节点服务器减轻负载，假如使用<a style="color: rgb(0,66,118); text-decoration: underline" title="apache" href="http://www.ha97.com/category/web-server/apache">apache</a>直接对外服务，那么出现很多的窄带链接时apache服务器将会占用大 量内存而不能释放，使用多一个Nginx做apache代理的话，这些窄带链接会被Nginx挡住，apache上就不会堆积过多的请求，这样就减少了相当多的资源占用。这点使用squid也有相同的作用，即使squid本身配置为不缓存，对apache还是有很大帮助的。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">7、Nginx能支持http、https和email（email的功能比较少用），LVS所支持的应用在这点上会比Nginx更多。在使用上，一般最前端所采取的策略应是LVS，也就是DNS的指向应为LVS均衡器，LVS的优点令它非常适合做这个任务。重要的ip地址，最好交由LVS托管，比如数据库的 ip、webservice服务器的ip等等，这些ip地址随着时间推移，使用面会越来越大，如果更换ip则故障会接踵而至。所以将这些重要ip交给 LVS托管是最为稳妥的，这样做的唯一缺点是需要的VIP数量会比较多。Nginx可作为LVS节点机器使用，一是可以利用Nginx的功能，二是可以利用Nginx的性能。当然这一层面也可以直接使用squid，squid的功能方面就比Nginx弱不少了，性能上也有所逊色于Nginx。Nginx也可作为中层代理使用，这一层面Nginx基本上无对手，唯一可以撼动Nginx的就只有lighttpd了，不过lighttpd目前还没有能做到 Nginx完全的功能，配置也不那么清晰易读。另外，中层代理的IP也是重要的，所以中层代理也拥有一个VIP和LVS是最完美的方案了。具体的应用还得具体分析，如果是比较小的网站（日PV小于1000万），用Nginx就完全可以了，如果机器也不少，可以用DNS轮询，LVS所耗费的机器还是比较多的；大型网站或者重要的服务，机器不发愁的时候，要多多考虑利用LVS。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><strong style="text-align: center; font-weight: bold">现在对网络负载均衡的使用是随着网站规模的提升根据不同的阶段来使用不同的技术：</strong></p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">第一阶段：利用Nginx或HAProxy进行单点的负载均衡，这一阶段服务器规模刚脱离开单服务器、单数据库的模式，需要一定的负载均衡，但是仍然规模较小没有专业的维护团队来进行维护，也没有需要进行大规模的网站部署。这样利用Nginx或HAproxy就是第一选择，此时这些东西上手快， 配置容易，在七层之上利用HTTP协议就可以。这时是第一选择。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">第二阶段：随着网络服务进一步扩大，这时单点的Nginx已经不能满足，这时使用LVS或者商用Array就是首要选择，Nginx此时就作为LVS或者Array的节点来使用，具体LVS或Array的是选择是根据公司规模和预算来选择，Array的应用交付功能非常强大，本人在某项目中使用过，性价比也远高于F5，商用首选！但是一般来说这阶段相关人才跟不上业务的提升，所以购买商业负载均衡已经成为了必经之路。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">第三阶段：这时网络服务已经成为主流产品，此时随着公司知名度也进一步扩展，相关人才的能力以及数量也随之提升，这时无论从开发适合自身产品的定制，以及降低成本来讲开源的LVS，已经成为首选，这时LVS会成为主流。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">最终形成比较理想的基本架构为：<strong style="text-align: center; font-weight: bold">Array/LVS &#8212; Nginx/Haproxy &#8212; Squid/Varnish &#8212; AppServer</strong>。</p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">原文链接：<a style="color: rgb(0,66,118); text-decoration: underline" href="http://www.ha97.com/5646.html">http://www.ha97.com/5646.html</a></p>
<p style="padding-bottom: 0px; text-transform: none; background-color: rgb(248,248,248); text-indent: 28px; margin: 10px 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">【编辑推荐】</p>
<div style="text-transform: none; background-color: rgb(248,248,248); text-indent: 0px; letter-spacing: normal; font: 14px/28px 宋体; white-space: normal; color: rgb(51,51,51); word-spacing: 0px; -webkit-text-stroke-width: 0px">
<ol style="list-style: none none outside; padding-bottom: 0px; margin: 0px 0px 0px 55px; padding-left: 0px; padding-right: 0px; word-wrap: break-word; color: rgb(51,51,51); word-break: normal; padding-top: 0px"><li style="list-style: decimal none outside; padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: break-word; color: rgb(51,51,51); word-break: normal; padding-top: 0px"><a style="color: rgb(0,66,118); text-decoration: underline" href="http://os.51cto.com/art/201202/317108.htm" target="_blank">LVS基本介绍</a></li><li style="list-style: decimal none outside; padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: break-word; color: rgb(51,51,51); word-break: normal; padding-top: 0px"><a style="color: rgb(0,66,118); text-decoration: underline" href="http://os.51cto.com/art/201202/317441.htm" target="_blank">LVS+Keepalived构建高可用负载均衡</a></li><li style="list-style: decimal none outside; padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: break-word; color: rgb(51,51,51); word-break: normal; padding-top: 0px"><a style="color: rgb(0,66,118); text-decoration: underline" href="http://netsecurity.51cto.com/art/201403/434157.htm" target="_blank">Nginx安全配置研究</a></li><li style="list-style: decimal none outside; padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: break-word; color: rgb(51,51,51); word-break: normal; padding-top: 0px"><a style="color: rgb(0,66,118); text-decoration: underline" href="http://os.51cto.com/art/201404/434930.htm" target="_blank">Nginx配置性能优化的方法</a></li><li style="list-style: decimal none outside; padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: break-word; color: rgb(51,51,51); word-break: normal; padding-top: 0px"><a style="color: rgb(0,66,118); text-decoration: underline" href="http://os.51cto.com/art/201405/437652.htm" target="_blank">Nginx自定义模块编写：根据post参数路由到不同服务器</a></li></ol></div><img src ="http://www.blogjava.net/jjshcc/aggbug/426446.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-07-27 15:37 <a href="http://www.blogjava.net/jjshcc/archive/2015/07/27/426446.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>shell编程中的date用法</title><link>http://www.blogjava.net/jjshcc/archive/2015/07/23/426394.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Thu, 23 Jul 2015 07:50:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/07/23/426394.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/426394.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/07/23/426394.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/426394.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/426394.html</trackback:ping><description><![CDATA[<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">1、date --help</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">%% 输出%符号 a literal %<br />%a 当前域的星期缩写 locale&#8217;s abbreviated weekday name (Sun..Sat)<br />%A 当前域的星期全写 locale&#8217;s full weekday name, variable length (Sunday..Saturday)<br />%b 当前域的月份缩写 locale&#8217;s abbreviated month name (Jan..Dec)<br />%B 当前域的月份全称 locale&#8217;s full month name, variable length (January..December)<br />%c 当前域的默认时间格式 locale&#8217;s date and time (Sat Nov 04 12:02:33 EST 1989)<br />%C n百年 century (year divided by 100 and truncated to an integer) [00-99]<br />%d 两位的天 day of month (01..31)<br />%D 短时间格式 date (mm/dd/yy)<br />%e 短格式天 day of month, blank padded ( 1..31)<br />%F 文件时间格式 same as %Y-%m-%d<br />%g the 2-digit year corresponding to the %V week number<br />%G the 4-digit year corresponding to the %V week number<br />%h same as %b<br />%H 24小时制的小时 hour (00..23)<br />%I 12小时制的小时 hour (01..12)<br />%j 一年中的第几天 day of year (001..366)<br />%k 短格式24小时制的小时 hour ( 0..23)<br />%l 短格式12小时制的小时 hour ( 1..12)<br />%m 双位月份 month (01..12)<br />%M 双位分钟 minute (00..59)<br />%n 换行 a newline<br />%N 十亿分之一秒 nanoseconds (000000000..999999999)<br />%p 大写的当前域的上下午指示 locale&#8217;s upper case AM or PM indicator (blank in many locales)<br />%P 小写的当前域的上下午指示 locale&#8217;s lower case am or pm indicator (blank in many locales)<br />%r 12小时制的时间表示（时:分:秒,双位） time, 12-hour (hh:mm:ss [AP]M)<br />%R 24小时制的时间表示 （时:分,双位）time, 24-hour (hh:mm)<br />%s 自基础时间 1970-01-01 00:00:00 到当前时刻的秒数 seconds since `00:00:00 1970-01-01 UTC&#8217; (a GNU extension)<br />%S 双位秒 second (00..60); the 60 is necessary to accommodate a leap second<br />%t 横向制表位(tab) a horizontal tab<br />%T 24小时制时间表示 time, 24-hour (hh:mm:ss)<br />%u 数字表示的星期（从星期一开始 1-7）day of week (1..7); 1 represents Monday<br />%U 一年中的第几周星期天为开始 week number of year with Sunday as first day of week (00..53)<br />%V 一年中的第几周星期一为开始 week number of year with Monday as first day of week (01..53)<br />%w 一周中的第几天 星期天为开始 0-6 day of week (0..6); 0 represents Sunday<br />%W 一年中的第几周星期一为开始 week number of year with Monday as first day of week (00..53)<br />%x 本地日期格式 locale&#8217;s date representation (mm/dd/yy)<br />%X 本地时间格式 locale&#8217;s time representation (%H:%M:%S)<br />%y 两位的年 last two digits of year (00..99)<br />%Y 年 year (1970&#8230;)<br />%z RFC-2822 标准时间格式表示的域 RFC-2822 style numeric timezone (-0500) (a nonstandard extension)<br />%Z 时间域 time zone (e.g., EDT), or nothing if no time zone is determinable</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">By default, date pads numeric fields with zeroes. GNU date recognizes<br />the following modifiers between `%&#8217; and a numeric directive.</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">`-&#8217; (hyphen) do not pad the field<br />`_&#8217; (underscore) pad the field with spaces</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">--------------------------------------------------------------------------------</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">2、一些用法</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">1）#以yymmdd的格式输出43天前的当前时刻</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">date +%Y%m%d --date='43 days ago'&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">2）# 测试十亿分之一秒<br />date +&#8217;%Y%m%d %H:%M:%S.%N&#8217;;date +&#8217;%Y%m%d %H:%M:%S.%N&#8217;;date +&#8217;%Y%m%d %H:%M:%S.%N&#8217;;date +&#8217;%Y%m%d %H:%M:%S.%N&#8217;<br /></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">3）#创建以当前时间为文件名的目录<br />mkdir `date +%Y%m%d`</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">4）#备份以时间做为文件名的<br />tar -cvf ./htdocs`date +%Y%m%d`.tar ./*</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">5）#显示时间后跳行，再显示目前日期&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">date +%T%n%Y%m%d</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">6）#只显示月份与日数&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">date +%B%d</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">7）#获取上周日期（day,month,year,hour）</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">date -d "-1 week" +%Y%m%d 　　</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">8）#获取24小时前日期</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">date --date="-24 hour" +%Y%m%d</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">9）#shell脚本里面赋给变量值</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">date_now=`date +%s`</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">10）#计算执行一段sql脚本的运行时间</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">TIME_BEGIN=$(date '+%s.%N')<br />$sqlcli &lt; queries/q1.3.sql 1&gt;&gt; $FILE_RESULT&nbsp;<wbr><span class="Apple-converted-space">&nbsp;</span>2&gt;&gt; $FILE_ERROR<br />TIME_END=$(date '+%s.%N')<br />TIME_RUN=$(awk 'BEGIN{print '$TIME_END' - '$TIME_BEGIN'}')</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">11）#编写shell脚本计算离自己生日还有多少天？</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr><span class="Apple-converted-space">&nbsp;</span>read -p "Input your birthday(YYYYmmdd):" date1</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　m=`date --date="$date1" +%m`&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr><span class="Apple-converted-space">&nbsp;</span>#得到生日的月</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　d=`date --date="$date1" +%d`&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr><span class="Apple-converted-space">&nbsp;</span>#得到生日的日</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　date_now=`date +%s`&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr><span class="Apple-converted-space">&nbsp;</span>#得到当前时间的秒值</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　y=`date +%Y`&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>#得到当前时间的年</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　birth=`date --date="$y$m$d" +%s`&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr><span class="Apple-converted-space">&nbsp;</span>#得到今年的生日日期的秒值</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　internal=$(($birth-$date_now))&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr><span class="Apple-converted-space">&nbsp;</span>#计算今日到生日日期的间隔时间</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　if [ "$internal" -lt "0" ]; then&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr><span class="Apple-converted-space">&nbsp;</span>#判断今天的生日是否已过</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　birth=`date --date="$(($y+1))$m$d" +%s`&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr><span class="Apple-converted-space">&nbsp;</span>#得到明天的生日日期秒值</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　internal=$(($birth-$date_now))&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr><span class="Apple-converted-space">&nbsp;</span>#计算今天到下一个生日的间隔时间</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　fi</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">　　echo "There is :$((einternal/60/60/24)) days."&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr><span class="Apple-converted-space">&nbsp;</span>#输出结果，秒换算为天</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">12）#若是不以加号作为开头，则表示要设定时间，而时间格式为 MMDDhhmm[[CC]YY][.ss]，</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">其中 MM 为月份，</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">DD 为日，</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">hh 为小时，</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">mm 为分钟，</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">CC 为年份前两位数字，</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">YY 为年份后两位数字，</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">ss 为秒数</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">13）</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">#显示目前的格林威治时间，也叫&#8220;世界时&#8221;。是英国的标准时间，也是世界各地时间的参考标准。中英两国的标准<a style="color: rgb(82,102,115); text-decoration: none" href="http://baike.baidu.com/view/72144.htm" target="_blank"><font style="line-height: 21px; word-wrap: normal; word-break: normal" color="#136ec2">时差</font></a>为8个小时，即英国的当地时间比中国的<a style="color: rgb(82,102,115); text-decoration: none" href="http://baike.baidu.com/view/21267.htm" target="_blank"><font style="line-height: 21px; word-wrap: normal; word-break: normal" color="#136ec2">北京时间</font></a>晚8小时。</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">date -u&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr><br />Thu Sep 28 09:32:04 UTC 2006</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">14）#修改时间</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; text-transform: none; background-color: rgb(246,246,246); list-style-type: none; text-indent: 0px; margin: 0px 0px 5px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/21px simsun; word-wrap: normal; white-space: normal; color: rgb(73,73,73); word-break: normal; border-top: 0px; border-right: 0px; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">date -s<br />按字符串方式修改时间<br />可以只修改日期,不修改时间,输入: date -s 2007-08-03<br />只修改时间,输入:date -s 14:15:00<br />同时修改日期时间,注意要加双引号,日期与时间之间有一空格,输入:date -s "2007-08-03 14:15:00"<br /><br />修改完后,记得输入:clock -w<br />把系统时间写入CMOS</p><img src ="http://www.blogjava.net/jjshcc/aggbug/426394.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-07-23 15:50 <a href="http://www.blogjava.net/jjshcc/archive/2015/07/23/426394.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux traceroute命令详解和使用例子（追踪路由信息）</title><link>http://www.blogjava.net/jjshcc/archive/2015/07/21/426361.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Tue, 21 Jul 2015 06:06:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/07/21/426361.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/426361.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/07/21/426361.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/426361.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/426361.html</trackback:ping><description><![CDATA[<div id="art_desc">通过traceroute我们可以知道信息从你的计算机到互联网另一端的主机是走的什么路径。当然每次数据包由某一同样的出发点（source）到达某一同样的目的地(destination)走的路径可能会不一样，但基本上来说大部分时候所走的路由是相同的</div><br /><br />
<p>linux系统中，我们称之为traceroute,在MS Windows中为tracert。 traceroute通过发送小的数据包到目的设备直到其返回，来测量其需要多长时间。一条路径上的每个设备traceroute要测3次。输出结果中包括每次测试的时间(ms)和设备的名称（如有的话）及其IP地址。</p>
<p>在大多数情况下，我们会在linux主机系统下，直接执行命令行：traceroute hostname</p>
<p>而在Windows系统下是执行tracert的命令： tracert hostname</p>
<p><strong>1.命令格式：</strong></p>
<p>traceroute[参数][主机]</p>
<p><strong>2.命令功能：</strong></p>
<p>traceroute指令让你追踪网络数据包的路由途径，预设数据包大小是40Bytes，用户可另行设置。</p>
<p>具体参数格式：traceroute [-dFlnrvx][-f&lt;存活数值&gt;][-g&lt;网关&gt;...][-i&lt;网络界面&gt;][-m&lt;存活数值&gt;][-p&lt;通信端口&gt;][-s&lt;来源地址&gt;][-t&lt;服务类型&gt;][-w&lt;超时秒数&gt;][主机名称或IP地址][数据包大小]<br /></p>
<p><strong>3.命令参数：</strong></p>
<p>-d 使用Socket层级的排错功能。</p>
<p>-f 设置第一个检测数据包的存活数值TTL的大小。</p>
<p>-F 设置勿离断位。</p>
<p>-g 设置来源路由网关，最多可设置8个。</p>
<p>-i 使用指定的网络界面送出数据包。</p>
<p>-I 使用ICMP回应取代UDP资料信息。</p>
<p>-m 设置检测数据包的最大存活数值TTL的大小。</p>
<p>-n 直接使用IP地址而非主机名称。</p>
<p>-p 设置UDP传输协议的通信端口。</p>
<p>-r 忽略普通的Routing Table，直接将数据包送到远端主机上。</p>
<p>-s 设置本地主机送出数据包的IP地址。</p>
<p>-t 设置检测数据包的TOS数值。</p>
<p>-v 详细显示指令的执行过程。</p>
<p>-w 设置等待远端主机回报的时间。</p>
<p>-x 开启或关闭数据包的正确性检验。</p>
<p><strong>4.使用实例：</strong></p>
<p><strong>实例1：traceroute 用法简单、最常用的用法</strong></p>
<p>命令：traceroute www.baidu.com </p>
<p>输出：<br />[root@localhost ~]# traceroute www.baidu.com<br />traceroute to www.baidu.com (61.135.169.125), 30 hops max, 40 byte packets<br />1 192.168.74.2 (192.168.74.2) 2.606 ms 2.771 ms 2.950 ms<br />2 211.151.56.57 (211.151.56.57) 0.596 ms 0.598 ms 0.591 ms<br />3 211.151.227.206 (211.151.227.206) 0.546 ms 0.544 ms 0.538 ms<br />4 210.77.139.145 (210.77.139.145) 0.710 ms 0.748 ms 0.801 ms<br />5 202.106.42.101 (202.106.42.101) 6.759 ms 6.945 ms 7.107 ms<br />6 61.148.154.97 (61.148.154.97) 718.908 ms * bt-228-025.bta.net.cn (202.106.228.25) 5.177 ms<br />7 124.65.58.213 (124.65.58.213) 4.343 ms 4.336 ms 4.367 ms<br />8 202.106.35.190 (202.106.35.190) 1.795 ms 61.148.156.138 (61.148.156.138) 1.899 ms 1.951 ms<br />9 * * *<br />30 * * *<br />[root@localhost ~]# <br /></p>
<p>&nbsp;</p>
<p>说明：</p>
<p>记录按序列号从1开始，每个纪录就是一跳 ，每跳表示一个网关，我们看到每行有三个时间，单位是 ms，其实就是-q的默认参数。探测数据包向每个网关发送三个数据包后，网关响应后返回的时间；如果您用 traceroute -q 4 www.58.com ，表示向每个网关发送4个数据包。</p>
<p>有时我们traceroute 一台主机时，会看到有一些行是以星号表示的。出现这样的情况，可能是防火墙封掉了ICMP的返回信息，所以我们得不到什么相关的数据包返回数据。</p>
<p>有时我们在某一网关处延时比较长，有可能是某台网关比较阻塞，也可能是物理设备本身的原因。当然如果某台DNS出现问题时，不能解析主机名、域名时，也会 有延时长的现象；您可以加-n 参数来避免DNS解析，以IP格式输出数据。</p>
<p>如果在局域网中的不同网段之间，我们可以通过traceroute 来排查问题所在，是主机的问题还是网关的问题。如果我们通过远程来访问某台服务器遇到问题时，我们用到traceroute 追踪数据包所经过的网关，提交IDC服务商，也有助于解决问题；但目前看来在国内解决这样的问题是比较困难的，就是我们发现问题所在，IDC服务商也不可能帮助我们解决。</p>
<p><strong>实例2：跳数设置</strong></p>
<p>命令：traceroute -m 10 www.baidu.com</p>
<p>输出：<br />[root@localhost ~]# traceroute -m 10 www.baidu.com<br />traceroute to www.baidu.com (61.135.169.105), 10 hops max, 40 byte packets<br />1 192.168.74.2 (192.168.74.2) 1.534 ms 1.775 ms 1.961 ms<br />2 211.151.56.1 (211.151.56.1) 0.508 ms 0.514 ms 0.507 ms<br />3 211.151.227.206 (211.151.227.206) 0.571 ms 0.558 ms 0.550 ms<br />4 210.77.139.145 (210.77.139.145) 0.708 ms 0.729 ms 0.785 ms<br />5 202.106.42.101 (202.106.42.101) 7.978 ms 8.155 ms 8.311 ms<br />6 bt-228-037.bta.net.cn (202.106.228.37) 772.460 ms bt-228-025.bta.net.cn (202.106.228.25) 2.152 ms 61.148.154.97 (61.148.154.97) 772.107 ms<br />7 124.65.58.221 (124.65.58.221) 4.875 ms 61.148.146.29 (61.148.146.29) 2.124 ms 124.65.58.221 (124.65.58.221) 4.854 ms<br />8 123.126.6.198 (123.126.6.198) 2.944 ms 61.148.156.6 (61.148.156.6) 3.505 ms 123.126.6.198 (123.126.6.198) 2.885 ms<br />9 * * *<br />10 * * *<br />[root@localhost ~]#<br /></p><br />
<p>&nbsp;</p>
<p><strong>实例3：显示IP地址，不查主机名</strong><strong></strong></p>
<p>命令：traceroute -n www.baidu.com</p>
<p>输出：<br />[root@localhost ~]# traceroute -n www.baidu.com<br />traceroute to www.baidu.com (61.135.169.125), 30 hops max, 40 byte packets<br />1 211.151.74.2 5.430 ms 5.636 ms 5.802 ms<br />2 211.151.56.57 0.627 ms 0.625 ms 0.617 ms<br />3 211.151.227.206 0.575 ms 0.584 ms 0.576 ms<br />4 210.77.139.145 0.703 ms 0.754 ms 0.806 ms<br />5 202.106.42.101 23.683 ms 23.869 ms 23.998 ms<br />6 202.106.228.37 247.101 ms * *<br />7 61.148.146.29 5.256 ms 124.65.58.213 4.386 ms 4.373 ms<br />8 202.106.35.190 1.610 ms 61.148.156.138 1.786 ms 61.148.3.34 2.089 ms<br />9 * * *<br />30 * * *<br />[root@localhost ~]# traceroute www.baidu.com<br />traceroute to www.baidu.com (61.135.169.125), 30 hops max, 40 byte packets<br />1 211.151.74.2 (211.151.74.2) 4.671 ms 4.865 ms 5.055 ms<br />2 211.151.56.57 (211.151.56.57) 0.619 ms 0.618 ms 0.612 ms<br />3 211.151.227.206 (211.151.227.206) 0.620 ms 0.642 ms 0.636 ms<br />4 210.77.139.145 (210.77.139.145) 0.720 ms 0.772 ms 0.816 ms<br />5 202.106.42.101 (202.106.42.101) 7.667 ms 7.910 ms 8.012 ms<br />6 bt-228-025.bta.net.cn (202.106.228.25) 2.965 ms 2.440 ms 61.148.154.97 (61.148.154.97) 431.337 ms<br />7 124.65.58.213 (124.65.58.213) 5.134 ms 5.124 ms 5.044 ms<br />8 202.106.35.190 (202.106.35.190) 1.917 ms 2.052 ms 2.059 ms<br />9 * * *<br />30 * * *<br />[root@localhost ~]# <br /></p>
<p>&nbsp;</p>
<p><strong>实例4：探测包使用的基本UDP端口设置6888</strong></p>
<p>命令：traceroute -p 6888 <a href="http://www.baidu.com">www.baidu.com</a><br />[root@localhost ~]# traceroute -p 6888 www.baidu.com<br />traceroute to www.baidu.com (220.181.111.147), 30 hops max, 40 byte packets<br />1 211.151.74.2 (211.151.74.2) 4.927 ms 5.121 ms 5.298 ms<br />2 211.151.56.1 (211.151.56.1) 0.500 ms 0.499 ms 0.509 ms<br />3 211.151.224.90 (211.151.224.90) 0.637 ms 0.631 ms 0.641 ms<br />4 * * *<br />5 220.181.70.98 (220.181.70.98) 5.050 ms 5.313 ms 5.596 ms<br />6 220.181.17.94 (220.181.17.94) 1.665 ms !X * *<br />[root@localhost ~]# <br /></p>
<p>&nbsp;</p>
<p><strong>实例5：把探测包的个数设置为值4</strong></p>
<p>命令：traceroute -q 4 www.baidu.com</p>
<p>&nbsp;<br />[root@localhost ~]# traceroute -q 4 www.baidu.com<br />traceroute to www.baidu.com (61.135.169.125), 30 hops max, 40 byte packets<br />1 211.151.74.2 (211.151.74.2) 40.633 ms 40.819 ms 41.004 ms 41.188 ms<br />2 211.151.56.57 (211.151.56.57) 0.637 ms 0.633 ms 0.627 ms 0.619 ms<br />3 211.151.227.206 (211.151.227.206) 0.505 ms 0.580 ms 0.571 ms 0.569 ms<br />4 210.77.139.145 (210.77.139.145) 0.753 ms 0.800 ms 0.853 ms 0.904 ms<br />5 202.106.42.101 (202.106.42.101) 7.449 ms 7.543 ms 7.738 ms 7.893 ms<br />6 61.148.154.97 (61.148.154.97) 316.817 ms bt-228-025.bta.net.cn (202.106.228.25) 3.695 ms 3.672 ms *<br />7 124.65.58.213 (124.65.58.213) 3.056 ms 2.993 ms 2.960 ms 61.148.146.29 (61.148.146.29) 2.837 ms<br />8 61.148.3.34 (61.148.3.34) 2.179 ms 2.295 ms 2.442 ms 202.106.35.190 (202.106.35.190) 7.136 ms<br />9 * * * *<br />30 * * * *<br />[root@localhost ~]# <br /></p><br />
<p><strong>实例6：绕过正常的路由表，直接发送到网络相连的主机</strong></p>
<p>命令：traceroute -r www.baidu.com</p>
<p>输出：<br />[root@localhost ~]# traceroute -r www.baidu.com<br />traceroute to www.baidu.com (61.135.169.125), 30 hops max, 40 byte packets<br />connect: 网络不可达<br />[root@localhost ~]# <br /></p>
<p>&nbsp;</p>
<p>实例7：把对外发探测包的等待响应时间设置为3秒</p>
<p>命令：traceroute -w 3 www.baidu.com</p>
<p>输出：<br /><br />[root@localhost ~]# traceroute -w 3 www.baidu.com<br />traceroute to www.baidu.com (61.135.169.105), 30 hops max, 40 byte packets<br />1 211.151.74.2 (211.151.74.2) 2.306 ms 2.469 ms 2.650 ms<br />2 211.151.56.1 (211.151.56.1) 0.621 ms 0.613 ms 0.603 ms<br />3 211.151.227.206 (211.151.227.206) 0.557 ms 0.560 ms 0.552 ms<br />4 210.77.139.145 (210.77.139.145) 0.708 ms 0.761 ms 0.817 ms<br />5 202.106.42.101 (202.106.42.101) 7.520 ms 7.774 ms 7.902 ms<br />6 bt-228-025.bta.net.cn (202.106.228.25) 2.890 ms 2.369 ms 61.148.154.97 (61.148.154.97) 471.961 ms<br />7 124.65.58.221 (124.65.58.221) 4.490 ms 4.483 ms 4.472 ms<br />8 123.126.6.198 (123.126.6.198) 2.948 ms 61.148.156.6 (61.148.156.6) 7.688 ms 7.756 ms<br />9 * * *<br />30 * * *<br />[root@localhost ~]# <br /></p><br />
<p>&nbsp;</p>
<p><strong>Traceroute的工作原理：</strong></p>
<p>Traceroute最简单的基本用法是：traceroute hostname</p>
<p>Traceroute程序的设计是利用ICMP及IP header的TTL（Time To Live）栏位（field）。首先，traceroute送出一个TTL是1的IP datagram（其实，每次送出的为3个40字节的包，包括源地址，目的地址和包发出的时间标签）到目的地，当路径上的第一个路由器（router）收到这个datagram时，它将TTL减1。此时，TTL变为0了，所以该路由器会将此datagram丢掉，并送回一个「ICMP time exceeded」消息（包括发IP包的源地址，IP包的所有内容及路由器的IP地址），traceroute 收到这个消息后，便知道这个路由器存在于这个路径上，接着traceroute 再送出另一个TTL是2 的datagram，发现第2 个路由器...... traceroute 每次将送出的datagram的TTL 加1来发现另一个路由器，这个重复的动作一直持续到某个datagram 抵达目的地。当datagram到达目的地后，该主机并不会送回ICMP time exceeded消息，因为它已是目的地了，那么traceroute如何得知目的地到达了呢？</p>
<p>Traceroute在送出UDP datagrams到目的地时，它所选择送达的port number 是一个一般应用程序都不会用的号码（30000 以上），所以当此UDP datagram 到达目的地后该主机会送回一个「ICMP port unreachable」的消息，而当traceroute 收到这个消息时，便知道目的地已经到达了。所以traceroute 在Server端也是没有所谓的Daemon 程式。</p>
<p>Traceroute提取发 ICMP TTL到期消息设备的IP地址并作域名解析。每次 ，Traceroute都打印出一系列数据,包括所经过的路由设备的域名及 IP地址,三个包每次来回所花时间。</p>
<p><strong>windows之tracert:</strong></p>
<p>格式：</p>
<p>tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] target_name</p>
<p>参数说明：</p>
<p>tracert [-d] [-h maximum_hops] [-j computer-list] [-w timeout] target_name</p>
<p>该诊断实用程序通过向目的地发送具有不同生存时间 (TL) 的 Internet 控制信息协议 (CMP) 回应报文，以确定至目的地的路由。路径上的每个路由器都要在转发该 ICMP 回应报文之前将其 TTL 值至少减 1，因此 TTL 是有效的跳转计数。当报文的 TTL 值减少到 0 时，路由器向源系统发回 ICMP 超时信息。通过发送 TTL 为 1 的第一个回应报文并且在随后的发送中每次将 TTL 值加 1，直到目标响应或达到最大 TTL 值，Tracert 可以确定路由。通过检查中间路由器发发回的 ICMP 超时 (ime Exceeded) 信息，可以确定路由器。注意，有些路由器&#8220;安静&#8221;地丢弃生存时间 (TLS) 过期的报文并且对 tracert 无效。</p>
<p>参数：</p>
<p>-d 指定不对计算机名解析地址。</p>
<p>-h maximum_hops 指定查找目标的跳转的最大数目。</p>
<p>-jcomputer-list 指定在 computer-list 中松散源路由。</p>
<p>-w timeout 等待由 timeout 对每个应答指定的毫秒数。</p>
<p>target_name 目标计算机的名称。</p>
<p>实例：<br /><br /></p>
<div class="msgheader">
<div class="right"><span style="cursor: pointer"></span><u>&nbsp;</u><br />C:\Users\Administrator&gt;tracert www.58.com<br />Tracing route to www.58.com [221.187.111.30]<br />over a maximum of 30 hops:<br />1 1 ms 1 ms 1 ms 10.58.156.1<br />2 1 ms &lt;1 ms &lt;1 ms 10.10.10.1<br />3 1 ms 1 ms 1 ms 211.103.193.129<br />4 2 ms 2 ms 2 ms 10.255.109.129<br />5 1 ms 1 ms 3 ms 124.205.98.205<br />6 2 ms 2 ms 2 ms 124.205.98.253<br />7 2 ms 6 ms 1 ms 202.99.1.125<br />8 5 ms 6 ms 5 ms 118.186.0.113<br />9 207 ms * * 118.186.0.106<br />10 8 ms 6 ms 11 ms 124.238.226.201<br />11 6 ms 7 ms 6 ms 219.148.19.177<br />12 12 ms 12 ms 16 ms 219.148.18.117<br />13 14 ms 17 ms 16 ms 219.148.19.125<br />14 13 ms 13 ms 12 ms 202.97.80.113<br />15 * * * Request timed out.<br />16 12 ms 12 ms 17 ms bj141-147-82.bjtelecom.net [219.141.147.82]<br />17 13 ms 13 ms 12 ms 202.97.48.2<br />18 * * * Request timed out.<br />19 14 ms 14 ms 12 ms 221.187.224.85<br />20 15 ms 13 ms 12 ms 221.187.104.2<br />21 * * * Request timed out.<br />22 15 ms 17 ms 18 ms 221.187.111.30<br />Trace complete.<br /></div></div><img src ="http://www.blogjava.net/jjshcc/aggbug/426361.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-07-21 14:06 <a href="http://www.blogjava.net/jjshcc/archive/2015/07/21/426361.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>/etc/resolv.conf中关键字search和domain的作用</title><link>http://www.blogjava.net/jjshcc/archive/2015/07/21/426356.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Tue, 21 Jul 2015 04:49:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/07/21/426356.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/426356.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/07/21/426356.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/426356.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/426356.html</trackback:ping><description><![CDATA[<span style="text-align: left; text-transform: none; background-color: rgb(202,155,112); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 14px/21px simsun; white-space: normal; float: none; color: rgb(70,70,70); word-spacing: 0px; -webkit-text-stroke-width: 0px">domain 声明主机的域名。很多程序用到它，如邮件系统；当为没有域名的主机进行DNS 查询时，也要用到。如果没有域名，主机名将被使用，删除所有在第一个点( . )前面的内容。</span><br style="text-align: left; text-transform: none; background-color: rgb(202,155,112); text-indent: 0px; letter-spacing: normal; font: 14px/21px simsun; white-space: normal; color: rgb(70,70,70); word-spacing: 0px; -webkit-text-stroke-width: 0px" /><span style="text-align: left; text-transform: none; background-color: rgb(202,155,112); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 14px/21px simsun; white-space: normal; float: none; color: rgb(70,70,70); word-spacing: 0px; -webkit-text-stroke-width: 0px">search 它的多个参数指明域名查询顺序。当要查询没有域名的主机，主机将在由search 声明的域中分别查找。domain 和search 不能共存；如果同时存在，后面出现的将会被使用。</span><br style="text-align: left; text-transform: none; background-color: rgb(202,155,112); text-indent: 0px; letter-spacing: normal; font: 14px/21px simsun; white-space: normal; color: rgb(70,70,70); word-spacing: 0px; -webkit-text-stroke-width: 0px" />
<div style="text-align: left; text-transform: none; background-color: rgb(202,155,112); text-indent: 0px; letter-spacing: normal; font: 14px/21px simsun; white-space: normal; color: rgb(70,70,70); word-spacing: 0px; -webkit-text-stroke-width: 0px"><br /></div>
<div style="text-align: left; text-transform: none; background-color: rgb(202,155,112); text-indent: 0px; letter-spacing: normal; font: 14px/21px simsun; white-space: normal; color: rgb(70,70,70); word-spacing: 0px; -webkit-text-stroke-width: 0px">下面的说明更清晰</div>
<div style="text-align: left; text-transform: none; background-color: rgb(202,155,112); text-indent: 0px; letter-spacing: normal; font: 14px/21px simsun; white-space: normal; color: rgb(70,70,70); word-spacing: 0px; -webkit-text-stroke-width: 0px">
<div>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 21px; list-style-type: none; margin: 0px 0px 5px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; border-top: 0px; border-right: 0px; padding-top: 0px">在<tt>/etc/resolv.conf</tt><span class="Apple-converted-space">&nbsp;</span>配置文件：domain 和search作用是一样的</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 21px; list-style-type: none; margin: 0px 0px 5px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; border-top: 0px; border-right: 0px; padding-top: 0px">domain linpro.no<br />search linpro.no uio.no ifi.uio.no</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 21px; list-style-type: none; margin: 0px 0px 5px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; border-top: 0px; border-right: 0px; padding-top: 0px"><span style="line-height: 21px; word-wrap: normal; color: rgb(255,0,0); word-break: normal">domain function:</span></p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 21px; list-style-type: none; margin: 0px 0px 5px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; border-top: 0px; border-right: 0px; padding-top: 0px">Had I typed<span class="Apple-converted-space">&nbsp;</span><tt>telnet math.uio.no</tt>. with the trailing dot, the resolver would have known it was an FQDN and would have looked up<span class="Apple-converted-space">&nbsp;</span><tt>math.uio.no</tt><span class="Apple-converted-space">&nbsp;</span>at once, without trying to append the specified domain first. Not all applications are tolerant of the trailing dot, though, so it can't always be specified.</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 21px; list-style-type: none; margin: 0px 0px 5px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; border-top: 0px; border-right: 0px; padding-top: 0px"><span style="line-height: 21px; word-wrap: normal; color: rgb(255,0,0); word-break: normal">search function:</span></p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; line-height: 21px; list-style-type: none; margin: 0px 0px 5px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; border-top: 0px; border-right: 0px; padding-top: 0px">When<span class="Apple-converted-space">&nbsp;</span><tt>ssh gram</tt><span class="Apple-converted-space">&nbsp;</span>is executed, the resolver first looks for<span class="Apple-converted-space">&nbsp;</span><tt>gram.linpro.no</tt>, which does not exist; then<tt>gram.uio.no</tt>, which does not exist, either; and finally<span class="Apple-converted-space">&nbsp;</span><tt>gram.ifi.uio.no</tt>, which will succeed because it does exist</p></div></div><img src ="http://www.blogjava.net/jjshcc/aggbug/426356.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-07-21 12:49 <a href="http://www.blogjava.net/jjshcc/archive/2015/07/21/426356.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>bash中 2&gt;&amp;1 &amp; 的解释</title><link>http://www.blogjava.net/jjshcc/archive/2015/07/15/426227.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Wed, 15 Jul 2015 01:56:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/07/15/426227.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/426227.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/07/15/426227.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/426227.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/426227.html</trackback:ping><description><![CDATA[<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">1、首先，bash中0，1，2三个数字分别代表STDIN_FILENO、STDOUT_FILENO、STDERR_FILENO，即标准输入（一般是键盘），标准输出（一般是显示屏，准确的说是用户终端控制台），标准错误（出错信息输出）。</p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">2、输入输出可以重定向，所谓重定向输入就是在命令中指定具体的输入来源，譬如 cat &lt; test.c 将test.c重定向为cat命令的输入源。输出重定向是指定具体的输出目标以替换默认的标准输出，譬如ls &gt; 1.txt将ls的结果从标准输出重定向为1.txt文本。有时候会看到如 ls &gt;&gt; 1.txt这类的写法，&gt; 和 &gt;&gt; 的区别在于：&gt; 用于新建而&gt;&gt;用于追加。即ls &gt; 1.txt会新建一个1.txt文件并且将ls的内容输出到新建的1.txt中，而ls &gt;&gt; 1.txt则用在1.txt已经存在，而我们只是想将ls的内容追加到1.txt文本中的时候。<br /></p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">3、默认输入只有一个（0，STDIN_FILENO），而默认输出有两个（标准输出1 STDOUT_FILENO，标准错误2 STDERR_FILENO）。因此默认情况下，shell输出的错误信息会被输出到2，而普通输出信息会输出到1。但是某些情况下，我们希望在一个终端下看到所有的信息（包括标准输出信息和错误信息），要怎么办呢？</p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 对了，你可以使用我们上面讲到的输出重定向。思路有了，怎么写呢？ 非常直观的想法就是2&gt;1（将2重定向到1嘛），行不行呢？试一试就知道了。我们进行以下测试步骤：</p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">1）mkdir test &amp;&amp; cd test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; 创建test文件夹并进入test目录</p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">2）touch a.txt b.c c&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; ; 创建a.txt b.c c 三个文件</p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">3）ls &gt; 1&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; ; 按我们的猜测，这句应该是将ls的结果重定向到标准输出，因此效果和直接ls应该一样。但是实际这句执行后，标准输出中并没有任何信息。</p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">4）ls&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; ; 执行3之后再次ls，则会看到test文件夹中多了一个文件1</p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">5）cat 1&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; ; 查看文件1的内容，实际结果为：1 a.txt b.c c&nbsp;&nbsp;&nbsp;&nbsp; 可见步骤3中 ls &gt; 1并不是将ls的结果重定向为标准输出，而是将结果重定向到了一个文件1中。即1在此处不被解释为STDOUT_FILENO，而是文件1。</p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">4、到了此时，你应该也能猜到2&gt;&amp;1的用意了。不错，2&gt;&amp;1就是用来将标准错误2重定向到标准输出1中的。此处1前面的&amp;就是为了让bash将1解释成标准输出而不是文件1。至于最后一个&amp;，则是让bash在后台执行。</p><img src ="http://www.blogjava.net/jjshcc/aggbug/426227.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-07-15 09:56 <a href="http://www.blogjava.net/jjshcc/archive/2015/07/15/426227.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux 切换用户身份、su、sudo、/etc/sudoers</title><link>http://www.blogjava.net/jjshcc/archive/2015/07/13/426188.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Mon, 13 Jul 2015 03:54:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/07/13/426188.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/426188.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/07/13/426188.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/426188.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/426188.html</trackback:ping><description><![CDATA[<p>Linux系统中，有时候普通用户有些事情是不能做的，除非是root用户才能做到。这时就需要用su命令临时切换到root身份来做事了。 </p>
<p>su：substitute['sʌbstɪtjuːt]代替 user <br />su 的语法为： <br />su [OPTION选项参数] [用户] <br />-, -l, --login 登录并改变到所切换的用户环境； <br />-c, --commmand=COMMAND 执行一个命令，然后退出所切换到的用户环境； </p>
<p>用su命令切换用户后，可以用 exit 命令或快捷键[Ctrl+D]可返回原登录用户。 </p>
<p>例子： <br />su 在不加任何参数，默认为切换到root用户，但没有转到root用户家目录下，也就是说这时虽然是切换为root用户了，但并没有改变root登录环境；用户默认的登录环境，可以在/etc/passwd 中查得到，包括家目录，SHELL定义等； <br />su 加参数 - ，表示默认切换到root用户，并且改变到root用户的环境； </p>
<p><br />用su是可以切换用户身份，如果每个普通用户都能切换到root身份，如果某个用户不小心泄漏了root的密码，那岂不是系统非常的不安全？没有错，为了改进这个问题，产生了sudo这个命令。使用sudo执行一个root才能执行的命令是可以办到的，但是需要输入密码，这个密码并不是root的密码而是用户自己的密码。默认只有root用户能使用sudo命令，普通用户想要使用sudo，是需要root预先设定的，即，使用visudo命令去编辑相关的配置文件/etc/sudoers。如果没有visudo这个命令，请使用 "yum install -y sudo" 安装。 </p>
<p>默认root能够sudo是因为这个文件中有一行&#8221; root ALL=(ALL) ALL&#8221; </p>
<p>sudo 的适用条件： <br />由于su对切换到超级权限用户root后，权限的无限制性，所以su并不能担任多个管理员所管理的系统。如果用su来切换到超级用户来管理系统，也不能明 确哪些工作是由哪个管理员进行的操作。特别是对于服务器的管理有多人参与管理时，最好是针对每个管理员的技术特长和管理范围，并且有针对性的下放给权限， 并且约定其使用哪些工具来完成与其相关的工作，这时我们就有必要用到 sudo。 <br />通过sudo，我们能把某些超级权限有针对性的下放，并且不需要普通用户知道root密码，所以sudo 相对于权限无限制性的su来说，还是比较安全的，所以sudo 也能被称为受限制的su ；另外sudo 是需要授权许可的，所以也被称为授权许可的su； <br />sudo 执行命令的流程：是当前用户切换到root（或其它指定切换到的用户），然后以root（或其它指定的切换到的用户）身份执行命令，执行完成后，直接退回到当前用户；而这些的前提是要通过sudo的配置文件/etc/sudoers来进行授权； </p>
<p>从编写 sudo 配置文件/etc/sudoers开始 <br />sudo的配置文件是/etc/sudoers ，我们可以用他的专用编辑工具visodu ，此工具的好处是在添加规则不太准确时，保存退出时会提示给我们错误信息；配置好后，可以用切换到您授权的用户下，通过sudo -l 来查看哪些命令是可以执行或禁止的； <br />/etc/sudoers 文件中每行算一个规则，前面带有#号可以当作是说明的内容，并不执行；如果规则很长，一行列不下时，可以用\号来续行，这样看来一个规则也可以拥有多个行； <br />/etc/sudoers 的规则可分为两类；一类是别名定义，另一类是授权规则；别名定义并不是必须的，但授权规则是必须的； </p>
<p>sudo授权规则(sudoers配置)： <br />授权用户 主机=命令动作 <br />这三个要素缺一不可，但在动作之前也可以指定切换到特定用户下，在这里指定切换的用户要用( )号括起来，如果不需要密码直接运行命令的，应该加NOPASSWD:参数，但这些可以省略；举例说明； </p>
<p>sudoers的缺省配置： <br />Html代码&nbsp; 收藏代码<br />#############################################################&nbsp;&nbsp; <br /># sudoers file.&nbsp;&nbsp; <br />#&nbsp;&nbsp; <br /># This file MUST be edited with the 'visudo' command as root.&nbsp;&nbsp; <br />#&nbsp;&nbsp; <br /># See the sudoers man page for the details on how to write a sudoers file.&nbsp;&nbsp; <br />#&nbsp;&nbsp; <br /># Host alias specification&nbsp;&nbsp; <br /># User alias specification&nbsp;&nbsp; <br /># Cmnd alias specification&nbsp;&nbsp; <br /># Defaults specification&nbsp;&nbsp; <br /># User privilege specification&nbsp;&nbsp; <br />root&nbsp;&nbsp;&nbsp; ALL=(ALL) ALL&nbsp;&nbsp; <br /># Uncomment to allow people in group wheel to run all commands&nbsp;&nbsp; <br /># %wheel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ALL=(ALL)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ALL&nbsp;&nbsp; <br /># Same thing without a password&nbsp;&nbsp; <br /># %wheel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ALL=(ALL)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NOPASSWD: ALL&nbsp;&nbsp; <br /># Samples&nbsp;&nbsp; <br /># %users&nbsp; ALL=/sbin/mount /cdrom,/sbin/umount /cdrom&nbsp;&nbsp; <br /># %users&nbsp; localhost=/sbin/shutdown -h now&nbsp;&nbsp; <br />##################################################################&nbsp;&nbsp; </p>
<p>1. 最简单的配置，让普通用户support具有root的所有权限 <br />执行visudo之后，可以看见缺省只有一条配置： <br />root&nbsp;&nbsp;&nbsp; ALL=(ALL) ALL <br />那么你就在下边再加一条配置： <br />support ALL=(ALL) ALL <br />这样，普通用户support就能够执行root权限的所有命令 <br />以support用户登录之后，执行： <br />sudo su - <br />然后输入support用户自己的密码，就可以切换成root用户了 <br />2. 让普通用户support只能在某几台服务器上，执行root能执行的某些命令 <br />首先需要配置一些Alias，这样在下面配置权限时，会方便一些，不用写大段大段的配置。Alias主要分成4种 <br />Host_Alias <br />Cmnd_Alias <br />User_Alias <br />Runas_Alias <br />1) 配置Host_Alias：就是主机的列表 <br />Host_Alias&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HOST_FLAG = hostname1, hostname2, hostname3 <br />2) 配置Cmnd_Alias：就是允许执行的命令的列表，命令前加上!表示不能执行此命令. <br />命令一定要使用绝对路径，避免其他目录的同名命令被执行，造成安全隐患 ,因此使用的时候也是使用绝对路径! <br />Cmnd_Alias&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COMMAND_FLAG = command1, command2, command3 ，!command4 <br />3) 配置User_Alias：就是具有sudo权限的用户的列表 <br />User_Alias USER_FLAG = user1, user2, user3 <br />4) 配置Runas_Alias：就是用户以什么身份执行（例如root，或者oracle）的列表 <br />Runas_Alias RUNAS_FLAG = operator1, operator2, operator3 <br />5) 配置权限 <br />配置权限的格式如下： <br />USER_FLAG HOST_FLAG=(RUNAS_FLAG) COMMAND_FLAG <br />如果不需要密码验证的话，则按照这样的格式来配置 <br />USER_FLAG HOST_FLAG=(RUNAS_FLAG) NOPASSWD: COMMAND_FLAG <br />配置示例： <br />Html代码&nbsp; 收藏代码<br />############################################################################&nbsp;&nbsp; <br /># sudoers file.&nbsp;&nbsp; <br />#&nbsp;&nbsp; <br /># This file MUST be edited with the 'visudo' command as root.&nbsp;&nbsp; <br />#&nbsp;&nbsp; <br /># See the sudoers man page for the details on how to write a sudoers file.&nbsp;&nbsp; <br />#&nbsp;&nbsp; <br /># Host alias specification&nbsp;&nbsp; <br />Host_Alias&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EPG = 192.168.1.1, 192.168.1.2&nbsp;&nbsp; <br /># User alias specification&nbsp;&nbsp; <br /># Cmnd alias specification&nbsp;&nbsp; <br />Cmnd_Alias&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SQUID = /opt/vtbin/squid_refresh, !/sbin/service, /bin/rm&nbsp; <br />&nbsp; <br />Cmnd_Alias&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ADMPW = /usr/bin/passwd [A-Za-z]*, !/usr/bin/passwd, !/usr/bin/passwd root&nbsp;&nbsp; <br /># Defaults specification&nbsp;&nbsp; <br /># User privilege specification&nbsp;&nbsp; <br />root&nbsp;&nbsp;&nbsp; ALL=(ALL) ALL&nbsp;&nbsp; <br />support EPG=(ALL) NOPASSWD: SQUID&nbsp;&nbsp; <br />support EPG=(ALL) NOPASSWD: ADMPW&nbsp; <br /># Uncomment to allow people in group wheel to run all commands&nbsp;&nbsp; <br /># %wheel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ALL=(ALL)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ALL&nbsp;&nbsp; <br /># Same thing without a password&nbsp;&nbsp; <br /># %wheel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ALL=(ALL)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NOPASSWD: ALL&nbsp;&nbsp; <br /># Samples&nbsp;&nbsp; <br /># %users&nbsp; ALL=/sbin/mount /cdrom,/sbin/umount /cdrom&nbsp;&nbsp; <br /># %users&nbsp; localhost=/sbin/shutdown -h now&nbsp;&nbsp; <br />###############################################################&nbsp; </p><img src ="http://www.blogjava.net/jjshcc/aggbug/426188.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-07-13 11:54 <a href="http://www.blogjava.net/jjshcc/archive/2015/07/13/426188.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Nginx负载均衡和LVS负载均衡的比较分析</title><link>http://www.blogjava.net/jjshcc/archive/2015/07/01/425977.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Wed, 01 Jul 2015 02:51:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/07/01/425977.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/425977.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/07/01/425977.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/425977.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/425977.html</trackback:ping><description><![CDATA[<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">LVS和Nginx都可以用作多机负载的方案，它们各有优缺，在生产环境中需要好好分析实际情况并加以利用。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　首先提醒，做技术切不可人云亦云，我云即你云；同时也不可太趋向保守，过于相信旧有方式而等别人来帮你做垫被测试。把所有即时听说到的好东西加以钻研，从而提高自己对技术的认知和水平，乃是一个好习惯。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">下面来分析一下两者：</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px"><strong>一、lvs的优势：</strong></p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　1、抗负载能力强，因为lvs工作方式的逻辑是非常之简单，而且工作在网络4层仅做请求分发之用，没有流量，所以在效率上基本不需要太过考虑。在我手里的 lvs，仅仅出过一次问题：在并发最高的一小段时间内均衡器出现丢包现象，据分析为网络问题，即网卡或linux2.4内核的承载能力已到上限，内存和 cpu方面基本无消耗。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　2、配置性低，这通常是一大劣势，但同时也是一大优势，因为没有太多可配置的选项，所以除了增减服务器，并不需要经常去触碰它，大大减少了人为出错的几率。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　3、工作稳定，因为其本身抗负载能力很强，所以稳定性高也是顺理成章，另外各种lvs都有完整的双机热备方案，所以一点不用担心均衡器本身会出什么问题，节点出现故障的话，lvs会自动判别，所以系统整体是非常稳定的。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　4、无流量，上面已经有所提及了。lvs仅仅分发请求，而流量并不从它本身出去，所以可以利用它这点来做一些线路分流之用。没有流量同时也保住了均衡器的IO性能不会受到大流量的影响。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　5、基本上能支持所有应用，因为lvs工作在4层，所以它可以对几乎所有应用做负载均衡，包括http、数据库、聊天室等等。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　另：lvs也不是完全能判别节点故障的，譬如在wlc分配方式下，集群里有一个节点没有配置VIP，会使整个集群不能使用，这时使用wrr分配方式则会丢掉一台机。目前这个问题还在进一步测试中。所以，用lvs也得多多当心为妙。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px"><strong>二、nginx和lvs作对比的结果</strong></p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　1、nginx工作在网络的7层，所以它可以针对http应用本身来做分流策略，比如针对域名、目录结构等，相比之下lvs并不具备这样的功能，所以 nginx单凭这点可利用的场合就远多于lvs了；但nginx有用的这些功能使其可调整度要高于lvs，所以经常要去触碰触碰，由lvs的第2条优点 看，触碰多了，人为出问题的几率也就会大。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　2、nginx对网络的依赖较小，理论上只要ping得通，网页访问正常，nginx就能连得通，nginx同时还能区分内外网，如果是同时拥有内外网的 节点，就相当于单机拥有了备份线路；lvs就比较依赖于网络环境，目前来看服务器在同一网段内并且lvs使用direct方式分流，效果较能得到保证。另 外注意，lvs需要向托管商至少申请多一个ip来做Visual IP，貌似是不能用本身的IP来做VIP的。要做好LVS管理员，确实得跟进学习很多有关网络通信方面的知识，就不再是一个HTTP那么简单了。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　3、nginx安装和配置比较简单，测试起来也很方便，因为它基本能把错误用日志打印出来。lvs的安装和配置、测试就要花比较长的时间了，因为同上所述，lvs对网络依赖比较大，很多时候不能配置成功都是因为网络问题而不是配置问题，出了问题要解决也相应的会麻烦得多。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　4、nginx也同样能承受很高负载且稳定，但负载度和稳定度差lvs还有几个等级：nginx处理所有流量所以受限于机器IO和配置；本身的bug也还是难以避免的；nginx没有现成的双机热备方案，所以跑在单机上还是风险较大，单机上的事情全都很难说。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　5、nginx可以检测到服务器内部的故障，比如根据服务器处理网页返回的状态码、超时等等，并且会把返回错误的请求重新提交到另一个节点。目前lvs中 ldirectd也能支持针对服务器内部的情况来监控，但lvs的原理使其不能重发请求。重发请求这点，譬如用户正在上传一个文件，而处理该上传的节点刚 好在上传过程中出现故障，nginx会把上传切到另一台服务器重新处理，而lvs就直接断掉了，如果是上传一个很大的文件或者很重要的文件的话，用户可能 会因此而恼火。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　6、nginx对请求的异步处理可以帮助节点服务器减轻负载，假如使用Apache直接对外服务，那么出现很多的窄带链接时apache服务器将会占用大 量内存而不能释放，使用多一个nginx做apache代理的话，这些窄带链接会被nginx挡住，apache上就不会堆积过多的请求，这样就减少了相 当多的内存占用。这点使用squid也有相同的作用，即使squid本身配置为不缓存，对apache还是有很大帮助的。lvs没有这些功能，也就无法能 比较。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　7、nginx能支持http和email（email的功能估计比较少人用），lvs所支持的应用在这点上会比nginx更多。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　在使用上，一般最前端所采取的策略应是lvs，也就是DNS的指向应为lvs均衡器，lvs的优点令它非常适合做这个任务。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　重要的ip地址，最好交由lvs托管，比如数据库的ip、webservice服务器的ip等等，这些ip地址随着时间推移，使用面会越来越大，如果更换ip则故障会接踵而至。所以将这些重要ip交给lvs托管是最为稳妥的，这样做的唯一缺点是需要的VIP数量会比较多。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　nginx可作为lvs节点机器使用，一是可以利用nginx的功能，二是可以利用nginx的性能。当然这一层面也可以直接使用squid，squid的功能方面就比nginx弱不少了，性能上也有所逊色于nginx。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　nginx也可作为中层代理使用，这一层面nginx基本上无对手，唯一可以撼动nginx的就只有lighttpd了，不过lighttpd目前还没有 能做到nginx完全的功能，配置也不那么清晰易读。另外，中层代理的IP也是重要的，所以中层代理也拥有一个VIP和lvs是最完美的方案了。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　nginx也可作为网页静态服务器，不过超出了本文讨论的范畴，简单提一下。</p>
<p style="text-align: left; padding-bottom: 5px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/22px 宋体; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">　　具体的应用还得具体分析，如果是比较小的网站（日PV&lt;1000万），用nginx就完全可以了，如果机器也不少，可以用DNS轮询，lvs所耗费的机器还是比较多的；大型网站或者重要的服务，机器不发愁的时候，要多多考虑利用lvs。</p><img src ="http://www.blogjava.net/jjshcc/aggbug/425977.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-07-01 10:51 <a href="http://www.blogjava.net/jjshcc/archive/2015/07/01/425977.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux系统诊断之iostat</title><link>http://www.blogjava.net/jjshcc/archive/2015/06/30/425954.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Tue, 30 Jun 2015 02:13:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/06/30/425954.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/425954.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/06/30/425954.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/425954.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/425954.html</trackback:ping><description><![CDATA[<p>在Linux中常用于判断问题所在的初步定位或性能瓶颈，iostat则给我们提供了丰富的IO状态信息，其他工具还有iotop。</p>
<p><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#108;&#101;&#116;&#111;&#110;&#103;&#64;&#109;&#101;&#58;&#126;&#36;">letong@me:~$</a> sudo iostat<br />Linux 3.13.0-41-generic (me) 2014年12月18日 _x86_64_ (4 CPU)</p>
<p>avg-cpu: %user %nice %system %iowait %steal %idle<br />8.92 0.12 2.27 0.65 0.00 88.05</p>
<p>Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn<br />sda 5.12 85.24 1.97 586069 13512<br />sdb 9.51 43.74 112.81 300771 775678<br />rrqm/s: 每秒进行 merge 的读操作数目。即 delta(rmerge)/s<br />wrqm/s: 每秒进行 merge 的写操作数目。即 delta(wmerge)/s<br />r/s: 每秒完成的读 I/O 设备次数。即 delta(rio)/s<br />w/s: 每秒完成的写 I/O 设备次数。即 delta(wio)/s<br />rsec/s: 每秒读扇区数。即 delta(rsect)/s<br />wsec/s: 每秒写扇区数。即 delta(wsect)/s<br />rkB/s: 每秒读K字节数。是 rsect/s 的一半，因为每扇区大小为512字节。(需要计算)<br />wkB/s: 每秒写K字节数。是 wsect/s 的一半。(需要计算)<br />avgrq-sz: 平均每次设备I/O操作的数据大小 (扇区)。delta(rsect+wsect)/delta(rio+wio)<br />avgqu-sz: 平均I/O队列长度。即 delta(aveq)/s/1000 (因为aveq的单位为毫秒)。<br />await: 平均每次设备I/O操作的等待时间 (毫秒)。即 delta(ruse+wuse)/delta(rio+wio)<br />svctm: 平均每次设备I/O操作的服务时间 (毫秒)。即 delta(use)/delta(rio+wio)<br />%util: 一秒中有百分之多少的时间用于 I/O 操作，或者说一秒中有多少时间 I/O 队列是非空的。即 delta(use)/s/1000 (因为use的单位为毫秒)<br />常用参数：<br />-d 1 #每1秒显示1次<br />-x #显示更详细信息<br />-c #显示cpu相关</p>
<p>常见用法<br />iostat -d -k 1 10 #查看TPS和吞吐量信息<br />iostat -d -x -k 1 10 #查看设备使用率、响应时间<br />iostat -c 1 10 #查看cpu状态</p><img src ="http://www.blogjava.net/jjshcc/aggbug/425954.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-06-30 10:13 <a href="http://www.blogjava.net/jjshcc/archive/2015/06/30/425954.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用GDB生成coredump文件</title><link>http://www.blogjava.net/jjshcc/archive/2015/06/26/425893.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Fri, 26 Jun 2015 02:58:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/06/26/425893.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/425893.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/06/26/425893.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/425893.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/425893.html</trackback:ping><description><![CDATA[<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">如果在测试过程中遇到某个进程的CPU利用率过高或者卡死而需要去调试该进程时，可以利用gdb命令生成coredump文件，然后再去调试coredump文件来定位问题。</p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">那么如何使用gdb生成coredump文件呢？其实步骤很简单：</p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><br /></p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">1. 安装好gdb，然后使用命令 'gdb'。（假设需要调试的进程号为 21509）</p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">2. 使用 &#8216;attach 21590&#8217;命令将gdb附加到进程21509上。</p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">3. 使用&#8216;gcore core_name&#8217;命令生成coredump文件core_name。</p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">4. 使用&#8216;detach&#8217;命令断开连接。</p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">5.使用&#8216;q&#8217;命令退出gdb。</p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px"><br /></p>
<p style="text-align: left; padding-bottom: 0px; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Arial; white-space: normal; color: rgb(0,0,0); word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">此时，在当前目录下就会产生一个名为core_name的coredump文件。下面就可以利用gdb工具来对该coredump文件进行调试了。</p><img src ="http://www.blogjava.net/jjshcc/aggbug/425893.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-06-26 10:58 <a href="http://www.blogjava.net/jjshcc/archive/2015/06/26/425893.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux修改程序运行优先级命令</title><link>http://www.blogjava.net/jjshcc/archive/2015/06/19/425805.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Fri, 19 Jun 2015 09:20:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/06/19/425805.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/425805.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/06/19/425805.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/425805.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/425805.html</trackback:ping><description><![CDATA[<div>linux renice 命令详解&nbsp;</div><div>　　功能说明：调整程序优先级。&nbsp;</div><div>　　语　　法：renice [优先等级][-g &lt;程序群组名称&gt;...][-p &lt;程序识别码&gt;...][-u &lt;用户名称&gt;...]&nbsp;</div><div>　　补充说明：renice指令可重新调整程序执行的优先权等级。预设是以程序识别码指定程序调整其优先权，您亦可以指定程序群组或用户名称调整优先权等级，并修改所有隶属于该程序群组或用户的程序的优先权。等级范围从-20--19，只有系统管理者可以改变其他用户程序的优先权，也仅有系统管理者可以设置负数等级。&nbsp;</div><div>　　参　　数：&nbsp;</div><div>　　-g &lt;程序群组名称&gt; 　使用程序群组名称，修改所有隶属于该程序群组的程序的优先权。&nbsp;</div><div>　　-p &lt;程序识别码&gt; 　改变该程序的优先权等级，此参数为预设值。&nbsp;</div><div>　　-u &lt;用户名称&gt; 　指定用户名称，修改所有隶属于该用户的程序的优先权。&nbsp;</div><div>&nbsp;</div><div>一开始执行程式就立即给予一个特定的 nice 值：用 nice 命令；&nbsp;</div><div>调整某个已经存在的 PID 的 nice 值：用 renice 命令。&nbsp;</div><div>推荐阅读一：linux进程cpu资源分配命令nice,renice,taskset&nbsp;</div><div>进程cpu资源分配就是指进程的优先权（priority）。优先权高的进程有优先执行权利。配置进程优先权对多任务环境的linux很有用，可以改善系统性能。还可以把进程运行到指定的CPU上，这样一来，把不重要的进程安排到某个CPU，可以大大改善系统整体性能。&nbsp;</div><div>一、先看系统进程：&nbsp;</div><div>PR 就是 Priority 的简写，而 NI 是 nice 的简写。这两个值决定了PR的值，PR越小，进程优先权就越高，就越&#8220;优先执行&#8221;。换算公式为：PR(new) = PR(old) + NI&nbsp;</div><div>---------------------------------------------------------------------------&nbsp;</div><div>二、修改进程优先级的命令主要有两个：nice,renice&nbsp;</div><div>1、一开始执行程序就指定nice值：nice&nbsp;</div><div></div><div>nice -n -5 /usr/local/mysql/bin/mysqld_safe &amp;&nbsp;</div><div></div><div>linux nice 命令详解&nbsp;</div><div>　　功能说明：设置优先权。&nbsp;</div><div>　　语　　法：nice [-n &lt;优先等级&gt;][--help][--version][执行指令]&nbsp;</div><div>　　补充说明：nice指令可以改变程序执行的优先权等级。&nbsp;</div><div>　　参　　数：-n&lt;优先等级&gt;或-&lt;优先等级&gt;或--adjustment=&lt;优先等级&gt; 　设置欲执行的指令的优先权等级。等级的范围从-20-19，其中-20最高，19最低，只有系统管理者可以设置负数的等级。&nbsp;</div><div>　　 --help 　在线帮助。&nbsp;</div><div>　 　--version 　显示版本信息。&nbsp;</div><div>---------------------------------------------------------------------------&nbsp;</div><div>2.1、调整已存在进程的nice：renice&nbsp;</div><div></div><div></div><div>renice -5 -p 5200&nbsp;</div><div>#PID为5200的进程nice设为-5&nbsp;</div><div></div><div>linux renice 命令详解&nbsp;</div><div>　　功能说明：调整优先权。&nbsp;</div><div>　　语　　法：renice [优先等级][-g &lt;程序群组名称&gt;...][-p &lt;程序识别码&gt;...][-u &lt;用户名称&gt;...]&nbsp;</div><div>　　补充说明：renice指令可重新调整程序执行的优先权等级。预设是以程序识别码指定程序调整其优先权，您亦可以指定程序群组或用户名称调整优先权等级，并修改所有隶属于该程序群组或用户的程序的优先权。等级范围从-20--19，只有系统管理者可以改变其他用户程序的优先权，也仅有系统管理者可以设置负数等级。&nbsp;</div><div>　　参　　数：&nbsp;</div><div>　　-g &lt;程序群组名称&gt; 　使用程序群组名称，修改所有隶属于该程序群组的程序的优先权。&nbsp;</div><div>　　-p &lt;程序识别码&gt; 　改变该程序的优先权等级，此参数为预设值。&nbsp;</div><div>　　-u &lt;用户名称&gt; 　指定用户名称，修改所有隶属于该用户的程序的优先权。&nbsp;</div><img src ="http://www.blogjava.net/jjshcc/aggbug/425805.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-06-19 17:20 <a href="http://www.blogjava.net/jjshcc/archive/2015/06/19/425805.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux awk命令详解</title><link>http://www.blogjava.net/jjshcc/archive/2015/06/11/425642.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Thu, 11 Jun 2015 14:29:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/06/11/425642.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/425642.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/06/11/425642.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/425642.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/425642.html</trackback:ping><description><![CDATA[<h2><strong><span style="line-height: 1.5; font-size: 18px;">简介</span></strong></h2><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><span style="line-height: 1.5;">awk是一个强大的文本分析工具，相对于grep的查找，sed的编辑，awk在其对数据分析并生成报告时，显得尤为强大。<span style="line-height: 1.5;">简单来说awk就是把文件逐行的读入，以空格为默认分隔符将每行切片，切开的部分再进行各种分析处理。</span></span></p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><span style="line-height: 1.5;"><span style="line-height: 1.5;">awk有3个不同版本: awk、nawk和gawk，未作特别说明，一般指gawk，<span style="line-height: 1.5;">gawk 是 AWK 的 GNU 版本。</span></span></span></p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">awk其名称得自于它的创始人 Alfred Aho 、Peter Weinberger 和 Brian Kernighan 姓氏的首个字母。实际上 AWK 的确拥有自己的语言： AWK 程序设计语言 ， 三位创建者已将它正式定义为&#8220;样式扫描和处理语言&#8221;。它允许您创建简短的程序，这些程序读取输入文件、为数据排序、处理数据、对输入执行计算以及生成报表，还有无数其他的功能。</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><h2><strong><span style="line-height: 1.5; font-size: 14pt;">使用方法</span></strong></h2><div style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="color: #0000ff; line-height: 1.5 !important;">awk</span> <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">{pattern + action}</span><span style="color: #800000; line-height: 1.5 !important;">'</span> {filenames}</pre></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><span style="line-height: 1.5;">尽管操作可能会很复杂，但语法总是这样，<span style="line-height: 1.5;">其中 pattern 表示 AWK 在数据中查找的内容，而 action 是在找到匹配内容时所执行的一系列命令。花括号（{}）不需要在程序中始终出现，但它们用于根据特定的模式对一系列指令进行分组。 pattern就是要表示的正则表达式，用斜杠括起来。</span></span></p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">awk语言的最基本功能是在文件或者字符串中基于指定规则浏览和抽取信息，awk抽取信息后，才能进行其他文本操作。完整的awk脚本通常用来格式化文本文件中的信息。</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">通常，awk是以文件的一行为处理单位的。awk每接收文件的一行，然后执行相应的命令，来处理文本。</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><h2><strong><span style="line-height: 1.5; font-size: 14pt;">调用awk</span></strong></h2><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><span style="line-height: 1.5;">有三种方式调用awk</span></p><div style="margin: 5px 0px; font-size: 12px !important;"><div style="margin-top: 5px;"><span style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: navy; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border: none !important;" /></a></span></div><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="color: #800080; line-height: 1.5 !important;">1</span><span style="line-height: 1.5 !important;">.命令行方式 </span><span style="color: #0000ff; line-height: 1.5 !important;">awk</span> [-F  field-separator]  <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">commands</span><span style="color: #800000; line-height: 1.5 !important;">'</span>  input-<span style="color: #0000ff; line-height: 1.5 !important;">file</span><span style="line-height: 1.5 !important;">(s) 其中，commands 是真正awk命令，[</span>-F域分隔符]是可选的。 input-<span style="color: #0000ff; line-height: 1.5 !important;">file</span><span style="line-height: 1.5 !important;">(s) 是待处理的文件。 在awk中，文件的每一行中，由域分隔符分开的每一项称为一个域。通常，在不指名</span>-<span style="line-height: 1.5 !important;">F域分隔符的情况下，默认的域分隔符是空格。  </span><span style="color: #800080; line-height: 1.5 !important;">2</span><span style="line-height: 1.5 !important;">.shell脚本方式 将所有的awk命令插入一个文件，并使awk程序可执行，然后awk命令解释器作为脚本的首行，一遍通过键入脚本名称来调用。 相当于shell脚本首行的：#</span>!/bin/<span style="color: #0000ff; line-height: 1.5 !important;">sh</span><span style="line-height: 1.5 !important;"> 可以换成：#</span>!/bin/<span style="color: #0000ff; line-height: 1.5 !important;">awk</span>  <span style="color: #800080; line-height: 1.5 !important;">3</span><span style="line-height: 1.5 !important;">.将所有的awk命令插入一个单独文件，然后调用： </span><span style="color: #0000ff; line-height: 1.5 !important;">awk</span> -f <span style="color: #0000ff; line-height: 1.5 !important;">awk</span>-script-<span style="color: #0000ff; line-height: 1.5 !important;">file</span> input-<span style="color: #0000ff; line-height: 1.5 !important;">file</span><span style="line-height: 1.5 !important;">(s) 其中，</span>-f选项加载awk-script-file中的awk脚本，input-<span style="color: #0000ff; line-height: 1.5 !important;">file</span>(s)跟上面的是一样的。</pre><div style="margin-top: 5px;"><span style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: navy; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border: none !important;" /></a></span></div></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;本章重点介绍命令行方式。</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><h2><strong><span style="line-height: 1.5; font-size: 14pt;">入门实例</span></strong></h2><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">假设last -n 5的输出如下</p><div style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;">[root@www ~]# <span style="color: #0000ff; line-height: 1.5 !important;">last</span> -n <span style="color: #800080; line-height: 1.5 !important;">5</span> &lt;==<span style="line-height: 1.5 !important;">仅取出前五行 root     pts</span>/<span style="color: #800080; line-height: 1.5 !important;">1</span>   <span style="color: #800080; line-height: 1.5 !important;">192.168</span>.<span style="color: #800080; line-height: 1.5 !important;">1.100</span>  Tue Feb <span style="color: #800080; line-height: 1.5 !important;">10</span> <span style="color: #800080; line-height: 1.5 !important;">11</span>:<span style="color: #800080; line-height: 1.5 !important;">21</span>   still logged <span style="color: #0000ff; line-height: 1.5 !important;">in</span><span style="line-height: 1.5 !important;"> root     pts</span>/<span style="color: #800080; line-height: 1.5 !important;">1</span>   <span style="color: #800080; line-height: 1.5 !important;">192.168</span>.<span style="color: #800080; line-height: 1.5 !important;">1.100</span>  Tue Feb <span style="color: #800080; line-height: 1.5 !important;">10</span> <span style="color: #800080; line-height: 1.5 !important;">00</span>:<span style="color: #800080; line-height: 1.5 !important;">46</span> - <span style="color: #800080; line-height: 1.5 !important;">02</span>:<span style="color: #800080; line-height: 1.5 !important;">28</span>  (<span style="color: #800080; line-height: 1.5 !important;">01</span>:<span style="color: #800080; line-height: 1.5 !important;">41</span><span style="line-height: 1.5 !important;">) root     pts</span>/<span style="color: #800080; line-height: 1.5 !important;">1</span>   <span style="color: #800080; line-height: 1.5 !important;">192.168</span>.<span style="color: #800080; line-height: 1.5 !important;">1.100</span>  Mon Feb  <span style="color: #800080; line-height: 1.5 !important;">9</span> <span style="color: #800080; line-height: 1.5 !important;">11</span>:<span style="color: #800080; line-height: 1.5 !important;">41</span> - <span style="color: #800080; line-height: 1.5 !important;">18</span>:<span style="color: #800080; line-height: 1.5 !important;">30</span>  (<span style="color: #800080; line-height: 1.5 !important;">06</span>:<span style="color: #800080; line-height: 1.5 !important;">48</span><span style="line-height: 1.5 !important;">) dmtsai   pts</span>/<span style="color: #800080; line-height: 1.5 !important;">1</span>   <span style="color: #800080; line-height: 1.5 !important;">192.168</span>.<span style="color: #800080; line-height: 1.5 !important;">1.100</span>  Mon Feb  <span style="color: #800080; line-height: 1.5 !important;">9</span> <span style="color: #800080; line-height: 1.5 !important;">11</span>:<span style="color: #800080; line-height: 1.5 !important;">41</span> - <span style="color: #800080; line-height: 1.5 !important;">11</span>:<span style="color: #800080; line-height: 1.5 !important;">41</span>  (<span style="color: #800080; line-height: 1.5 !important;">00</span>:<span style="color: #800080; line-height: 1.5 !important;">00</span><span style="line-height: 1.5 !important;">) root     tty1                   Fri Sep  </span><span style="color: #800080; line-height: 1.5 !important;">5</span> <span style="color: #800080; line-height: 1.5 !important;">14</span>:<span style="color: #800080; line-height: 1.5 !important;">09</span> - <span style="color: #800080; line-height: 1.5 !important;">14</span>:<span style="color: #800080; line-height: 1.5 !important;">10</span>  (<span style="color: #800080; line-height: 1.5 !important;">00</span>:<span style="color: #800080; line-height: 1.5 !important;">01</span>)</pre></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">如果只是显示最近登录的5个帐号</p><div style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="color: #0000ff; line-height: 1.5 !important;">#last</span> -n <span style="color: #800080; line-height: 1.5 !important;">5</span> | <span style="color: #0000ff; line-height: 1.5 !important;">awk</span>  <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">{print $1}</span><span style="color: #800000; line-height: 1.5 !important;">'<br />root<br />root<br />root<br />dmtsai<br />root</span></pre></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><span style="line-height: 1.5;">awk工作流程是这样的：读入有'\n'换行符分割的一条记录，然后将记录按指定的域分隔符划分域，填充域，<span style="line-height: 1.5;">$0则表示所有域,$1表示第一个域,$n表示第n个域。</span>默认域分隔符是"空白键" 或 "[tab]键",所以$1表示登录用户，$3表示登录用户ip,以此类推。</span></p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><span style="line-height: 1.5;">如果只是显示/etc/passwd的账户</span></p><div style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;">#<span style="color: #0000ff; line-height: 1.5 !important;">cat</span> /etc/<span style="color: #0000ff; line-height: 1.5 !important;">passwd</span> |<span style="color: #0000ff; line-height: 1.5 !important;">awk</span>  -F <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">:</span><span style="color: #800000; line-height: 1.5 !important;">'</span>  <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">{print $1}</span><span style="color: #800000; line-height: 1.5 !important;">'</span><span style="line-height: 1.5 !important;">   root daemon bin sys</span></pre></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">这种是awk+action的示例，每行都会执行action{print $1}。</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">-F指定域分隔符为':'。</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">如果只是显示/etc/passwd的账户和账户对应的shell,而账户与shell之间以tab键分割</p><div style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;">#<span style="color: #0000ff; line-height: 1.5 !important;">cat</span> /etc/<span style="color: #0000ff; line-height: 1.5 !important;">passwd</span> |<span style="color: #0000ff; line-height: 1.5 !important;">awk</span>  -F <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">:</span><span style="color: #800000; line-height: 1.5 !important;">'</span>  <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">{print $1"\t"$7}</span><span style="color: #800000; line-height: 1.5 !important;">'</span><span style="line-height: 1.5 !important;"> root    </span>/bin/<span style="line-height: 1.5 !important;">bash daemon  </span>/bin/<span style="color: #0000ff; line-height: 1.5 !important;">sh</span><span style="line-height: 1.5 !important;"> bin     </span>/bin/<span style="color: #0000ff; line-height: 1.5 !important;">sh</span><span style="line-height: 1.5 !important;"> sys     </span>/bin/<span style="color: #0000ff; line-height: 1.5 !important;">sh</span></pre></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">如果只是显示/etc/passwd的账户和账户对应的shell,而账户与shell之间以逗号分割,而且在所有行添加列名name,shell,在最后一行添加"blue,/bin/nosh"。</p><div style="margin: 5px 0px; font-size: 12px !important;"><div style="margin-top: 5px;"><span style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: navy; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border: none !important;" /></a></span></div><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="color: #0000ff; line-height: 1.5 !important;">cat</span> /etc/<span style="color: #0000ff; line-height: 1.5 !important;">passwd</span> |<span style="color: #0000ff; line-height: 1.5 !important;">awk</span>  -F <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">:</span><span style="color: #800000; line-height: 1.5 !important;">'</span>  <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">BEGIN {print "name,shell"}  {print $1","$7} END {print "blue,/bin/nosh"}</span><span style="color: #800000; line-height: 1.5 !important;">'</span><span style="line-height: 1.5 !important;"> name,shell root,</span>/bin/<span style="line-height: 1.5 !important;">bash daemon,</span>/bin/<span style="color: #0000ff; line-height: 1.5 !important;">sh</span><span style="line-height: 1.5 !important;"> bin,</span>/bin/<span style="color: #0000ff; line-height: 1.5 !important;">sh</span><span style="line-height: 1.5 !important;"> sys,</span>/bin/<span style="color: #0000ff; line-height: 1.5 !important;">sh</span><span style="line-height: 1.5 !important;"> .... blue,</span>/bin/nosh</pre><div style="margin-top: 5px;"><span style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: navy; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border: none !important;" /></a></span></div></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><span style="line-height: 1.5;">awk工作流程是这样的：先执行BEGING，然后读取文件，读入有/n换行符分割的一条记录，然后将记录按指定的域分隔符划分域，填充域，<span style="line-height: 1.5;">$0则表示所有域,$1表示第一个域,$n表示第n个域</span>,随后开始执行模式所对应的动作action。接着开始读入第二条记录&#183;&#183;&#183;&#183;&#183;&#183;直到所有的记录都读完，最后执行END操作。</span></p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">搜索/etc/passwd有root关键字的所有行</p><div style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;">#<span style="color: #0000ff; line-height: 1.5 !important;">awk</span> -F: <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">/root/</span><span style="color: #800000; line-height: 1.5 !important;">'</span> /etc/<span style="color: #0000ff; line-height: 1.5 !important;">passwd</span><span style="line-height: 1.5 !important;"> root:x:</span><span style="color: #800080; line-height: 1.5 !important;">0</span>:<span style="color: #800080; line-height: 1.5 !important;">0</span>:root:/root:/bin/bash</pre></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">这种是pattern的使用示例，匹配了pattern(这里是root)的行才会执行action(没有指定action，默认输出每行的内容)。</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">搜索支持正则，例如找root开头的:&nbsp;awk -F: '/^root/' /etc/passwd</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">搜索/etc/passwd有root关键字的所有行，并显示对应的shell</p><div style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"># <span style="color: #0000ff; line-height: 1.5 !important;">awk</span> -F: <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">/root/{print $7}</span><span style="color: #800000; line-height: 1.5 !important;">'</span> /etc/<span style="color: #0000ff; line-height: 1.5 !important;">passwd</span>              /bin/bash</pre></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;这里指定了action{print $7}</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><h2><strong><span style="line-height: 1.5; font-size: 14pt;">awk内置变量</span></strong></h2><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><span style="line-height: 1.5;">awk有许多内置变量用来设置环境信息，这些变量可以被改变，下面给出了最常用的一些变量。</span></p><div style="margin: 5px 0px; font-size: 12px !important;"><div style="margin-top: 5px;"><span style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: navy; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border: none !important;" /></a></span></div><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="line-height: 1.5 !important;">ARGC               命令行参数个数 ARGV               命令行参数排列 ENVIRON            支持队列中系统环境变量的使用 FILENAME           awk浏览的文件名 FNR                浏览文件的记录数 FS                 设置输入域分隔符，等价于命令行 </span>-<span style="line-height: 1.5 !important;">F选项 NF                 浏览记录的域的个数 NR                 已读的记录数 OFS                输出域分隔符 ORS                输出记录分隔符 RS                 控制记录分隔符</span></pre><div style="margin-top: 5px;"><span style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: navy; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border: none !important;" /></a></span></div></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;此外,<span style="line-height: 1.5;">$0变量是指整条记录。$1表示当前行的第一个域,$2表示当前行的第二个域,......以此类推。</span></p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">统计/etc/passwd:文件名，每行的行号，每行的列数，对应的完整行内容:</p><div style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="color: #0000ff; line-height: 1.5 !important;">#awk</span>  -F <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">:</span><span style="color: #800000; line-height: 1.5 !important;">'</span>  <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">{print "filename:" FILENAME ",linenumber:" NR ",columns:" NF ",linecontent:"$0}</span><span style="color: #800000; line-height: 1.5 !important;">'</span> /etc/<span style="color: #0000ff; line-height: 1.5 !important;">passwd</span><span style="line-height: 1.5 !important;"> filename:</span>/etc/<span style="color: #0000ff; line-height: 1.5 !important;">passwd</span>,linenumber:<span style="color: #800080; line-height: 1.5 !important;">1</span>,columns:<span style="color: #800080; line-height: 1.5 !important;">7</span>,linecontent:root:x:<span style="color: #800080; line-height: 1.5 !important;">0</span>:<span style="color: #800080; line-height: 1.5 !important;">0</span>:root:/root:/bin/<span style="line-height: 1.5 !important;">bash filename:</span>/etc/<span style="color: #0000ff; line-height: 1.5 !important;">passwd</span>,linenumber:<span style="color: #800080; line-height: 1.5 !important;">2</span>,columns:<span style="color: #800080; line-height: 1.5 !important;">7</span>,linecontent:daemon:x:<span style="color: #800080; line-height: 1.5 !important;">1</span>:<span style="color: #800080; line-height: 1.5 !important;">1</span>:daemon:/usr/sbin:/bin/<span style="color: #0000ff; line-height: 1.5 !important;">sh</span><span style="line-height: 1.5 !important;"> filename:</span>/etc/<span style="color: #0000ff; line-height: 1.5 !important;">passwd</span>,linenumber:<span style="color: #800080; line-height: 1.5 !important;">3</span>,columns:<span style="color: #800080; line-height: 1.5 !important;">7</span>,linecontent:bin:x:<span style="color: #800080; line-height: 1.5 !important;">2</span>:<span style="color: #800080; line-height: 1.5 !important;">2</span>:bin:/bin:/bin/<span style="color: #0000ff; line-height: 1.5 !important;">sh</span><span style="line-height: 1.5 !important;"> filename:</span>/etc/<span style="color: #0000ff; line-height: 1.5 !important;">passwd</span>,linenumber:<span style="color: #800080; line-height: 1.5 !important;">4</span>,columns:<span style="color: #800080; line-height: 1.5 !important;">7</span>,linecontent:sys:x:<span style="color: #800080; line-height: 1.5 !important;">3</span>:<span style="color: #800080; line-height: 1.5 !important;">3</span>:sys:/dev:/bin/<span style="color: #0000ff; line-height: 1.5 !important;">sh</span></pre></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">使用printf替代print,可以让代码更加简洁，易读</p><div style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"> <span style="color: #0000ff; line-height: 1.5 !important;">awk</span>  -F <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">:</span><span style="color: #800000; line-height: 1.5 !important;">'</span>  <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">{printf("filename:%10s,linenumber:%s,columns:%s,linecontent:%s\n",FILENAME,NR,NF,$0)}</span><span style="color: #800000; line-height: 1.5 !important;">'</span> /etc/<span style="color: #0000ff; line-height: 1.5 !important;">passwd</span></pre></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><h2><strong><span style="line-height: 1.5; font-size: 14pt;">print和printf</span></strong></h2><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><span style="line-height: 1.5;">awk中同时提供了print和printf两种打印输出的函数。</span></p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><span style="line-height: 1.5;">其中print函数的参数可以是变量、数值或者字符串。字符串必须用双引号引用，参数用逗号分隔。如果没有逗号，参数就串联在一起而无法区分。这里，逗号的作用与输出文件的分隔符的作用是一样的，只是后者是空格而已。</span></p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><span style="line-height: 1.5;">printf函数，其用法和c语言中printf基本相似,可以格式化字符串,输出复杂时，printf更加好用，代码更易懂。</span></p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><h2><strong><span style="line-height: 1.5; font-size: 14pt;">&nbsp;awk编程</span></strong></h2><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><strong>&nbsp;变量和赋值</strong></p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">除了awk的内置变量，awk还可以自定义变量。</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">下面统计/etc/passwd的账户人数</p><div style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="color: #0000ff; line-height: 1.5 !important;">awk</span> <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">{count++;print $0;} END{print "user count is ", count}</span><span style="color: #800000; line-height: 1.5 !important;">'</span> /etc/<span style="color: #0000ff; line-height: 1.5 !important;">passwd</span><span style="line-height: 1.5 !important;"> root:x:</span><span style="color: #800080; line-height: 1.5 !important;">0</span>:<span style="color: #800080; line-height: 1.5 !important;">0</span>:root:/root:/bin/<span style="line-height: 1.5 !important;">bash ...... user count is &nbsp;40<br /></span></pre></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">count是自定义变量。之前的action{}里都是只有一个print,其实print只是一个语句，而action{}可以有多个语句，以;号隔开。</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">这里没有初始化count，虽然默认是0，但是妥当的做法还是初始化为0:</p><div style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="color: #0000ff; line-height: 1.5 !important;">awk</span> <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">BEGIN {count=0;print "[start]user count is ", count} {count=count+1;print $0;} END{print "[end]user count is ", count}</span><span style="color: #800000; line-height: 1.5 !important;">'</span> /etc/<span style="color: #0000ff; line-height: 1.5 !important;">passwd</span><span style="line-height: 1.5 !important;"> [start]user count is  </span><span style="color: #800080; line-height: 1.5 !important;">0</span><span style="line-height: 1.5 !important;"> root:x:</span><span style="color: #800080; line-height: 1.5 !important;">0</span>:<span style="color: #800080; line-height: 1.5 !important;">0</span>:root:/root:/bin/<span style="line-height: 1.5 !important;">bash ... [end]user count is  </span><span style="color: #800080; line-height: 1.5 !important;">40</span></pre></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">统计某个文件夹下的文件占用的字节数</p><div style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="color: #0000ff; line-height: 1.5 !important;">ls</span> -l |<span style="color: #0000ff; line-height: 1.5 !important;">awk</span> <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">BEGIN {size=0;} {size=size+$5;} END{print "[end]size is ", size}</span><span style="color: #800000; line-height: 1.5 !important;">'<br />[end]size is &nbsp;8657198<br /></span></pre></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">如果以M为单位显示:</p><div style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="color: #0000ff; line-height: 1.5 !important;">ls</span> -l |<span style="color: #0000ff; line-height: 1.5 !important;">awk</span> <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">BEGIN {size=0;} {size=size+$5;} END{print "[end]size is ", size/1024/1024,"M"}</span><span style="color: #800000; line-height: 1.5 !important;">'</span> <br />[end]size is &nbsp;8.25889 M</pre></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">注意，统计不包括文件夹的子目录。</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><strong>条件语句</strong></p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><span style="line-height: 1.5;">&nbsp;awk中的条件语句是从C语言中借鉴来的，见如下声明方式：</span></p><div style="margin: 5px 0px; font-size: 12px !important;"><div style="margin-top: 5px;"><span style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: navy; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border: none !important;" /></a></span></div><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="color: #0000ff; line-height: 1.5 !important;">if</span><span style="line-height: 1.5 !important;"> (expression) {     statement;     statement;     ... ... }  </span><span style="color: #0000ff; line-height: 1.5 !important;">if</span><span style="line-height: 1.5 !important;"> (expression) {     statement; } </span><span style="color: #0000ff; line-height: 1.5 !important;">else</span><span style="line-height: 1.5 !important;"> {     statement2; }  </span><span style="color: #0000ff; line-height: 1.5 !important;">if</span><span style="line-height: 1.5 !important;"> (expression) {     statement1; } </span><span style="color: #0000ff; line-height: 1.5 !important;">else</span> <span style="color: #0000ff; line-height: 1.5 !important;">if</span><span style="line-height: 1.5 !important;"> (expression1) {     statement2; } </span><span style="color: #0000ff; line-height: 1.5 !important;">else</span><span style="line-height: 1.5 !important;"> {     statement3; }</span></pre><div style="margin-top: 5px;"><span style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: navy; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border: none !important;" /></a></span></div></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">统计某个文件夹下的文件占用的字节数,过滤4096大小的文件(一般都是文件夹):</p><div style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="color: #0000ff; line-height: 1.5 !important;">ls</span> -l |<span style="color: #0000ff; line-height: 1.5 !important;">awk</span> <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">BEGIN {size=0;print "[start]size is ", size} {if($5!=4096){size=size+$5;}} END{print "[end]size is ", size/1024/1024,"M"}</span><span style="color: #800000; line-height: 1.5 !important;">'</span> <br />[end]size is &nbsp;8.22339 M</pre></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><strong>循环语句</strong></p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">awk中的循环语句同样借鉴于C语言，支持while、do/while、for、break、continue，这些关键字的语义和C语言中的语义完全相同。</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><strong>数组</strong></p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><span style="line-height: 1.5;">&nbsp; 因为awk中数组的下标可以是数字和字母，数组的下标通常被称为关键字(key)。值和关键字都存储在内部的一张针对key/value应用hash的表格里。由于hash不是顺序存储，因此在显示数组内容时会发现，它们并不是按照你预料的顺序显示出来的。数组和变量一样，都是在使用时自动创建的，awk也同样会自动判断其存储的是数字还是字符串。一般而言，awk中的数组用来从记录中收集信息，可以用于计算总和、统计单词以及跟踪模板被匹配的次数等等。</span></p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;"><span style="line-height: 1.5;">显示/etc/passwd的账户</span></p><div style="margin: 5px 0px; font-size: 12px !important;"><div style="margin-top: 5px;"><span style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: navy; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border: none !important;" /></a></span></div><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="color: #0000ff; line-height: 1.5 !important;">awk</span> -F <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">:</span><span style="color: #800000; line-height: 1.5 !important;">'</span> <span style="color: #800000; line-height: 1.5 !important;">'</span><span style="color: #800000; line-height: 1.5 !important;">BEGIN {count=0;} {name[count] = $1;count++;}; END{for (i = 0; i &lt; NR; i++) print i, name[i]}</span><span style="color: #800000; line-height: 1.5 !important;">'</span> /etc/<span style="color: #0000ff; line-height: 1.5 !important;">passwd</span> <span style="color: #800080; line-height: 1.5 !important;">0</span><span style="line-height: 1.5 !important;"> root </span><span style="color: #800080; line-height: 1.5 !important;">1</span><span style="line-height: 1.5 !important;"> daemon </span><span style="color: #800080; line-height: 1.5 !important;">2</span><span style="line-height: 1.5 !important;"> bin </span><span style="color: #800080; line-height: 1.5 !important;">3</span><span style="line-height: 1.5 !important;"> sys </span><span style="color: #800080; line-height: 1.5 !important;">4</span> <span style="color: #0000ff; line-height: 1.5 !important;">sync</span> <span style="color: #800080; line-height: 1.5 !important;">5</span><span style="line-height: 1.5 !important;"> games ......</span></pre><div style="margin-top: 5px;"><span style="padding-right: 5px; line-height: 1.5 !important;"><a title="复制代码" style="color: navy; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border: none !important;" /></a></span></div></div><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">这里使用for循环遍历数组</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="font-size: 13px; line-height: 19.5px; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff;">awk编程的内容极多，这里只罗列简单常用的用法，更多请参考&nbsp;<a href="http://www.gnu.org/software/gawk/manual/gawk.html" style="color: navy; text-decoration: none;">http://www.gnu.org/software/gawk/manual/gawk.html</a></p><img src ="http://www.blogjava.net/jjshcc/aggbug/425642.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-06-11 22:29 <a href="http://www.blogjava.net/jjshcc/archive/2015/06/11/425642.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux tee 命令详解</title><link>http://www.blogjava.net/jjshcc/archive/2015/06/11/425617.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Thu, 11 Jun 2015 03:43:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/06/11/425617.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/425617.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/06/11/425617.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/425617.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/425617.html</trackback:ping><description><![CDATA[<strong style="padding: 0px; margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;">linux tee 命令详解<br style="padding: 0px; margin: 0px;" />
</strong><span style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;">功能说明：读取标准输入的数据，并将其内容输出成文件。</span><br style="padding: 0px; margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;" />
<span style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;">语法：tee [-ai][--help][--version][文件...]</span><br style="padding: 0px; margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;" />
<span style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;">补充说明：tee指令会从标准输入设备读取数据，将其内容输出到标准输出设备，同时保存成文件。</span><br style="padding: 0px; margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;" />
<span style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;">参数：</span><br style="padding: 0px; margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;" />
<span style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;">　-a或--append 　附加到既有文件的后面，而非覆盖它．</span><br style="padding: 0px; margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;" />
<span style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;">　-i-i或--ignore-interrupts 　忽略中断信号。</span><br style="padding: 0px; margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;" />
<span style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;">　--help 　在线帮助。</span><br style="padding: 0px; margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;" />
<span style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;">　--version 　显示版本信息。<br />
<br />
</span><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">&nbsp;</p><h2 style="line-height: 1.5em; margin: 0px 0px 0.5em; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; widows: auto; background-color: #ffffff;">用途说明</h2><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">在执行Linux命令时，我们可以把输出重定向到文件中，比如 ls &gt;a.txt，这时我们就不能看到输出了，如果我们既想把输出保存到文件中，又想在屏幕上看到输出内容，就可以使用tee命令了。tee命令读取标准输入，把这些内容同时输出到标准输出和（多个）文件中（read from standard input and write to standard output and files. Copy standard input to each FILE, and also to standard output. If a FILE is -, copy again to standard output.）。在info tee中说道：tee命令可以重定向标准输出到多个文件（`tee': Redirect output to multiple files. The `tee' command copies standard input to standard output and also to any files given as arguments.&nbsp; This is useful when you want not only to send some data down a pipe, but also to save a copy.）。要注意的是：在使用管道线时，前一个命令的标准错误输出不会被tee读取。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">&nbsp;</p><h2 style="line-height: 1.5em; margin: 0px 0px 0.5em; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; widows: auto; background-color: #ffffff;">常用参数</h2><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">格式：tee</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">只输出到标准输出，因为没有指定文件嘛。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">格式：tee file</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">输出到标准输出的同时，保存到文件file中。如果文件不存在，则创建；如果已经存在，则覆盖之。（If a file being written to does not already exist, it is created. If a file being written to already exists, the data it previously<br />contained is overwritten unless the `-a' option is used.）</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">格式：tee -a file</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">输出到标准输出的同时，追加到文件file中。如果文件不存在，则创建；如果已经存在，就在末尾追加内容，而不是覆盖。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">格式：tee -</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">输出到标准输出两次。（A FILE of `-' causes `tee' to send another copy of input to standard output, but this is typically not that useful as the copies are interleaved.）</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">格式：tee file1 file2 -</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; widows: auto; background-color: #ffffff;">输出到标准输出两次，同时保存到file1和file2中。</p><span style="color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; widows: auto; background-color: #ffffff;"><br />
</span><img src ="http://www.blogjava.net/jjshcc/aggbug/425617.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-06-11 11:43 <a href="http://www.blogjava.net/jjshcc/archive/2015/06/11/425617.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Perl IDE之Perl Express和Eclipse+EPIC+PadWalker</title><link>http://www.blogjava.net/jjshcc/archive/2015/06/10/425601.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Wed, 10 Jun 2015 07:01:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/06/10/425601.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/425601.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/06/10/425601.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/425601.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/425601.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">一 初级</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">1）Notepad++ （编辑和查看Perl）</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">2）Komobo Edit （编辑和执行Perl）&nbsp;<br style="margin: 0px; padding: 0px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">二 高级</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">A&nbsp; Perl Express<br style="margin: 0px; padding: 0px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">主页：http://www.perl-express.com/</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">使用： 很简单<br style="margin: 0px; padding: 0px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;"><br style="margin: 0px; padding: 0px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">B Eclipse+EPIC+PadWalker</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">a) 下载解压Eclipse</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">b）下载EPIC插件之设置 (help-&gt;install new software)<br style="margin: 0px; padding: 0px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;"><img alt="" src="http://images.cnblogs.com/cnblogs_com/itech/192594/perl1.png" width="573" height="560" style="margin: 0px; padding: 0px; border: 0px;" />&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">c）下载EPIC插件之下载&nbsp;<br style="margin: 0px; padding: 0px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;"><img alt="" src="http://images.cnblogs.com/cnblogs_com/itech/192594/perl2.png" width="573" height="560" style="margin: 0px; padding: 0px; border: 0px;" /><br style="margin: 0px; padding: 0px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">d）EPIC设置（菜单windows-&gt;preferences）</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;"><img alt="" src="http://images.cnblogs.com/cnblogs_com/itech/192594/perl3.png" width="633" height="544" style="margin: 0px; padding: 0px; border: 0px;" />&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">c）下载perl模块PadWalker (用来在debug时显示变量值)<br style="margin: 0px; padding: 0px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;ppm install PadWalker 或cpan&gt; install PadWalker （注意模块名字的大小写）<br style="margin: 0px; padding: 0px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">d）运行和调试perl&nbsp;<br style="margin: 0px; padding: 0px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;<img alt="" src="http://images.cnblogs.com/cnblogs_com/itech/192594/perl5.png" width="651" height="462" style="margin: 0px; padding: 0px; border: 0px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">完！&nbsp;</p><img src ="http://www.blogjava.net/jjshcc/aggbug/425601.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-06-10 15:01 <a href="http://www.blogjava.net/jjshcc/archive/2015/06/10/425601.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>at命令</title><link>http://www.blogjava.net/jjshcc/archive/2015/06/04/425499.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Thu, 04 Jun 2015 09:19:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/06/04/425499.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/425499.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/06/04/425499.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/425499.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/425499.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 在windows系统中，windows提供了计划任务这一功能，在控制面板&nbsp;-&gt;&nbsp;性能与维护&nbsp;-&gt;&nbsp;任务计划，&nbsp;它的功能就是安排自动运行的任务。&nbsp;通过'添加任务计划'的一步步引导，则可建立一个定时执行的任务。在linux系统中你可能已经发现了为什么系统常常会自动的进行一些任务？这些任务到底是谁在支配他们工作的？在linux系统如...&nbsp;&nbsp;<a href='http://www.blogjava.net/jjshcc/archive/2015/06/04/425499.html'>阅读全文</a><img src ="http://www.blogjava.net/jjshcc/aggbug/425499.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-06-04 17:19 <a href="http://www.blogjava.net/jjshcc/archive/2015/06/04/425499.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>wget进行整站下载（递归下载至本地）</title><link>http://www.blogjava.net/jjshcc/archive/2015/03/05/423219.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Thu, 05 Mar 2015 08:54:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/03/05/423219.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/423219.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/03/05/423219.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/423219.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/423219.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 这个命令可以以递归的方式下载整站，并可以将下载的页面中的链接转换为本地链接。wget加上参数之后，即可成为相当强大的下载工具。wget&nbsp;-r -p -np -k&nbsp;/var/lcoal/ &nbsp;http://xxx.com/abc/-r,&nbsp; --recursive（递归）&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp...&nbsp;&nbsp;<a href='http://www.blogjava.net/jjshcc/archive/2015/03/05/423219.html'>阅读全文</a><img src ="http://www.blogjava.net/jjshcc/aggbug/423219.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-03-05 16:54 <a href="http://www.blogjava.net/jjshcc/archive/2015/03/05/423219.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux Hugepages(提高OLTP 10%的吞吐量) </title><link>http://www.blogjava.net/jjshcc/archive/2014/04/16/412530.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Wed, 16 Apr 2014 06:31:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2014/04/16/412530.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/412530.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2014/04/16/412530.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/412530.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/412530.html</trackback:ping><description><![CDATA[<div><span style="font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; line-height: 28px; font-size: 16px; color: #444444; "><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">Hugepages是从Linux kernal 2.6后被引入的，其目的是使用更大的memory page size以适应越来越大的系统内存,使得oracle SGA这种大内存结构能分配到一个大块（hugepagesize)连续的内存，提高效率.</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="line-height: 28px; " /></p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">在Linux下，默认的page size大小为4k。默认的hugepagesize=2M。</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">我们来看看两者之间有什么区别</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">1. Page Table大小<strong style="line-height: 28px; ">（小page size 可以节省内存，但提高管理成本page table的规模很大）</strong><br style="line-height: 28px; " /></p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">Page Table是用来存放虚拟内存也和物理内存页对应关系的内存结构。因为page size较小，所以相应的改内存结构也会比较大。</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">而Hugepages的常见page size为2M，是4k size的500倍，所以可以大大减小page table的size。</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">我们来看两个例子：</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">这是一个没有配置Hugepage的系统，系统内存128G，pagetable大小大约为4G。</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">cat /proc/meminfo</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">MemTotal: 132086880 kB<br style="line-height: 28px; " />PageTables: 4059612 kB</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">这是配置了Hugepage的系统，系统内存96G, PageTable大小仅为78M</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">MemTotal: 98999880 kB<br style="line-height: 28px; " />PageTables: 79916 kB</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">2. 大大提高了CPU cache中存放的page table所覆盖的内存大小，从而提高了TLB命中率</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">进程的虚拟内存地址段先连接到page tables然后再连接到物理内存。所以在访问内存时需要先访问page tables得到虚拟内存和物理内存的映射关系，然后再访问物理内存。</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">CPU cache中有一部分TLB（Translation Lookaside Buffer）用来存放部分page table以提高这种装换的速度。因为page size变大了，所以同样大小的TLB，所覆盖的内存大小也变大了。提高了TBL命中率，也就是提高了地址转换的速度。</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">3. 使用Hugepages的内存页是不会被交换出去的，永远常驻在内存中，所以也减少了内存也替换的额外开销</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">下面再说说在数据库服务器上使用Hugepages要注意的几点</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">1. Hugepages是在分配后就会预留出来的，其大小一定要比服务器上所有实例的SGA总和要大，差一点都不行。</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">比如说Hugepages设置为90G，oracle SGA为91G，那么oracle在启动的时候就不会使用到这90G的Hugepages。这90G就浪费了。所以在设置Hugepages时要计算SGA的大小，后面会给出一个脚本来计算。</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">2. 其他进程无法使用Hugepages的内存，所以不要设置太大，稍稍比SGA大一点保证SGA可以使用到hugepages就好了。</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">3. PGA不会使用Hugepages的内存。所以11g的AMM (Automatic Memory Management，memory_target参数）是不被支持的。而ASMM(Automatic Shared Memory Management, SGA_target参数)是被支持的，这两个不要搞混淆了。</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">4. 在meminfo中和Hugepage相关的有四项（RHEL5）</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">HugePages_Total: 43000<br style="line-height: 28px; " />HugePages_Free: 29493<br style="line-height: 28px; " />HugePages_Rsvd: 23550<br style="line-height: 28px; " />Hugepagesize: 2048 kB</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">HugePages_Total为所分配的页面数目，和Hugepagesize相乘后得到所分配的内存大小。43000*2/1024大约为84GB<br style="line-height: 28px; " />HugePages_Free为从来没有被使用过的Hugepages数目。即使oracle sga已经分配了这部分内存，但是如果没有实际写入，那么看到的还是Free的。这是很容易误解的地方<br style="line-height: 28px; " />HugePages_Rsvd为已经被分配预留但是还没有使用的page数目。在Oracle刚刚启动时，大部分内存应该都是Reserved并且Free的，随着oracle SGA的使用，Reserved和Free都会不断的降低</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">HugePages_Free &#8211; HugePages_Rsvd 这部分是没有被使用到的内存，如果没有其他的oracle instance，这部分内存也许永远都不会被使用到，也就是被浪费了。在该系统上有11.5GB的内存被浪费了。</p><blockquote style="line-height: 28px; font-size: 1em; margin-top: auto; margin-right: 0px; margin-bottom: auto; margin-left: 35px; "><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">Note: RHEL4上的meminfo有所区别，没有HugePages_Rsvd这一项，并且当oracle instance启动时，所分配的内存就从free list上被移除掉了。也就是启动后HugePages_Free就是没有被SGA用到被浪费的内存。</p></blockquote><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">最后说说如何设置HugePages：</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><strong style="line-height: 28px; ">1. 首先计算SGA大小已决定你要使用多少HugePages内存页。</strong></p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><strong style="line-height: 28px; ">你可以手工计算，如果使用了ASMM可以用SGA_Target/Hugepagesize，否则可以将 db_cache_size，large_pool_size, shared_pool_size,jave_pool_size， streams_pool_size五个部分加起来除以Hugepagesize。</strong></p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">或者可以先将oracle instance都起起来，然后ipcs -m查看共享内存段大小来计算。oracle在401749.1中也提供了一个脚本来帮助计算，脚本如下：</p><div style="line-height: 28px; "><div style="line-height: 28px; ">#!/bin/bash<br style="line-height: 28px; " />#<br style="line-height: 28px; " /># hugepages_settings.sh<br style="line-height: 28px; " />#<br style="line-height: 28px; " /># Linux bash script to compute values for the<br style="line-height: 28px; " /># recommended HugePages/HugeTLB configuration<br style="line-height: 28px; " />#<br style="line-height: 28px; " /># Note: This script does calculation for all shared memory<br style="line-height: 28px; " /># segments available when the script is run, no matter it<br style="line-height: 28px; " /># is an Oracle RDBMS shared memory segment or not.<br style="line-height: 28px; " />#<br style="line-height: 28px; " /># This script is provided by Doc ID 401749.1 from My Oracle Support<br style="line-height: 28px; " /># http://support.oracle.com<br style="line-height: 28px; " /><br style="line-height: 28px; " /># Welcome text<br style="line-height: 28px; " />echo "<br style="line-height: 28px; " />This script is provided by Doc ID 401749.1 from My Oracle Support<br style="line-height: 28px; " />(http://support.oracle.com) where it is intended to compute values for<br style="line-height: 28px; " />the recommended HugePages/HugeTLB configuration for the current shared<br style="line-height: 28px; " />memory segments. Before proceeding with the execution please make sure<br style="line-height: 28px; " />that:<br style="line-height: 28px; " />&nbsp;* Oracle Database instance(s) are up and running<br style="line-height: 28px; " />&nbsp;* Oracle Database 11g Automatic Memory Management (AMM) is not setup<br style="line-height: 28px; " />&nbsp;&nbsp; (See Doc ID 749851.1)<br style="line-height: 28px; " />&nbsp;* The shared memory segments can be listed by command:<br style="line-height: 28px; " />&nbsp;&nbsp; &nbsp; # ipcs -m<br style="line-height: 28px; " /><br style="line-height: 28px; " />Press Enter to proceed..."<br style="line-height: 28px; " /><br style="line-height: 28px; " />read<br style="line-height: 28px; " /><br style="line-height: 28px; " /># Check for the kernel version<br style="line-height: 28px; " />KERN=`uname -r | awk -F. '{ printf("%d.%d\n",$1,$2); }'`<br style="line-height: 28px; " /><br style="line-height: 28px; " /># Find out the HugePage size<br style="line-height: 28px; " />HPG_SZ=`grep Hugepagesize /proc/meminfo | awk '{print $2}'`<br style="line-height: 28px; " /><br style="line-height: 28px; " /># Initialize the counter<br style="line-height: 28px; " />NUM_PG=0<br style="line-height: 28px; " /><br style="line-height: 28px; " /># Cumulative number of pages required to handle the running shared memory segments<br style="line-height: 28px; " />for SEG_BYTES in `ipcs -m | awk '{print $5}' | grep "[0-9][0-9]*"`<br style="line-height: 28px; " />do<br style="line-height: 28px; " />&nbsp;&nbsp; MIN_PG=`echo "$SEG_BYTES/($HPG_SZ*1024)" | bc -q`<br style="line-height: 28px; " />&nbsp;&nbsp; if [ $MIN_PG -gt 0 ]; then<br style="line-height: 28px; " />&nbsp;&nbsp; &nbsp; &nbsp;NUM_PG=`echo "$NUM_PG+$MIN_PG+1" | bc -q`<br style="line-height: 28px; " />&nbsp;&nbsp; fi<br style="line-height: 28px; " />done<br style="line-height: 28px; " /><br style="line-height: 28px; " />RES_BYTES=`echo "$NUM_PG * $HPG_SZ * 1024" | bc -q`<br style="line-height: 28px; " /><br style="line-height: 28px; " /># An SGA less than 100MB does not make sense<br style="line-height: 28px; " /># Bail out if that is the case<br style="line-height: 28px; " />if [ $RES_BYTES -lt 100000000 ]; then<br style="line-height: 28px; " />&nbsp;&nbsp; echo "***********"<br style="line-height: 28px; " />&nbsp;&nbsp; echo "** ERROR **"<br style="line-height: 28px; " />&nbsp;&nbsp; echo "***********"<br style="line-height: 28px; " />&nbsp;&nbsp; echo "Sorry! There are not enough total of shared memory segments allocated for<br style="line-height: 28px; " />HugePages configuration. HugePages can only be used for shared memory segments<br style="line-height: 28px; " />that you can list by command:<br style="line-height: 28px; " /><br style="line-height: 28px; " />&nbsp;&nbsp; # ipcs -m<br style="line-height: 28px; " /><br style="line-height: 28px; " />of a size that can match an Oracle Database SGA. Please make sure that:<br style="line-height: 28px; " />&nbsp;* Oracle Database instance is up and running<br style="line-height: 28px; " />&nbsp;* Oracle Database 11g Automatic Memory Management (AMM) is not configured"<br style="line-height: 28px; " />&nbsp;&nbsp; exit 1<br style="line-height: 28px; " />fi<br style="line-height: 28px; " /><br style="line-height: 28px; " /># Finish with results<br style="line-height: 28px; " />case $KERN in<br style="line-height: 28px; " />&nbsp;&nbsp; '2.4') HUGETLB_POOL=`echo "$NUM_PG*$HPG_SZ/1024" | bc -q`;<br style="line-height: 28px; " />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo "Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL" ;;<br style="line-height: 28px; " />&nbsp;&nbsp; '2.6') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;<br style="line-height: 28px; " />&nbsp;&nbsp; &nbsp;*) echo "Unrecognized kernel version $KERN. Exiting." ;;<br style="line-height: 28px; " />esac<br style="line-height: 28px; " /><br style="line-height: 28px; " /># End</div></div><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">2. 关闭所有oracle实例</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">3. 用root设定oracle memlock limit,设置一个较大的数值或者unlimited</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">在/etc/security/limits.conf最后添加<br style="line-height: 28px; " />oracle hard memlock unlimited<br style="line-height: 28px; " />oracle soft memlock unlimited</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">4. 分配hugepages内存</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">在/etc/sysctl.conf中添加</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">vm.nr_hugepages = 46000 (step1&#8242;s value)</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">执行sysctl -p使其生效。这时候内存就已经被分配了，可以查看meminfo</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">grep Huge /proc/meminfo</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">HugePages_Total为设定的值大小，HugePages_Free应该和HugePages_Total一样大，HugePages_Rsvd为0.</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">5. 启动Oracle instance</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">这时候再次查看meminfo</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">HugePages_Total为设定的值大小不变，HugePages_Free有所降低，HugePages_Rsvd为一个较大的数值（因为刚刚启动时，大部分SGA被分配但是没有被使用到）。</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">如果Hugepages没有被使用，可能一些memory page被分配为4k大小了，那么需要重启server来设置。</p><p style="line-height: 28px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">从我们的测试结果看，Hugepages可以提高OLTP系统10%的吞吐量，当然不同的数据库应用结果可能不同，但是总体来说这是一个nice to have的设置。</p></span></div><img src ="http://www.blogjava.net/jjshcc/aggbug/412530.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2014-04-16 14:31 <a href="http://www.blogjava.net/jjshcc/archive/2014/04/16/412530.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Crontab的格式</title><link>http://www.blogjava.net/jjshcc/archive/2014/01/22/409232.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Wed, 22 Jan 2014 08:54:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2014/01/22/409232.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/409232.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2014/01/22/409232.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/409232.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/409232.html</trackback:ping><description><![CDATA[<div><span style="font-family: 'Lucida Grande', 'Lucida Sans Unicode', Helvetica, Arial, Verdana, sans-serif; line-height: 18px; font-size: 12px; "><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; text-indent: 0px; "><div><span style="font-family: Arial; line-height: 26px; font-size: 14px; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 18px; ">在linux中启动crontab服务：</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 18px; color: #ff0000; ">/etc/init.d/crond&nbsp; start</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 18px; color: #000000; ">crontab的命令格式</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 18px; ">crontab -l&nbsp;&nbsp; 显示当前的crontab 文件（默认编写的crontab文件会保存在&nbsp;<span style="color: #ff0000; ">(/var/spool/cron/用户名&nbsp;&nbsp; 例</span><span style="color: #ff0000; ">如: /var/spool/cron/roger</span>)</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 18px; ">crontab -r 删除当前的crontab (谨慎使用此方法，因为将会把所有的计划任务全部删除）</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 18px; ">crontab -e 使用编辑器编辑当前的crontab文件</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 18px; ">crontab 的文件格式：</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;minutes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hour&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; day-of-month&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; month-of-year&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; day-of-week&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; commands</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 18px; ">例如：</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4&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; 2，5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/bin/wall&lt;/etc/motd</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 18px; color: #ff0000; ">*************解释：每周的周二和周五广播&nbsp; /etc/motd中的信息************************************************</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;12-14&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; 3-6,9-12&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1-5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bash_scripts</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 18px; ">*******************解释：每年的3-6月份，以及9-12月份的周一到周五的下午12-14点，每隔两分钟执行一个脚本*****</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 18px; ">crontab的配置文件放在 /etc/crontab中</span></p></span></div><br />第1列分钟1～59<br style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; " />第2列小时1～23（0表示子夜）<br style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; " />第3列日1～31<br style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; " />第4列月1～12<br style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; " />第5列星期0～6（0表示星期天）<br style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; " />第6列要运行的命令</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; text-indent: 0px; ">下面是crontab的格式：<br style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; " />分 时 日 月 星期 要运行的命令</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; text-indent: 0px; ">这里有crontab文件条目的一些例子：</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; text-indent: 0px; ">30 21 * * * /usr/local/apache/bin/apachectl restart<br style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; " />上面的例子表示每晚的21:30重启apache。</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; text-indent: 0px; ">45 4 1,10,22 * * /usr/local/apache/bin/apachectl restart<br style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; " />上面的例子表示每月1、10、22日的4 : 45重启apache。</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; text-indent: 0px; ">10 1 * * 6,0 /usr/local/apache/bin/apachectl restart<br style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; " />上面的例子表示每周六、周日的1 : 10重启apache。</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; text-indent: 0px; ">0,30 18-23 * * * /usr/local/apache/bin/apachectl restart<br style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; " />上面的例子表示在每天18 : 00至23 : 00之间每隔30分钟重启apache。</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; text-indent: 0px; ">0 23 * * 6 /usr/local/apache/bin/apachectl restart<br style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; " />上面的例子表示每星期六的11 : 00 pm重启apache。</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; text-indent: 0px; ">* */1 * * * /usr/local/apache/bin/apachectl restart<br style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; " />每一小时重启apache</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; text-indent: 0px; ">* 23-7/1 * * * /usr/local/apache/bin/apachectl restart<br style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; " />晚上11点到早上7点之间，每隔一小时重启apache</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; text-indent: 0px; ">0 11 4 * mon-wed /usr/local/apache/bin/apachectl restart<br style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; " />每月的4号与每周一到周三的11点重启apache</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; text-indent: 0px; ">0 4 1 jan * /usr/local/apache/bin/apachectl restart<br style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; " />一月一号的4点重启apache<br /><br /><br /><br /></p></span></div><img src ="http://www.blogjava.net/jjshcc/aggbug/409232.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2014-01-22 16:54 <a href="http://www.blogjava.net/jjshcc/archive/2014/01/22/409232.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>command not found 解决办法 .</title><link>http://www.blogjava.net/jjshcc/archive/2013/12/06/407289.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Fri, 06 Dec 2013 06:19:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2013/12/06/407289.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/407289.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2013/12/06/407289.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/407289.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/407289.html</trackback:ping><description><![CDATA[原本使用ifconfig 可以使用，今天是怎么了，可能安装软件修改了，百度~~ <br />[oracle@localhost /]$ ifconfig <br />提示：&#8220;bash: ifconfig: command not found&#8221; <br /><br />于是我切换到root用户下 <br />[root@localhost /]$ ifconfig <br />依然提示：&#8220;bash: ifconfig: command not found&#8221; <br /><br />分析问题 <br />1.whereis ifconfig 看一下这个命令在哪个目录下 <br /><br />2.echo $PATH 看一下该目录是否在路经下,注意lunux下是完全区分大小写的，所以不要忽略这点 <br /><br />3.执行命令，需要指定路径或者把目录加入PATH中 <br /><br />4.于是可以这样访问 <br />方法一：[root@localhost sbin]$ /sbin/ifconfig 就可以出现使用了 <br />方法二：[root@localhost sbin]$ export PATH=$PATH:/sbin ，这样设置后，下次就可以直接访问了，免处第一种的麻烦，如： <br />[root@localhost /]$ ifconfig <br /><br />方法三:修改/etc/profile文件,注释掉if语句即可 <br />把下面的if语句注释掉： <br /># Path manipulation <br />if [ "$EUID" = "0" ]; then <br />pathmunge /sbin <br />pathmunge /usr/sbin <br />pathmunge /usr/local/sbin <br />fi <br />修改为 <br /># Path manipulation <br /># if [ "$EUID" = "0" ]; then <br />pathmunge /sbin <br />pathmunge /usr/sbin <br />pathmunge /usr/local/sbin <br />#fi <br /><br />注：不光是ifconfig命令出现&#8220;bash: ifconfig: command not found&#8221;，原因非root用户的path中没有/sbin/ifconfig <br />，其它的命令也可以出现这种情况，解决的方法是一样的<img src ="http://www.blogjava.net/jjshcc/aggbug/407289.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2013-12-06 14:19 <a href="http://www.blogjava.net/jjshcc/archive/2013/12/06/407289.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux之sort用法</title><link>http://www.blogjava.net/jjshcc/archive/2013/11/29/407024.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Fri, 29 Nov 2013 08:38:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2013/11/29/407024.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/407024.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2013/11/29/407024.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/407024.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/407024.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 19px; font-size: 13px; "><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">sort命令是帮我们依据不同的数据类型进行排序，其语法及常用参数格式：<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />　　<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #ff0000; ">sort [-bcfMnrtk][源文件][-o 输出文件]</span>&nbsp;<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />补充说明：sort可针对文本文件的内容，以行为单位来排序。</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">参　　数：<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp;&nbsp;-b&nbsp;&nbsp;&nbsp;忽略每行前面开始出的空格字符。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp;&nbsp;-c&nbsp;&nbsp;&nbsp;检查文件是否已经按照顺序排序。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp;&nbsp;-f&nbsp;&nbsp;&nbsp;排序时，忽略大小写字母。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp;&nbsp;-M&nbsp;&nbsp;&nbsp;将前面3个字母依照月份的缩写进行排序。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp;&nbsp;-n&nbsp;&nbsp;&nbsp;依照数值的大小排序。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp;&nbsp;-o&lt;输出文件&gt;&nbsp;&nbsp;&nbsp;将排序后的结果存入指定的文件。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp;&nbsp;-r&nbsp;&nbsp;&nbsp;以相反的顺序来排序。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp;&nbsp;-t&lt;分隔字符&gt;&nbsp;&nbsp;&nbsp;指定排序时所用的栏位分隔字符。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp; -k&nbsp;&nbsp;选择以哪个区间进行排序。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp;&nbsp;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 2em; ">下面通过几个例子来讲述Sort的使用。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />（1）sort将文件的每一行作为一个单位，相互比较，比较原则是从首字符向后，依次按ASCII码值进行比较，最后将他们按升序输出。</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">[rocrocket@rocrocket programming]$ cat seq.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />banana<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />apple<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />pear<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />orange<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />[rocrocket@rocrocket programming]$ sort seq.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />apple<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />banana<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />orange<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />pear</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">用户可以保存排序后的文件内容，或把排序后的文件内容输出至打印机。下例中用户把排序后的文件内容保存到名为result的文件中。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />$ Sort seq.txt &gt; result</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">（2）sort的-u选项</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">它的作用很简单，就是在输出行中去除重复行。</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">[rocrocket@rocrocket programming]$ cat seq.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />banana<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />apple<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />pear<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />orange<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />pear<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />[rocrocket@rocrocket programming]$ sort seq.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />apple<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />banana<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />orange<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />pear<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />pear<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />[rocrocket@rocrocket programming]$ sort -u seq.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />apple<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />banana<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />orange<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />pear</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">pear由于重复被-u选项无情的删除了。</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">（3）sort的-r选项</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">sort默认的排序方式是升序，如果想改成降序，就加个-r就搞定了。</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">[rocrocket@rocrocket programming]$ cat number.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />1<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />3<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />5<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />2<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />4<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />[rocrocket@rocrocket programming]$ sort number.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />1<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />2<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />3<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />4<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />5<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />[rocrocket@rocrocket programming]$ sort -r number.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />5<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />4<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />3<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />2<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />1<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />（5）sort的-o选项</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">由于sort默认是把结果输出到标准输出，所以需要用重定向才能将结果写入文件，形如sort filename &gt; newfile。</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">但是，如果你想把排序结果输出到原文件中，用重定向可就不行了。</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">[rocrocket@rocrocket programming]$ sort -r number.txt &gt; number.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />[rocrocket@rocrocket programming]$ cat number.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />[rocrocket@rocrocket programming]$<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />看，竟然将number清空了。</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">就在这个时候，-o选项出现了，它成功的解决了这个问题，让你放心的将结果写入原文件。这或许也是-o比重定向的唯一优势所在。</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">[rocrocket@rocrocket programming]$ cat number.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />1<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />3<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />5<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />2<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />4<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />[rocrocket@rocrocket programming]$ sort -r number.txt -o number.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />[rocrocket@rocrocket programming]$ cat number.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />5<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />4<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />3<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />2<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />1</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">（6）&nbsp;sort的-n选项</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">你有没有遇到过10比2小的情况。我反正遇到过。出现这种情况是由于排序程序将这些数字按字符来排序了，排序程序会先比较1和2，显然1小，所以就将10放在2前面喽。这也是sort的一贯作风。</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">我们如果想改变这种现状，就要使用-n选项，来告诉sort，&#8220;要以数值来排序&#8221;！</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">[rocrocket@rocrocket programming]$ cat number.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />1<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />10<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />19<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />11<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />2<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />5<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />[rocrocket@rocrocket programming]$ sort number.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />1<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />10<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />11<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />19<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />2<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />5<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />[rocrocket@rocrocket programming]$ sort -n number.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />1<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />2<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />5<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />10<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />11<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />19</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">（7）&nbsp;sort的-t选项和-k选项</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">如果有一个文件的内容是这样：</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">[rocrocket@rocrocket programming]$ cat facebook.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />banana:30:5.5<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />apple:10:2.5<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />pear:90:2.3<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />orange:20:3.4</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">这个文件有三列，列与列之间用冒号隔开了，第一列表示水果类型，第二列表示水果数量，第三列表示水果价格。那么我想以水果数量来排序，也就是以第二列来排序，如何利用sort实现？幸好，sort提供了-t选项，后面可以设定间隔符。指定了间隔符之后，就可以用-k来指定列数了。</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">[rocrocket@rocrocket programming]$ sort -n -k 2 -t &#8216;:&#8217; facebook.txt<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />apple:10:2.5<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />orange:20:3.4<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />banana:30:5.5<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />pear:90:2.3</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">（8）&nbsp;其他的sort常用选项</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">-f会将小写字母都转换为大写字母来进行比较，亦即忽略大小写</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">-c会检查文件是否已排好序，如果乱序，则输出第一个乱序的行的相关信息，最后返回1</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">-C会检查文件是否已排好序，如果乱序，不输出内容，仅返回1</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">-M会以月份来排序，比如JAN小于FEB等等</p><p style="margin-top: 10px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #000000; font-size: 13px; text-indent: 0px; ">-b会忽略每一行前面的所有空白部分，从第一个可见字符开始比较。</p></span></div><img src ="http://www.blogjava.net/jjshcc/aggbug/407024.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2013-11-29 16:38 <a href="http://www.blogjava.net/jjshcc/archive/2013/11/29/407024.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux系统下查看系统资源的命令</title><link>http://www.blogjava.net/jjshcc/archive/2013/11/29/407023.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Fri, 29 Nov 2013 08:19:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2013/11/29/407023.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/407023.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2013/11/29/407023.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/407023.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/407023.html</trackback:ping><description><![CDATA[<div><div>linux系统下查看系统资源的相关命令</div><div>&nbsp;</div><div>&nbsp;&nbsp; &nbsp;详细查看CPU，内存，硬盘，光驱的情况，可以用下面命令。</div><div>&nbsp;&nbsp; &nbsp;#dmesg | more</div><div>&nbsp;&nbsp; &nbsp;dmesg显示的是系统加载时的启动信息，把硬件信息都显示出来。</div><div>&nbsp;&nbsp; &nbsp;也可以用下面命令分别查看CPU，内存，硬盘，光驱的情况：</div><div>&nbsp;&nbsp; &nbsp;# dmesg|grep cpu //cpu</div><div>&nbsp;&nbsp; &nbsp;# dmesg|grep hd &nbsp; //硬盘</div><div>&nbsp;&nbsp; &nbsp;# dmesg | grep proc</div><div>&nbsp;&nbsp; &nbsp;查看LINUX的版本信息：</div><div>&nbsp;&nbsp; &nbsp;# uname -a</div><div>&nbsp;&nbsp; &nbsp;查看CPU的个数也可以用：</div><div>&nbsp;&nbsp; &nbsp;# more /proc/cpuinfo</div><div>&nbsp;&nbsp; &nbsp;查看内存情况也可以用下面两条命令：</div><div>&nbsp;&nbsp; &nbsp;#top</div><div>&nbsp;&nbsp; &nbsp;# more /proc/meminfo<br /><br /><div><div>top命令</div><div>1.作用</div><div>top命令用来显示执行中的程序进程，使用权限是所有用户。</div><div>2.格式</div><div>top [－] [d delay] [q] [c] [S] [s] [i] [n]</div><div>3.主要参数</div><div>d：指定更新的间隔，以秒计算。</div><div>q：没有任何延迟的更新。如果使用者有超级用户，则top命令将会以最高的优先序执行。</div><div>c：显示进程完整的路径与名称。</div><div>S：累积模式，会将己完成或消失的子行程的CPU时间累积起来。</div><div>s：安全模式。</div><div>i：不显示任何闲置(Idle)或无用(Zombie)的行程。</div><div>n：显示更新的次数，完成后将会退出top</div></div><br /><div><div>free命令</div><div>1.作用</div><div>free命令用来显示内存的使用情况，使用权限是所有用户。</div><div>2.格式</div><div>free [－b－k－m] [－o] [－s delay] [－t] [－V]</div><div>3.主要参数</div><div>－b －k －m：分别以字节（KB、MB）为单位显示内存使用情况。</div><div>－s delay：显示每隔多少秒数来显示一次内存使用情况。</div><div>－t：显示内存总和列。</div><div>－o：不显示缓冲区调节列。<br /><br /><br /><div><div># uname -a # 查看内核/操作系统/CPU信息</div><div># cat /etc/issue # 查看操作系统版本</div><div># cat /proc/cpuinfo # 查看CPU信息</div><div># hostname # 查看计算机名</div><div># lspci -tv # 列出所有PCI设备</div><div># lsusb -tv # 列出所有USB设备</div><div># lsmod # 列出加载的内核模块</div><div># env # 查看环境变量资源</div><div># free -m # 查看内存使用量和交换区使用量</div><div># df -h # 查看各分区使用情况</div><div># du -sh # 查看指定目录的大小</div><div># grep MemTotal /proc/meminfo # 查看内存总量</div><div># grep MemFree /proc/meminfo # 查看空闲内存量</div><div># uptime # 查看系统运行时间、用户数、负载</div><div># cat /proc/loadavg # 查看系统负载磁盘和分区</div><div># mount | column -t # 查看挂接的分区状态</div><div># fdisk -l # 查看所有分区</div><div># swapon -s # 查看所有交换分区</div><div># hdparm -i /dev/hda # 查看磁盘参数(仅适用于IDE设备)</div><div># dmesg | grep IDE # 查看启动时IDE设备检测状况网络</div><div># ifconfig # 查看所有网络接口的属性</div><div># iptables -L # 查看防火墙设置</div><div># route -n # 查看路由表</div><div># netstat -lntp # 查看所有监听端口</div><div># netstat -antp # 查看所有已经建立的连接</div><div># netstat -s # 查看网络统计信息进程</div><div># ps -ef # 查看所有进程</div><div># top # 实时显示进程状态用户</div><div># w # 查看活动用户</div><div># id # 查看指定用户信息</div><div># last # 查看用户登录日志</div><div># cut -d: -f1 /etc/passwd # 查看系统所有用户</div><div># cut -d: -f1 /etc/group # 查看系统所有组</div><div># crontab -l # 查看当前用户的计划任务服务</div><div># chkconfig &#8211;list # 列出所有系统服务</div><div># chkconfig &#8211;list | grep on # 列出所有启动的系统服务程序</div><div># rpm -qa # 查看所有安装的软件包</div><div>cat /proc/cpuinfo ：查看CPU相关参数</div><div>cat /proc/partitions ：查看硬盘和分区</div><div>cat /proc/meminfo ：查看内存信息</div><div>cat /proc/version ：查看版本，类似uname -r</div><div>cat /proc/ioports ：查看设备io端口</div><div>cat /proc/interrupts ：查看中断</div><div>cat /proc/pci ：查看pci设备的信息</div><div>cat /proc/swaps ：查看所有swap分区的信息</div></div></div></div></div></div><img src ="http://www.blogjava.net/jjshcc/aggbug/407023.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2013-11-29 16:19 <a href="http://www.blogjava.net/jjshcc/archive/2013/11/29/407023.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux 程序运行前后台切</title><link>http://www.blogjava.net/jjshcc/archive/2013/11/29/407014.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Fri, 29 Nov 2013 07:23:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2013/11/29/407014.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/407014.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2013/11/29/407014.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/407014.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/407014.html</trackback:ping><description><![CDATA[<div><span style="font-family: Verdana, 宋体, sans-serif; line-height: 18px; font-size: 12px; color: #323e32; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; border-style: initial; border-color: initial; word-wrap: normal; word-break: normal; line-height: 18px; "><strong style="font-weight: bold; ">A</strong>,Shell支持作用控制，有以下命令：<br />1. command&amp; 让进程在后台运行<br />2. jobs 查看后台运行的进程<br />3. fg %n 让后台运行的进程n到前台来<br />4. bg %n 让进程n到后台去；&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr><br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;PS:"n"为jobs查看到的进程编号.</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; border-style: initial; border-color: initial; word-wrap: normal; word-break: normal; line-height: 18px; "><strong style="font-weight: bold; ">B.&nbsp;</strong>fg、bg、jobs、&amp;、ctrl + z都是跟系统任务有关的，虽然现在基本上不怎么需要用到这些命令，但学会了也是很实用的</p><div width="100%" style="margin-top: 15px; margin-right: 15px; margin-bottom: 15px; margin-left: 15px; "><div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; border-style: initial; border-color: initial; word-wrap: normal; word-break: normal; line-height: 18px; ">一。&amp; 最经常被用到<br />这个用在一个命令的最后，可以把这个命令放到后台执行<br />二。ctrl + z<br />可以将一个正在前台执行的命令放到后台，并且暂停<br />三。jobs<br />查看当前有多少在后台运行的命令<br />四。fg<br />将后台中的命令调至前台继续运行<br />如果后台中有多个命令，可以用 fg %jobnumber将选中的命令调出，%jobnumber是通过jobs命令查到的后台正在执行的命令的序号(不是pid)<br />五。bg<br />将一个在后台暂停的命令，变成继续执行<br />如果后台中有多个命令，可以用bg %jobnumber将选中的命令调出，%jobnumber是通过jobs命令查到的后台正在执行的命令的序号(不是pid)</p></div></div></span></div><img src ="http://www.blogjava.net/jjshcc/aggbug/407014.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2013-11-29 15:23 <a href="http://www.blogjava.net/jjshcc/archive/2013/11/29/407014.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>df 命令</title><link>http://www.blogjava.net/jjshcc/archive/2013/11/17/406446.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Sun, 17 Nov 2013 13:26:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2013/11/17/406446.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/406446.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2013/11/17/406446.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/406446.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/406446.html</trackback:ping><description><![CDATA[<div><div>linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况。可以利用该命令来获取硬盘被占用了多少空间，目前还剩下多少空间等信息。</div><div>1．命令格式：</div><div>df [选项] [文件]</div><div>2．命令功能：</div><div>显示指定磁盘文件的可用空间。如果没有文件名被指定，则所有当前被挂载的文件系统的可用空间将被显示。默认情况下，磁盘空间将以 1KB 为单位进行显示，除非环境变量 POSIXLY_CORRECT 被指定，那样将以512字节为单位进行显示</div><div>3．命令参数：</div><div>必要参数：</div><div>-a 全部文件系统列表</div><div>-h 方便阅读方式显示</div><div>-H 等于&#8220;-h&#8221;，但是计算式，1K=1000，而不是1K=1024</div><div>-i 显示inode信息</div><div>-k 区块为1024字节</div><div>-l 只显示本地文件系统</div><div>-m 区块为1048576字节</div><div>--no-sync 忽略 sync 命令</div><div>-P 输出格式为POSIX</div><div>--sync 在取得磁盘信息前，先执行sync命令</div><div>-T 文件系统类型</div><div>选择参数：</div><div>--block-size=&lt;区块大小&gt; 指定区块大小</div><div>-t&lt;文件系统类型&gt; 只显示选定文件系统的磁盘信息</div><div>-x&lt;文件系统类型&gt; 不显示选定文件系统的磁盘信息</div><div>--help 显示帮助信息</div><div>--version 显示版本信息</div><div>4．使用实例：</div><div>实例1：显示磁盘使用情况</div><div>命令：</div><div>df</div><div>输出：</div><div>[root@CT1190 log]# df</div><div>文件系统 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1K-块 &nbsp; &nbsp; &nbsp; &nbsp;已用 &nbsp; &nbsp; 可用 已用% 挂载点</div><div>/dev/sda7 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 19840892 &nbsp; &nbsp;890896 &nbsp;17925856 &nbsp; 5% /</div><div>/dev/sda9 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;203727156 112797500 &nbsp;80413912 &nbsp;59% /opt</div><div>/dev/sda8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4956284 &nbsp; &nbsp;570080 &nbsp; 4130372 &nbsp;13% /var</div><div>/dev/sda6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 19840892 &nbsp; 1977568 &nbsp;16839184 &nbsp;11% /usr</div><div>/dev/sda3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 988116 &nbsp; &nbsp; 23880 &nbsp; &nbsp;913232 &nbsp; 3% /boot</div><div>tmpfs &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 16473212 &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp;16473212 &nbsp; 0% /dev/shm</div><div>说明：</div><div>linux中df命令的输出清单的第1列是代表文件系统对应的设备文件的路径名（一般是硬盘上的分区）；第2列给出分区包含的数据块（1024字节）的数目；第3，4列分别表示已用的和可用的数据块数目。用户也许会感到奇怪的是，第3，4列块数之和不等于第2列中的块数。这是因为缺省的每个分区都留了少量空间供系统管理员使用。即使遇到普通用户空间已满的情况，管理员仍能登录和留有解决问题所需的工作空间。清单中Use% 列表示普通用户空间使用的百分比，即使这一数字达到100％，分区仍然留有系统管理员使用的空间。最后，Mounted on列表示文件系统的挂载点。</div><div>实例2：以inode模式来显示磁盘使用情况</div><div>命令：</div><div>df -i</div><div>输出：</div><div>[root@CT1190 log]# df -i</div><div>文件系统 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Inode (I)已用 (I)可用 (I)已用% 挂载点</div><div>/dev/sda7 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;5124480 &nbsp; &nbsp;5560 5118920 &nbsp; &nbsp;1% /</div><div>/dev/sda9 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;52592640 &nbsp; 50519 52542121 &nbsp; &nbsp;1% /opt</div><div>/dev/sda8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1280000 &nbsp; &nbsp;8799 1271201 &nbsp; &nbsp;1% /var</div><div>/dev/sda6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;5124480 &nbsp; 80163 5044317 &nbsp; &nbsp;2% /usr</div><div>/dev/sda3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 255232 &nbsp; &nbsp; &nbsp;34 &nbsp;255198 &nbsp; &nbsp;1% /boot</div><div>tmpfs &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4118303 &nbsp; &nbsp; &nbsp; 1 4118302 &nbsp; &nbsp;1% /dev/shm</div><div>说明：</div><div>实例3：显示指定类型磁盘</div><div>命令：</div><div>df -t ext3</div><div>输出：</div><div>[root@CT1190 log]# df -t ext3</div><div>文件系统 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1K-块 &nbsp; &nbsp; &nbsp; &nbsp;已用 &nbsp; &nbsp; 可用 已用% 挂载点</div><div>/dev/sda7 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 19840892 &nbsp; &nbsp;890896 &nbsp;17925856 &nbsp; 5% /</div><div>/dev/sda9 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;203727156 &nbsp;93089700 100121712 &nbsp;49% /opt</div><div>/dev/sda8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4956284 &nbsp; &nbsp;570104 &nbsp; 4130348 &nbsp;13% /var</div><div>/dev/sda6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 19840892 &nbsp; 1977568 &nbsp;16839184 &nbsp;11% /usr</div><div>/dev/sda3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 988116 &nbsp; &nbsp; 23880 &nbsp; &nbsp;913232 &nbsp; 3% /boot</div><div>说明：</div><div>实例4：列出各文件系统的i节点使用情况</div><div>命令：</div><div>df -ia</div><div>输出：</div><div>[root@CT1190 log]# df -ia</div><div>文件系统 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Inode (I)已用 (I)可用 (I)已用% 挂载点</div><div>/dev/sda7 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;5124480 &nbsp; &nbsp;5560 5118920 &nbsp; &nbsp;1%&nbsp;</div><div>/proc &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp;- &nbsp;/proc</div><div>sysfs &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp;- &nbsp;/sys</div><div>devpts &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp;- &nbsp;/dev/pts</div><div>/dev/sda9 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;52592640 &nbsp; 50519 52542121 &nbsp; &nbsp;1% /opt</div><div>/dev/sda8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1280000 &nbsp; &nbsp;8799 1271201 &nbsp; &nbsp;1% /var</div><div>/dev/sda6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;5124480 &nbsp; 80163 5044317 &nbsp; &nbsp;2% /usr</div><div>/dev/sda3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 255232 &nbsp; &nbsp; &nbsp;34 &nbsp;255198 &nbsp; &nbsp;1% /boot</div><div>tmpfs &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4118303 &nbsp; &nbsp; &nbsp; 1 4118302 &nbsp; &nbsp;1% /dev/shm</div><div>none &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp;- &nbsp;/proc/sys/fs/binfmt_misc</div><div>说明：</div><div>实例5：列出文件系统的类型</div><div>命令：</div><div>df -T</div><div>输出：</div><div>root@CT1190 log]# df -T</div><div>文件系统 &nbsp; &nbsp; &nbsp;类型 &nbsp; &nbsp; 1K-块 &nbsp; &nbsp; &nbsp; &nbsp;已用 &nbsp; &nbsp; 可用 已用% 挂载点</div><div>/dev/sda7 &nbsp; &nbsp; ext3 &nbsp; &nbsp;19840892 &nbsp; &nbsp;890896 &nbsp;17925856 &nbsp; 5% /</div><div>/dev/sda9 &nbsp; &nbsp; ext3 &nbsp; 203727156 &nbsp;93175692 100035720 &nbsp;49% /opt</div><div>/dev/sda8 &nbsp; &nbsp; ext3 &nbsp; &nbsp; 4956284 &nbsp; &nbsp;570104 &nbsp; 4130348 &nbsp;13% /var</div><div>/dev/sda6 &nbsp; &nbsp; ext3 &nbsp; &nbsp;19840892 &nbsp; 1977568 &nbsp;16839184 &nbsp;11% /usr</div><div>/dev/sda3 &nbsp; &nbsp; ext3 &nbsp; &nbsp; &nbsp;988116 &nbsp; &nbsp; 23880 &nbsp; &nbsp;913232 &nbsp; 3% /boot</div><div>tmpfs &nbsp; &nbsp; &nbsp; &nbsp;tmpfs &nbsp; &nbsp;16473212 &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp;16473212 &nbsp; 0% /dev/shm</div><div>说明：</div><div>实例6：以更易读的方式显示目前磁盘空间和使用情况&nbsp;</div><div>命令：</div><div>输出：</div><div>[root@CT1190 log]# df -h</div><div>文件系统 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;容量 &nbsp;已用 可用 已用% 挂载点</div><div>/dev/sda7 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;19G &nbsp;871M &nbsp; 18G &nbsp; 5% /</div><div>/dev/sda9 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 195G &nbsp; 89G &nbsp; 96G &nbsp;49% /opt</div><div>/dev/sda8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4.8G &nbsp;557M &nbsp;4.0G &nbsp;13% /var</div><div>/dev/sda6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;19G &nbsp;1.9G &nbsp; 17G &nbsp;11% /usr</div><div>/dev/sda3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 965M &nbsp; 24M &nbsp;892M &nbsp; 3% /boot</div><div>tmpfs &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;16G &nbsp; &nbsp; 0 &nbsp; 16G &nbsp; 0% /dev/shm</div><div>[root@CT1190 log]# df -H</div><div>文件系统 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 容量 &nbsp; 已用 &nbsp;可用 已用% 挂载点</div><div>/dev/sda7 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 21G &nbsp; 913M &nbsp; &nbsp;19G &nbsp; 5% /</div><div>/dev/sda9 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;209G &nbsp; &nbsp;96G &nbsp; 103G &nbsp;49% /opt</div><div>/dev/sda8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;5.1G &nbsp; 584M &nbsp; 4.3G &nbsp;13% /var</div><div>/dev/sda6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 21G &nbsp; 2.1G &nbsp; &nbsp;18G &nbsp;11% /usr</div><div>/dev/sda3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1.1G &nbsp; &nbsp;25M &nbsp; 936M &nbsp; 3% /boot</div><div>tmpfs &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 17G &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp;17G &nbsp; 0% /dev/shm</div><div>[root@CT1190 log]# df -lh</div><div>文件系统 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;容量 &nbsp;已用 可用 已用% 挂载点</div><div>/dev/sda7 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;19G &nbsp;871M &nbsp; 18G &nbsp; 5% /</div><div>/dev/sda9 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 195G &nbsp; 89G &nbsp; 96G &nbsp;49% /opt</div><div>/dev/sda8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4.8G &nbsp;557M &nbsp;4.0G &nbsp;13% /var</div><div>/dev/sda6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;19G &nbsp;1.9G &nbsp; 17G &nbsp;11% /usr</div><div>/dev/sda3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 965M &nbsp; 24M &nbsp;892M &nbsp; 3% /boot</div><div>tmpfs &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;16G &nbsp; &nbsp; 0 &nbsp; 16G &nbsp; 0% /dev/shm</div><div>[root@CT1190 log]# df -k</div><div>文件系统 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1K-块 &nbsp; &nbsp; &nbsp; &nbsp;已用 &nbsp; &nbsp; 可用 已用% 挂载点</div><div>/dev/sda7 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 19840892 &nbsp; &nbsp;890896 &nbsp;17925856 &nbsp; 5% /</div><div>/dev/sda9 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;203727156 &nbsp;93292572 &nbsp;99918840 &nbsp;49% /opt</div><div>/dev/sda8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4956284 &nbsp; &nbsp;570188 &nbsp; 4130264 &nbsp;13% /var</div><div>/dev/sda6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 19840892 &nbsp; 1977568 &nbsp;16839184 &nbsp;11% /usr</div><div>/dev/sda3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 988116 &nbsp; &nbsp; 23880 &nbsp; &nbsp;913232 &nbsp; 3% /boot</div><div>tmpfs &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 16473212 &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp;16473212 &nbsp; 0% /dev/shm</div><div>说明：</div><div>-h更具目前磁盘空间和使用情况 以更易读的方式显示</div><div>-H根上面的-h参数相同,不过在根式化的时候,采用1000而不是1024进行容量转换</div><div>-k以单位显示磁盘的使用情况</div><div>-l显示本地的分区的磁盘空间使用率,如果服务器nfs了远程服务器的磁盘,那么在df上加上-l后系统显示的是过滤nsf驱动器后的结果</div><div>-i显示inode的使用情况。linux采用了类似指针的方式管理磁盘空间影射.这也是一个比较关键应用</div></div><img src ="http://www.blogjava.net/jjshcc/aggbug/406446.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2013-11-17 21:26 <a href="http://www.blogjava.net/jjshcc/archive/2013/11/17/406446.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>chown命令</title><link>http://www.blogjava.net/jjshcc/archive/2013/11/17/406445.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Sun, 17 Nov 2013 13:21:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2013/11/17/406445.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/406445.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2013/11/17/406445.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/406445.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/406445.html</trackback:ping><description><![CDATA[<div><h1><div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">chown将指定文件的拥有者改为指定的用户或组，用户可以是用户名或者用户ID；组可以是组名或者组ID；文件是以空格分开的要改变权限的文件列表，支持通配符。系统管理员经常使用chown命令，在将文件拷贝到另一个用户的名录下之后，让用户拥有使用该文件的权限。&nbsp;</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　1．命令格式：</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　　　chown [选项]... [所有者][:[组]] 文件...</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　2．命令功能：</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　　　通过chown改变文件的拥有者和群组。在更改文件的所有者或所属群组时，可以使用用户名称和用户识别码设置。普通用户不能将自己的文件改变成其他的拥有者。其操作权限一般为管理员。</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　3．命令参数：</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　必要参数:</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　　　-c 显示更改的部分的信息</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　　　-f 忽略错误信息</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　　　-h 修复符号链接</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　　　-R 处理指定目录以及其子目录下的所有文件</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　　　-v 显示详细的处理信息</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　　　-deference 作用于符号链接的指向，而不是链接文件本身</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　选择参数:</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　　　--reference=&lt;目录或文件&gt; 把指定的目录/文件作为参考，把操作的文件/目录设置成参考文件/目录相同拥有者和群组</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　　　--from=&lt;当前用户：当前群组&gt; 只有当前用户和群组跟指定的用户和群组相同时才进行改变</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　　　--help 显示帮助信息</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　　　--version 显示版本信息</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　4．使用实例：</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　实例1：改变拥有者和群组</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　命令：</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　　　chown mail:mail log2012.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　输出：　　</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">[root@localhost test6]# ll</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">---xr--r-- 1 root users 302108 11-30 08:39 linklog.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">---xr--r-- 1 root users 302108 11-30 08:39 log2012.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; 61 11-30 08:39 log2013.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2014.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2015.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2016.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2017.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">[root@localhost test6]# chown mail:mail log2012.log&nbsp;</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">[root@localhost test6]# ll</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">---xr--r-- 1 root users 302108 11-30 08:39 linklog.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">---xr--r-- 1 mail mail &nbsp;302108 11-30 08:39 log2012.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; 61 11-30 08:39 log2013.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2014.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2015.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2016.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2017.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">[root@localhost test6]#</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　说明：</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　实例2：改变文件拥有者和群组</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　命令：</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　　　chown root: log2012.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　输出：　　　　</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">[root@localhost test6]# ll</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">总计 604</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">---xr--r-- 1 root users 302108 11-30 08:39 linklog.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">---xr--r-- 1 mail mail &nbsp;302108 11-30 08:39 log2012.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; 61 11-30 08:39 log2013.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2014.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2015.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2016.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2017.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">[root@localhost test6]# chown root: log2012.log&nbsp;</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">[root@localhost test6]# ll</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">总计 604</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">---xr--r-- 1 root users 302108 11-30 08:39 linklog.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">---xr--r-- 1 root root &nbsp;302108 11-30 08:39 log2012.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; 61 11-30 08:39 log2013.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2014.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2015.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2016.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2017.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">[root@localhost test6]#</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　说明：</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　实例3：改变文件群组</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　命令：</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　　　chown :mail log2012.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　输出：　　</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">[root@localhost test6]# ll</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">总计 604</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">---xr--r-- 1 root users 302108 11-30 08:39 linklog.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">---xr--r-- 1 root root &nbsp;302108 11-30 08:39 log2012.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; 61 11-30 08:39 log2013.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2014.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2015.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2016.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2017.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">[root@localhost test6]# chown :mail log2012.log&nbsp;</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">[root@localhost test6]# ll</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">总计 604</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">---xr--r-- 1 root users 302108 11-30 08:39 linklog.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">---xr--r-- 1 root mail &nbsp;302108 11-30 08:39 log2012.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; 61 11-30 08:39 log2013.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2014.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2015.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2016.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root users &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2017.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　说明：</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　实例4：改变指定目录以及其子目录下的所有文件的拥有者和群组&nbsp;</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　命令：</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　　　chown -R -v root:mail test6</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">　　输出：　　</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;"><br /></span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">[root@localhost test]# ll</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">drwxr-xr-x 2 root users &nbsp; 4096 11-30 08:39 test6</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">[root@localhost test]# chown -R -v root:mail test6</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">&#8220;test6/log2014.log&#8221; 的所有者已更改为 root:mail</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">&#8220;test6/linklog.log&#8221; 的所有者已更改为 root:mail</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">&#8220;test6/log2015.log&#8221; 的所有者已更改为 root:mail</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">&#8220;test6/log2013.log&#8221; 的所有者已更改为 root:mail</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">&#8220;test6/log2012.log&#8221; 的所有者已保留为 root:mail</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">&#8220;test6/log2017.log&#8221; 的所有者已更改为 root:mail</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">&#8220;test6/log2016.log&#8221; 的所有者已更改为 root:mail</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">&#8220;test6&#8221; 的所有者已更改为 root:mail</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">[root@localhost test]# ll</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">drwxr-xr-x 2 root mail &nbsp; 4096 11-30 08:39 test6</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">[root@localhost test]# cd test6</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">[root@localhost test6]# ll</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">总计 604</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">---xr--r-- 1 root mail 302108 11-30 08:39 linklog.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">---xr--r-- 1 root mail 302108 11-30 08:39 log2012.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root mail &nbsp; &nbsp; 61 11-30 08:39 log2013.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root mail &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2014.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root mail &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2015.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root mail &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2016.log</span></span></div><div><span style="font-size: 13px; line-height: 23px;"><span class="Apple-style-span" style="font-weight: normal;">-rw-r--r-- 1 root mail &nbsp; &nbsp; &nbsp;0 11-30 08:39 log2017.log</span></span></div></div></h1></div><img src ="http://www.blogjava.net/jjshcc/aggbug/406445.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2013-11-17 21:21 <a href="http://www.blogjava.net/jjshcc/archive/2013/11/17/406445.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux下configure命令详细介绍</title><link>http://www.blogjava.net/jjshcc/archive/2013/06/30/401082.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Sun, 30 Jun 2013 05:42:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2013/06/30/401082.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/401082.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2013/06/30/401082.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/401082.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/401082.html</trackback:ping><description><![CDATA[<div><span style="font-size: 12px;">Linux环境下的软件安装，并不是一件容易的事情;如果通过源代码编译后在安装，当然事情就更为复杂一些;现在安装各种软件的教程都非常普遍;但万变不离其中，对基础知识的扎实掌握，安装各种软件的问题就迎刃而解了。Configure脚本配置工具就是基础之一，它是autoconf的工具的基本应用。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">与一些技巧相比，Configure显得基础一些，当然使用和学习起来就显得枯燥乏味一些，当然要成为高手，对基础的熟悉不能超越哦。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">为此我转载了一篇关于Configure选项配置的详细介绍。供大家参考</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">'configure'脚本有大量的命令行选项.对不同的软件包来说,这些选项可能会有变化,但是许多基本的选项是不会改变的.带上'--help'选项执行'configure'脚本可以看到可用的所有选项.尽管许多选项是很少用到的,但是当你为了特殊的需求而configure一个包时,知道他们的存在是很有益处的.下面对每一个选项进行简略的介绍:</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--cache-file=FILE</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">'configure'会在你的系统上测试存在的特性(或者bug!).为了加速随后进行的配置,测试的结果会存储在一个cache file里.当configure一个每个子树里都有'configure'脚本的复杂的源码树时,一个很好的cache file的存在会有很大帮助.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--help</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">输出帮助信息.即使是有经验的用户也偶尔需要使用使用'--help'选项,因为一个复杂的项目会包含附加的选项.例如,GCC包里的'configure'脚本就包含了允许你控制是否生成和在GCC中使用GNU汇编器的选项.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--no-create</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">'configure'中的一个主要函数会制作输出文件.此选项阻止'configure'生成这个文件.你可以认为这是一种演习(dry run),尽管缓存(cache)仍然被改写了.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--quiet</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--silent</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">当'configure'进行他的测试时,会输出简要的信息来告诉用户正在作什么.这样作是因为'configure'可能会比较慢,没有这种输出的话用户将会被扔在一旁疑惑正在发生什么.使用这两个选项中的任何一个都会把你扔到一旁.(译注:这两句话比较有意思,原文是这样的:If there was no such output, the user would be left wondering what is happening. By using this option, you too can be left wondering!)</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--version</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">打印用来产生'configure'脚本的Autoconf的版本号.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--prefix=PEWFIX</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">'--prefix'是最常用的选项.制作出的'Makefile'会查看随此选项传递的参数,当一个包在安装时可以彻底的重新安置他的结构独立部分. 举一个例子,当安装一个包,例如说Emacs,下面的命令将会使Emacs Lisp file被安装到"/opt/gnu/share":</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">$ ./configure --prefix=/opt/gnu</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--exec-prefix=EPREFIX</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">与'--prefix'选项类似,但是他是用来设置结构倚赖的文件的安装位置.编译好的'emacs'二进制文件就是这样一个问件.如果没有设置这个选项的话,默认使用的选项值将被设为和'--prefix'选项值一样.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--bindir=DIR</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定二进制文件的安装位置.这里的二进制文件定义为可以被用户直接执行的程序.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--sbindir=DIR</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定超级二进制文件的安装位置.这是一些通常只能由超级用户执行的程序.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--libexecdir=DIR</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定可执行支持文件的安装位置.与二进制文件相反,这些文件从来不直接由用户执行,但是可以被上面提到的二进制文件所执行.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--datadir=DIR</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定通用数据文件的安装位置.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--sysconfdir=DIR</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定在单个机器上使用的只读数据的安装位置.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--sharedstatedir=DIR</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定可以在多个机器上共享的可写数据的安装位置.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--localstatedir=DIR</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定只能单机使用的可写数据的安装位置.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--libdir=DIR</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定库文件的安装位置.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--includedir=DIR</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定C头文件的安装位置.其他语言如C++的头文件也可以使用此选项.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--oldincludedir=DIR</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定为除GCC外编译器安装的C头文件的安装位置.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--infodir=DIR</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定Info格式文档的安装位置.Info是被GNU工程所使用的文档格式.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--mandir=DIR</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定手册页的安装位置.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--srcdir=DIR</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">这个选项对安装没有作用.他会告诉'configure'源码的位置.一般来说不用指定此选项,因为'configure'脚本一般和源码文件在同一个目录下.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--program-prefix=PREFIX</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定将被加到所安装程序的名字上的前缀.例如,使用'--program-prefix=g'来configure一个名为'tar'的程序将会使安装的程序被命名为'gtar'.当和其他的安装选项一起使用时,这个选项只有当他被`Makefile.in'文件使用时才会工作.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--program-suffix=SUFFIX</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定将被加到所安装程序的名字上的后缀.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--program-transform-name=PROGRAM</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">这里的PROGRAM是一个sed脚本.当一个程序被安装时,他的名字将经过`sed -e PROGRAM'来产生安装的名字.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--build=BUILD</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定软件包安装的系统平台.如果没有指定,默认值将是'--host'选项的值.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--host=HOST</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定软件运行的系统平台.如果没有指定,将会运行`config.guess'来检测.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--target=GARGET</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定软件面向(target to)的系统平台.这主要在程序语言工具如编译器和汇编器上下文中起作用.如果没有指定,默认将使用'--host'选项的值.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--disable-FEATURE</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">一些软件包可以选择这个选项来提供为大型选项的编译时配置,例如使用Kerberos认证系统或者一个实验性的编译器最优配置.如果默认是提供这些特性,可以使用'--disable-FEATURE'来禁用它,这里'FEATURE'是特性的名字.例如:</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">$ ./configure --disable-gui</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">-enable-FEATURE[=ARG]</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">相反的,一些软件包可能提供了一些默认被禁止的特性,可以使用'--enable-FEATURE'来起用它.这里'FEATURE'是特性的名字.一个特性可能会接受一个可选的参数.例如:</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">$ ./configure --enable-buffers=128</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">`--enable-FEATURE=no'与上面提到的'--disable-FEATURE'是同义的.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--with-PACKAGE[=ARG]</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">在自由软件社区里,有使用已有软件包和库的优秀传统.当用'configure'来配置一个源码树时,可以提供其他已经安装的软件包的信息.例如,倚赖于Tcl和Tk的BLT器件工具包.要配置BLT,可能需要给'configure'提供一些关于我们把Tcl和Tk装的何处的信息:</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">$ ./configure --with-tcl=/usr/local --with-tk=/usr/local</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">'--with-PACKAGE=no'与下面将提到的'--without-PACKAGE'是同义的.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--without-PACKAGE</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">有时候你可能不想让你的软件包与系统已有的软件包交互.例如,你可能不想让你的新编译器使用GNU ld.通过使用这个选项可以做到这一点:</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">$ ./configure --without-gnu-ld</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--x-includes=DIR</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">这个选项是'--with-PACKAGE'选项的一个特例.在Autoconf最初被开发出来时,流行使用'configure'来作为Imake的一个变通方法来制作运行于X的软件.'--x-includes'选项提供了向'configure'脚本指明包含X11头文件的目录的方法.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">--x-libraries=DIR</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">类似的,'--x-libraries'选项提供了向'configure'脚本指明包含X11库的目录的方法.</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">在源码树中运行'configure'是不必要的同时也是不好的.一个由'configure'产生的良好的'Makefile'可以构筑源码属于另一棵树的软件包.在一个独立于源码的树中构筑派生的文件的好处是很明显的:派生的文件,如目标文件,会凌乱的散布于源码树.这也使在另一个不同的系统或用不同的配置选项构筑同样的目标文件非常困难.建议使用三棵树:一棵源码树(source tree),一棵构筑树(build tree),一棵安装树(install tree).这里有一个很接近的例子,是使用这种方法来构筑GNU malloc包:</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">$ gtar zxf mmalloc-1.0.tar.gz</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">$ mkdir build &amp;&amp; cd build</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">$ ../mmalloc-1.0/configure</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">creating cache ./config.cache</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">checking for gcc... gcc</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">checking whether the C compiler (gcc ) works... yes</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">checking whether the C compiler (gcc ) is a cross-compiler... no</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">checking whether we are using GNU C... yes</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">checking whether gcc accepts -g... yes</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">checking for a BSD compatible install... /usr/bin/install -c</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">checking host system type... i586-pc-linux-gnu</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">checking build system type... i586-pc-linux-gnu</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">checking for ar... ar</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">checking for ranlib... ranlib</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">checking how to run the C preprocessor... gcc -E</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">checking for unistd.h... yes</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">checking for getpagesize... yes</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">checking for working mmap... yes</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">checking for limits.h... yes</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">checking for stddef.h... yes</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">updating cache ../config.cache</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">creating ./config.status</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">这样这棵构筑树就被配置了,下面可以继续构筑和安装这个包到默认的位置'/usr/local':</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">$ make all &amp;&amp; make install</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">一个软件包通过编译源代码安装后，如何完全的卸载??</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">如果原先的source还在的话，很多source的Makefile都有写uninstall规则，直接在Souce里make uninstall就可行，不过碰到无良作者没写的，那一句一句看Makefile里install部分他都干了些什么，然后挨个删除。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">如果source没了.....那就一边郁闷吧</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">到目前为止, 我装的都可以make uninstall.......</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">(因为总是不小心装错地方, 结果就make uninstall&amp;&amp;make clean,然后重新configure......)</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">linux下软件的基本安装和卸载</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">Linux软件的安装和卸载一直是困扰许多新用户的难题。在Windows中，我们可以使用软件自带的安装卸载程序或在控制面板中的&#8220;添加/删除程序&#8221;来实现。与其相类似，在Linux下有一个功能强大的软件安装卸载工具，名为RPM。它可以用来建立、安装、查询、更新、卸载软件。该工具是在命令行下使用的。在Shell的提示符后输入rpm，就可获得该命令的帮助信息。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">软件的安装</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">Linux下软件的安装主要有两种不同的形式。第一种安装文件名为xxx.tar.gz;另一种安装文件名为xxx.i386.rpm。以第一种方式发行的软件多为以源码形式发送的;第二种方式则是直接以二进制形式发送的。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">对于第一种，安装方法如下：</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">1 .首先，将安装文件拷贝至你的目录中。例如，如果你是以root身份登录上的，就将软件拷贝至/root中。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">#cp xxx.tar.gz /root</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">2 .由于该文件是被压缩并打包的,应对其解压缩。命令为：</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">#tar xvzf filename.tar.gz 如果是filename.tar.bz2格式的，应该是tar jxvf filename.tar.bz2来解压</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">3. 执行该命令后，安装文件按路径，解压缩在当前目录下。用ls命令可以看到解压缩后的文件。通常在解压缩后产生的文件中，有&#8220;Install&#8221;的文件。该文件为纯文本文件，详细讲述了该软件包的安装方法。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">4.执行解压缩后产生的一个名为configure的可执行脚本程序。它是用于检查系统是否有编译时所需的库，以及库的版本是否满足编译的需要等安装所需要的系统信息。为随后的编译工作做准备。命令为： #./configure</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">如果您想把软件安装到指定目录，应该用#./configure --prefix=/您自己指定的目录，比如我想把一个mlterm安装到/opt/mlterm目录中，应该如下输入</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">#./configure --prefix=/opt/mlterm</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">5.检查通过后，将生成用于编译的MakeFile文件。此时，可以开始进行编译了。编译的过程视软件的规模和计算机性能的不同，所耗费的时间也不同。命令为： #make。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">6.成功编译后，键入如下的命令开始安装：</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">#make install</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">7.安装完毕，应清除编译过程中产生的临时文件和配置过程中产生的文件。键入如下命令：</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">#make clean</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">#make distclean</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">至此，软件的安装结束。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">对于第二种，其安装方法要简单得多。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">同第一种方式一样，将安装文件拷贝至你的目录中。然后使用rpm来安装该文件。命令如下：</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">#rpm -i filename.i386.rpm</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">rpm将自动将安装文件解包，并将软件安装到缺省的目录下。并将软件的安装信息注册到rpm的数据库中。参数i的作用是使rpm进入安装模式。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">软件的卸载</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">1.软件的卸载主要是使用rpm来进行的。卸载软件首先要知道软件包在系统中注册的名称。键入命令：</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">#rpm -q -a</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">即可查询到当前系统中安装的所有的软件包。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">2. 确定了要卸载的软件的名称，就可以开始实际卸载该软件了。键入命令：</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">#rpm -e [package name]</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">即可卸载软件。参数e的作用是使rpm进入卸载模式。对名为[package name]的软件包进行卸载。由于系统中各个软件包之间相互有依赖关系。如果因存在依赖关系而不能卸载，rpm将给予提示并停止卸载。你可以使用如下的命令来忽略依赖关系，直接开始卸载：</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">#rpm -e [package name] -nodeps</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">忽略依赖关系的卸载可能会导致系统中其它的一些软件无法使用</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">如果想知道rpm包安装到哪里了呢?</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">应该用 #rpm -ql [package name]</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">3.如何卸载用源码包安装的软件?</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">最好是看README和INSTALL ;一般的情况下都有说，但大多软件没有提供源码包的卸载方法;我们可以找到软件的安装点删除。主要看你把它安装在哪了。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">比如：</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">如果安装软件时，指定个目录。这个问题也不会难;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">比如用源码包安装gaim 的</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">#./configure --prefix=/opt/gaim</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">#make</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">#make install</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">如果安装mlterm</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">#./configure --prefix=/opt/mlterm</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">#make</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">#make install</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">把源码包安装的软件，都指定安装在 /opt目录中，这样不就知道了??</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">如果删除，就删除相应的软件目录;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">有些软件要在解压安装目录中执行 make uninstall ，这样就卸载掉了</span></div><img src ="http://www.blogjava.net/jjshcc/aggbug/401082.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2013-06-30 13:42 <a href="http://www.blogjava.net/jjshcc/archive/2013/06/30/401082.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DSL(Damn Small Linux) Linux 的root 密码</title><link>http://www.blogjava.net/jjshcc/archive/2013/06/27/400982.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Thu, 27 Jun 2013 01:43:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2013/06/27/400982.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/400982.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2013/06/27/400982.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/400982.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/400982.html</trackback:ping><description><![CDATA[缺省是没有密码的，当然你也就没有办法使用root登录。<br /><br />添加密码的方法为：启动后使用sudo su进入root权限，然后使用passwd进行密码设置，你设置的密码就是以后要使用的密码。<br /><img src ="http://www.blogjava.net/jjshcc/aggbug/400982.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2013-06-27 09:43 <a href="http://www.blogjava.net/jjshcc/archive/2013/06/27/400982.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qume,一个只有50M的Linux虚拟机</title><link>http://www.blogjava.net/jjshcc/archive/2013/06/23/400877.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Sun, 23 Jun 2013 10:51:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2013/06/23/400877.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/400877.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2013/06/23/400877.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/400877.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/400877.html</trackback:ping><description><![CDATA[<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">本软件包不需要安装绝对绿色只要解压后，运行linux.bat这个文件就可以了。</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">qume是一个虚拟机软件。</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">dsl.iso是一个极其精减但又不缺乏应用的linux livecd映像。</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">尽管这个操作系统软件包很小不能体现出linux操作系统极其强大的功能，但</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">麻雀虽小五脏俱全，它是一个完整的操作系统。这也恰恰体现出在linux高效</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">的特性，也绝对能让习惯windows的用户尝一下鲜。</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">本软件包使用很方便，不用安装不用重启，而且可以在Windows 98/NT/2000/XP/2003</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">使用起来也很方便，不用复杂的配置，只要运行里面的一个文件就可以了。</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"></p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"></p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">使用方法</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"></p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">1 运行linux.bat这个文件，会弹出一个窗口，然后你按照窗口出现的英文提示操作</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">便可。</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">2 当你用鼠标操作这个虚拟机时，你会发现鼠标移不出虚拟机的窗口，没关系的只要</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">你同时按下Ctrl+Alt就会把你的鼠标从虚拟机里放出来。</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">3 如果你发现linux的桌面不能完全显示，请在linux桌面单击右键system--Xvesa，</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">选择一个比你windows桌面小的分辨率，这样就可以看到一个完整的linux桌面了。</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">4 如果你的linux不能上网，请根据你的实际情况作一下设置，在linux桌面单击右键</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">system--net setup。</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">5 在linux桌面单击右键Desktop--Styles可以选择左面风格，我很喜欢里面的Tree_</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">and_Moon。</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"></p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"></p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">qume基本参数</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"></p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"></p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">#启动顺序为硬盘</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">-boot c</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">#cdrom的位置</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">-cdrom dsl.iso</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">#使用本地时间</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">-localtime</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">#使用128M内存</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">-m 128</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">#使用网络连接</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">-user-net</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">虚拟机使用声卡</p>
<p style="text-align: left; padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(255,255,255); list-style-type: none; text-indent: 0px; margin: 0px 10px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/26px Helvetica, Tahoma, Arial, sans-serif; white-space: normal; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; text-decoration: none; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">#-enable-audio263<br /><a href="http://download.csdn.net/detail/u011070461/5636425">http://download.csdn.net/detail/u011070461/5636425</a></p><img src ="http://www.blogjava.net/jjshcc/aggbug/400877.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2013-06-23 18:51 <a href="http://www.blogjava.net/jjshcc/archive/2013/06/23/400877.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Apache-WebLogic plub-in插件的安装</title><link>http://www.blogjava.net/jjshcc/archive/2013/06/23/400875.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Sun, 23 Jun 2013 07:50:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2013/06/23/400875.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/400875.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2013/06/23/400875.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/400875.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/400875.html</trackback:ping><description><![CDATA[<p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;"><span style="word-wrap: normal; word-break: normal;">在做大型商务网站时，考虑到为了分担系统负担以及提高系统安全（毕竟Apache是一个非常成熟的WEB服务器）等原因，需要将WebLogic的HTTP Server分离，而使用Apache HTTP Server；这需要安装Apache-WebLogic插件来实现。当客户端请求静态页面时，使用Apache Server，而当客户端请求动态页面时，Apache Server通过插件来使用WebLogic Server；对于客户端来说，WebLogic Server是不可见的，但是却能通过插件来使用WebLogic Server的所有服务。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　目前WebLogic支持aix，hpux11，solaris，linux等操作系统，在weblogic/lib/linux目录（不同的操作系统对应不同的目录）下，有一个共享目标文件mod_wl.so，这个文件需要安装到Apache中，所以要求Apache必须支持DSO（Dynamic Shared Object）；可以通过以下命令来检测你的Apache是否支持：</p><table cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC" border="1" style="margin: 0px; padding: 0px; color: #323e32; font-family: simsun; font-size: 14px;"><tbody><tr><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><pre style="white-space: normal;"><code><strong>Apache_home/bin/httpd -l</strong></code></pre></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　如果在列出的模块名中有mod_so.c，那么你的Apache已经支持so模块，否则需要重新编译Apache，在编译Apache时，需要加以下两个参数：</p><table cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC" border="1" style="margin: 0px; padding: 0px; color: #323e32; font-family: simsun; font-size: 14px;"><tbody><tr><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><pre style="white-space: normal;"><code><strong>./configure --enable-module=so --enable-rule=SHARED_CORE</strong></code></pre></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　接下来是安装mod_wl.so模块，先进入weblogic/lib/linux（假设你的操作系统是linux），用以下命令安装mod_wl.so：</p><table cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC" border="1" style="margin: 0px; padding: 0px; color: #323e32; font-family: simsun; font-size: 14px;"><tbody><tr><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><pre style="white-space: normal;"><code>perl APACHE_HOME/bin/apxs -i -a -n weblogic mod_wl.so</code></pre></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　以上命令执行完后会拷贝mod_wl.so文件到APACHE_HOME/libexec目录中，并在httpd.conf文件中自动增加一行：</p><table cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC" border="1" style="margin: 0px; padding: 0px; color: #323e32; font-family: simsun; font-size: 14px;"><tbody><tr><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><pre style="white-space: normal;"><code><strong>LoadModule&nbsp;</strong><strong>weblogic_module libexec/mod_wl.so</strong></code></pre></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　另外还可以在Apache的httpd.conf文件中设置Apache-WebLogic plug-in的参数，这些参数要包含在</p><table cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC" border="1" style="margin: 0px; padding: 0px; color: #323e32; font-family: simsun; font-size: 14px;"><tbody><tr><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><pre style="white-space: normal;"><code># 参数 值</code></pre></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　中，参数和值之间不能有等号；目前常用的参数有：</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　1，WebLogicHost 域名：设置WebLogic主机的名字</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　2，WebLogicPort 端口号：设置WebLogic主机的端口号</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　3，ConnectTimeoutSecs 秒数：设置服务器连接超时秒数</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　4，ErrorPage URL：如果Apache服务器不能请求WebLogic服务器，将转到你所设置的错误页面</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　如果不设置以上的参数，也可以通过虚拟主机来实现，具体例子如下： #装载模块</p><table cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC" border="1" style="margin: 0px; padding: 0px; color: #323e32; font-family: simsun; font-size: 14px;"><tbody><tr><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><pre style="white-space: normal;"><code>LoadModule&nbsp;<strong style="color: black; background-color: #ffff66;">weblogic_module</strong>&nbsp;libexec/mod_wl.so</code></pre></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　定位目录，这个目录必须和WebLogic Server中的放置.jsp文件的目录一致</p><table cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC" border="1" style="margin: 0px; padding: 0px; color: #323e32; font-family: simsun; font-size: 14px;"><tbody><tr><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　明确指定weblogic模块的操作者</p><table cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC" border="1" style="margin: 0px; padding: 0px; color: #323e32; font-family: simsun; font-size: 14px;"><tbody><tr><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><pre style="white-space: normal;"><code><strong>SetHandler weblogic-handler</strong></code></pre></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　如果请求页面不存在所返回的错误页面</p><table cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC" border="1" style="margin: 0px; padding: 0px; color: #323e32; font-family: simsun; font-size: 14px;"><tbody><tr><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><pre style="white-space: normal;"><code><strong>ErrorPage http://www.weblogic-server.com/error.html</strong></code></pre></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　客户段请求的动态文件，可增加</p><table cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC" border="1" style="margin: 0px; padding: 0px; color: #323e32; font-family: simsun; font-size: 14px;"><tbody><tr><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><pre style="white-space: normal;"><code><strong>MatchExpression *.jsp</strong></code></pre></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　设置虚拟主机</p><table cellspacing="0" cellpadding="5" width="100%" bgcolor="#CCCCCC" border="1" style="margin: 0px; padding: 0px; color: #323e32; font-family: simsun; font-size: 14px;"><tbody><tr><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><pre style="white-space: normal;"><code><strong>NameVirtualHost 10.1.1.6 #WebLogic Server的主机名和端口 WebLogicHost www.weblogic-server.com WebLogicPort 7001 #连接超时秒数 ConnectTimeoutSecs 30</strong></code></pre></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1;">　　现在就可以先启动WebLogic Server再启动Apache Server，就可以测试你的JSP了：</p><img src ="http://www.blogjava.net/jjshcc/aggbug/400875.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2013-06-23 15:50 <a href="http://www.blogjava.net/jjshcc/archive/2013/06/23/400875.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> FreeNAS安装与应用—安装篇</title><link>http://www.blogjava.net/jjshcc/archive/2013/06/22/400858.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Sat, 22 Jun 2013 12:47:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2013/06/22/400858.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/400858.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2013/06/22/400858.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/400858.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/400858.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 一、软件简介&nbsp;2、安装过程&nbsp;&nbsp; &nbsp;&nbsp; FreeNAS是一套免费的NAS服务器，它能将一部普通PC变成网络存储服务器。该软件基于FreeBSD，Samba 及PHP，支持CIFS (samba), FTP, NFS protocols, Software RAID (0,1,5) 及 web 界面的设定工具。用户可通过Windows、Macs...&nbsp;&nbsp;<a href='http://www.blogjava.net/jjshcc/archive/2013/06/22/400858.html'>阅读全文</a><img src ="http://www.blogjava.net/jjshcc/aggbug/400858.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2013-06-22 20:47 <a href="http://www.blogjava.net/jjshcc/archive/2013/06/22/400858.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linu下服务安装配置检查，以SSH为例</title><link>http://www.blogjava.net/jjshcc/archive/2013/06/16/400615.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Sun, 16 Jun 2013 14:34:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2013/06/16/400615.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/400615.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2013/06/16/400615.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/400615.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/400615.html</trackback:ping><description><![CDATA[<span style="font-family: Arial; line-height: 26px; background-color: #ffffff;">#rpm -qa |grep ssh 检查是否装了SSH包</span><br style="font-family: Arial; line-height: 26px; background-color: #ffffff;" /><span style="font-family: Arial; line-height: 26px; background-color: #ffffff;">#chkconfig --list sshd 检查SSHD是否在本运行级别下设置为开机启动</span><br style="font-family: Arial; line-height: 26px; background-color: #ffffff;" /><span style="font-family: Arial; line-height: 26px; background-color: #ffffff;">#chkconfig --level 2345 sshd on&nbsp;&nbsp;如果没设置启动就设置下.</span><br style="font-family: Arial; line-height: 26px; background-color: #ffffff;" /><span style="font-family: Arial; line-height: 26px; background-color: #ffffff;">#service sshd restart&nbsp;&nbsp;重新启动</span><br style="font-family: Arial; line-height: 26px; background-color: #ffffff;" /><span style="font-family: Arial; line-height: 26px; background-color: #ffffff;">#netstat -antp |grep sshd&nbsp;&nbsp;看是否启动了22端口.确认下.</span><br style="font-family: Arial; line-height: 26px; background-color: #ffffff;" /><span style="font-family: Arial; line-height: 26px; background-color: #ffffff;">#iptables -nL&nbsp;&nbsp;看看是否放行了22口.</span><img src ="http://www.blogjava.net/jjshcc/aggbug/400615.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2013-06-16 22:34 <a href="http://www.blogjava.net/jjshcc/archive/2013/06/16/400615.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>