﻿<?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-一江春水向东流-文章分类-LINUX配置，shell</title><link>http://www.blogjava.net/huyi2006/category/27153.html</link><description>专注于网络应用开发，电信增值服务，数据挖掘，通信工程
                                         --武汉---</description><language>zh-cn</language><lastBuildDate>Sat, 05 Apr 2008 09:31:51 GMT</lastBuildDate><pubDate>Sat, 05 Apr 2008 09:31:51 GMT</pubDate><ttl>60</ttl><item><title>linux下通过脚本实现自动重启程序</title><link>http://www.blogjava.net/huyi2006/articles/190902.html</link><dc:creator>胡意</dc:creator><author>胡意</author><pubDate>Sat, 05 Apr 2008 05:35:00 GMT</pubDate><guid>http://www.blogjava.net/huyi2006/articles/190902.html</guid><wfw:comment>http://www.blogjava.net/huyi2006/comments/190902.html</wfw:comment><comments>http://www.blogjava.net/huyi2006/articles/190902.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huyi2006/comments/commentRss/190902.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huyi2006/services/trackbacks/190902.html</trackback:ping><description><![CDATA[
		<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">无论什么程序都不可能完美无缺，理论上，任何程序都有</span>
		<span lang="EN-US">Core Dump</span>
		<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的一天，正式运营的程序，尤其是服务器程序，一旦</span>
		<span lang="EN-US">Core Dump</span>
		<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，后果不堪设想，有过服务器开发经验的朋友，一定都经历过深夜美梦中，被电话惊醒的惨痛经历，手忙脚乱把服务器重新启动，第二天上班还要被老板一顿狠批。所以，程序发生错误时自动重启变得很重要。这里集中讨论</span>
		<span lang="EN-US">linux</span>
		<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">实现自动重启程序的方法。</span>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US">    linux</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下实现程序的自动重启有很多方法，这里我们介绍的是通过自己写脚本来实现，<br /></span>
				<font size="5">
						<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
								<span style="mso-list: Ignore">
										<br />
								</span>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">    <strong>自动重启脚本<br /></strong></span>
				</font>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 15pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<br />假定需要实现重启的程序名为</span>
				<b style="mso-bidi-font-weight: normal">
						<i style="mso-bidi-font-style: normal">
								<span lang="EN-US" style="FONT-SIZE: 12pt">test </span>
						</i>
				</b>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">，我们这里通过判断进程数目来判断程序是否正常。</span>
				<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">
						<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 15pt">
				<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">ps -ef | grep "$1" | grep -v "grep" | wc –l </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">是获取</span>
				<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">$1</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">（本例中为</span>
				<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">test</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">）的进程数，脚本根据进程数来决定下一步的操作。通过一个死循环，每隔</span>
				<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">1</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">秒检查一次系统中的指定程序的进程数。</span>
				<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 15pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">代码如下：<br />    <strong><font size="4">脚本check</font></strong><br /><br /></span>
				<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">
						<o:p>
						</o:p>
				</span>
		</p>
		<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">
				<o:p>
						<div align="center">
								<table class="MsoNormalTable" style="BACKGROUND: #cccccc; WIDTH: 80%; mso-cellspacing: 0cm; mso-padding-alt: 3.75pt 3.75pt 3.75pt 3.75pt" cellspacing="0" cellpadding="0" width="80%" border="1">
										<tbody>
												<tr style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
														<td style="BORDER-RIGHT: #ece9d8; PADDING-RIGHT: 3.75pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 3.75pt; PADDING-BOTTOM: 3.75pt; BORDER-LEFT: #ece9d8; WIDTH: 100%; PADDING-TOP: 3.75pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" width="100%">
																<pre>
																		<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Courier New'">#!/bin/sh</span>
																</pre>
																<pre>
																		<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Courier New'">#------------------------------------------------------------------------------<br /># 函数: CheckProcess<br /># 功能: 检查一个进程是否存在<br /># 参数: $1 --- 要检查的进程名称<br /># 返回: 如果存在返回0, 否则返回1.<br />#------------------------------------------------------------------------------<br />CheckProcess()<br />{<br />  # 检查输入的参数是否有效<br />  if [ "$1" = "" ];<br />  then<br />    return 1<br />  fi<br />  <br />  #$PROCESS_NUM获取指定进程名的数目，为1返回0，表示正常，不为1返回1，表示有错误，需要重新启动<br />  PROCESS_NUM=`ps -ef | grep "$1" | grep -v "grep" | wc -l` <br />  if [ $PROCESS_NUM -eq 1 ];<br />  then<br />    return 0<br />  else<br />    return 1<br />  fi<br />}</span>
																</pre>
																<pre>
																		<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Courier New'"># 检查test实例是否已经存在<br />while [ 1 ] ; do<br /> CheckProcess "test"<br /> CheckQQ_RET=$?<br /> if [ $CheckQQ_RET -eq 1 ];<br /> then<br /><br /># 杀死所有test进程，可换任意你需要执行的操作<br /><br /><br />  killall -9 test<br />  exec ./test &amp;  <br /> fi<br /> sleep 1<br />done</span>
																</pre>
														</td>
												</tr>
										</tbody>
								</table>
						</div>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 15pt">
								<br />
								<br />    <font size="4"><strong>脚本start：</strong></font><br />    加入limit coredumpsize 102400，设置core file的大小，一旦程序Core Dump，有迹可寻。在该脚本中后台执行check脚本，可以省去很多麻烦，<br /></p>
						<div align="center">
								<table class="MsoNormalTable" style="BACKGROUND: #cccccc; WIDTH: 80%; mso-cellspacing: 0cm; mso-padding-alt: 3.75pt 3.75pt 3.75pt 3.75pt" cellspacing="0" cellpadding="0" width="80%" border="1">
										<tbody>
												<tr style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
														<td style="BORDER-RIGHT: #ece9d8; PADDING-RIGHT: 3.75pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 3.75pt; PADDING-BOTTOM: 3.75pt; BORDER-LEFT: #ece9d8; WIDTH: 100%; PADDING-TOP: 3.75pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" width="100%">
																<pre>
																		<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Courier New'">#!/bin/csh<br />limit coredumpsize 102400</span>
																</pre>
																<pre>
																		<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Courier New'">./check &amp;<o:p></o:p></span>
																</pre>
														</td>
												</tr>
										</tbody>
								</table>
						</div>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 15pt">
								<br /> </p>
				</o:p>
		</span>
<img src ="http://www.blogjava.net/huyi2006/aggbug/190902.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huyi2006/" target="_blank">胡意</a> 2008-04-05 13:35 <a href="http://www.blogjava.net/huyi2006/articles/190902.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>设置cron任务</title><link>http://www.blogjava.net/huyi2006/articles/189237.html</link><dc:creator>胡意</dc:creator><author>胡意</author><pubDate>Fri, 28 Mar 2008 04:20:00 GMT</pubDate><guid>http://www.blogjava.net/huyi2006/articles/189237.html</guid><wfw:comment>http://www.blogjava.net/huyi2006/comments/189237.html</wfw:comment><comments>http://www.blogjava.net/huyi2006/articles/189237.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huyi2006/comments/commentRss/189237.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huyi2006/services/trackbacks/189237.html</trackback:ping><description><![CDATA[
		<div>
				<p>设置cron任务</p>
				<p>本文来自redhat官方文档</p>
				<p>Cron是根据月、天、周、时间的组合设定，周期性的执行特定任务的守护程序。 Cron需要系统处于运行状态。如果系统未运行，则计划任务无法被执行。要使用cron服务, 需安装vixie-cron RPM包,也要确保crond处于运行状态。用rpm -q vixie-cron来 测定此软件包是否安装.用/sbin/service crond status来 测定crond是 否处于运行状态。 cron的主要配置文件在以下的/etc/crontab文件中:包 含如下行 </p>
				<pre> SHELL=/bin/bash 
 PATH=/sbin:/bin:/usr/sbin:/usr/bin 
 MAILTO=root 
 HOME=/ 
 # run-parts 
 01 * * * * root run-parts /etc/cron.hourly 
 02 4 * * * root run-parts /etc/cron.daily 
 22 4 * * 0 root run-parts /etc/cron.weekly 
 42 4 1 * * root run-parts /etc/cron.monthly 
</pre>
				<p>前 四行是有关设置cron任 务运行的环境变量. SHELL变 量的值指定系统使用的SHELL环 境(该 样例为bash shell)，PATH变 量定义了执行命令的路径。Cron的 输出以电子邮件的形式发给MSILTO变 量定义的用户名. 如 果MAILTO变 量定义为空字符串(MAILTO=""), 电子邮件不 会被发送. 执 行命令或脚本时HOME变 量可用来设置家目录。 </p>
				<p>文 件/etc/crontab中 每行任务的描述格式如下: </p>
				<p>minute hour day_of_month month day_of_week command </p>
				<ul>
						<li>minute - 从0 到 59的 整数 
</li>
						<li>hour - 从0到23的 整数 
</li>
						<li>day - 从1到31的 整数 (必须是指定月份的有效日期) 
</li>
						<li>month - 从1到12的 整数 (或如Jan或Feb简写的月份) 
</li>
						<li>dayofweek - 从0到7的整数,0或7用来描述周日 (或 用Sun或Mon简 写来表示) 
</li>
						<li>command - 需要执行的命令(可 用as ls /proc &gt;&gt; /tmp/proc或 执行自定义脚本的命令) </li>
				</ul>
				<p>对 于以上各语句,星 号(*)表 示所有可用的值. 例 如,*在 指代month时 表示每月执行（需要符合其他限制条件）该命令。 </p>
				<p>整 数间的连字号(-)表 示整数列,例 如1-4意 思是整数1,2,3,4. </p>
				<p>指 定数值由逗号分开。如：3,4,6,8表 示这四个指定整数. </p>
				<p>符 号“/”指 定步进设置.“/&lt;interger&gt;”表 示步进值。如0-59/2定 义每两分钟执行一次。步进值也可用星号表示。如*/3用 来运行每三个月份运行指定任务. </p>
				<p>以“#”开 头的为注释行,不 会被执行。 </p>
				<p>如 文件/etc/crontab所 示,它 在RUN－PART脚 本中指定系统每小时，每天，每周。每月运行/cron.hourly, /etc/cron.daily, /etc/cron.weekly, 和/etc/cron.monthly中 的文件.这 些目录中的文件为shell脚 本。 </p>
				<p>如 果一个cron任 务需要定期而不是按小时,天,周,月 来执行,则 需要添加/etc/cron.d目 录. 这 个目录下的所有文件和文件/etc/crontab语 法相同. 查 看样例 </p>
				<pre> # record the memory usage of the system every monday 
 # at 3:30AM in the file /tmp/meminfo 
 30 3 * * mon cat /proc/meminfo &gt;&gt; /tmp/meminfo 
 # run custom script the first day of every month at 4:10AM 
 10 4 1 * * /root/scripts/backup.sh 

</pre>
				<p>除 了root用 户之外的用户可以执行crontab配 置计划任务。所有用户定义的crontab存 储在目录/var/spool/cron下, 任 务会以创建者的身份被执行。要以特定用户创建一个crontab, 先 以该用户登录,执 行命令crontab -e, 系统会启动在VISUAL或 者EDITOR中 指定的的编辑软件编辑crontab. 文 件内容与/etc/crontab格 式相同. 当 更改的crontab需 要保存时,文 件会保存在成如下文件/var/spool/cron/username.文 件名会根据用户名而不同。 </p>
				<p>cron 服 务会每分钟检查一次/etc/crontab, /etc/cron.d/, 和/var/spool/cron文 件下的变更.如 果发现变化,就 会下载到存储器中.因 此,即 时crontab文 件改变了,程 序也不需要重新启动。</p>
		</div>
<img src ="http://www.blogjava.net/huyi2006/aggbug/189237.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huyi2006/" target="_blank">胡意</a> 2008-03-28 12:20 <a href="http://www.blogjava.net/huyi2006/articles/189237.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Bash 测试和比较函数 </title><link>http://www.blogjava.net/huyi2006/articles/188617.html</link><dc:creator>胡意</dc:creator><author>胡意</author><pubDate>Tue, 25 Mar 2008 15:51:00 GMT</pubDate><guid>http://www.blogjava.net/huyi2006/articles/188617.html</guid><wfw:comment>http://www.blogjava.net/huyi2006/comments/188617.html</wfw:comment><comments>http://www.blogjava.net/huyi2006/articles/188617.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huyi2006/comments/commentRss/188617.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huyi2006/services/trackbacks/188617.html</trackback:ping><description><![CDATA[
		<blockquote>您是否为 Bash shell 中大量的测试和比较选项而困惑呢？这个技巧可以帮助您解密不同类型的文件、算术和字符串测试，这样您就能够知道什么时候使用 <code>test</code>、 <code>[ ]</code>、 <code>[[ ]]</code>、 <code>(( ))</code> 或 <code>if-then-else</code> 了。</blockquote>
		<!--START RESERVED FOR FUTURE USE INCLUDE FILES-->
		<!-- include java script once we verify teams wants to use this and it will work on dbcs and cyrillic characters -->
		<!--END RESERVED FOR FUTURE USE INCLUDE FILES-->
		<p>Bash shell 在当今的许多 Linux® 和 UNIX® 系统上都可使用，是 Linux 上常见的默认 shell。Bash 包含强大的编程功能，其中包括丰富的可测试文件类型和属性的函数，以及在多数编程语言中可以使用的算术和字符串比较函数。理解不同的测试并认识到 shell 还能把一些操作符解释成 shell 元字符，是成为高级 shell 用户的重要一步。这篇文章摘自 developerWorks 教程 LPI exam 102 prep: Shells, scripting, programming, and compiling，介绍了如何理解和使用 Bash shell 的测试和比较操作。</p>
		<p>这个技巧解释了 shell 测试和比较函数，演示了如何向 shell 添加编程功能。您可能已经看到过使用 &amp;&amp; 和 || 操作符的简单 shell 逻辑，它允许您根据前一条命令的退出状态（正确退出或伴随错误退出）而执行后一条命令。在这个技巧中，将看到如何把这些基本的技术扩展成更复杂的 shell 编程。</p>
		<p>
				<span class="atitle">测试</span>
		</p>
		<p>在任何一种编程语言中，学习了如何给变量分配值和传递参数之后，都需要测试这些值和参数。在 shell 中，测试会设置返回的状态，这与其他命令执行的功能相同。实际上，<code>test</code> 是个内置<i>命令</i>！</p>
		<p>
				<span class="smalltitle">test 和 [</span>
		</p>
		<p>内置命令 <code>test</code> 根据表达式<i>expr</i> 求值的结果返回 0（真）或 1（假）。也可以使用方括号：<code>test <i>expr</i></code> 和 [ <i>expr</i> ] 是等价的。 可以用 <code>$?</code> 检查返回值；可以使用 &amp;&amp; 和 || 操作返回值；也可以用本技巧后面介绍的各种条件结构测试返回值。</p>
		<br />
		<b>清单 1. 一些简单测试</b>
		<br />
		<table cellspacing="0" cellpadding="0" width="75%" border="0">
				<tbody>
						<tr>
								<td class="code-outline">
										<pre class="displaycode">[ian@pinguino ~]$ test 3 -gt 4 &amp;&amp; echo True || echo false
false
[ian@pinguino ~]$ [ "abc" != "def" ];echo $?
0
[ian@pinguino ~]$ test -d "$HOME" ;echo $?
0
</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>在清单 1 的第一个示例中，<code>-gt</code> 操作符对两个字符值之间执行算术比较。在第二个示例中，用 <code>[ ]</code> 的形式比较两个字符串不相等。在最后一个示例中，测试 HOME 变量的值，用单目操作符 <code>-d</code> 检查它是不是目录。</p>
		<p>可以用 <code>-eq</code>、 -<code>ne</code>、<code>-lt</code>、 -<code>le</code>、 -<code>gt</code> 或 -<code>ge</code> 比较算术值，它们分别表示等于、不等于、小于、小于等于、大于、大于等于。 </p>
		<p>可以分别用操作符 <code>=</code>、 <code>!=</code>、<code>&lt;</code> 和 <code>&gt;</code> 比较字符串是否相等、不相等或者第一个字符串的排序在第二个字符串的前面或后面。单目操作符 <code>-z</code> 测试 null 字符串，如果字符串非空 <code>-n</code> 返回 True（或者根本没有操作符）。</p>
		<p>
				<b>说明：</b>shell 也用 <code>&lt;</code> 和 <code>&gt;</code> 操作符进行重定向，所以必须用 <code>\&lt;</code> 或 <code>\&gt;</code> 加以转义。清单 2 显示了字符串测试的更多示例。检查它们是否如您预期的一样。</p>
		<br />
		<b>清单 2. 一些字符串测试</b>
		<br />
		<table cellspacing="0" cellpadding="0" width="75%" border="0">
				<tbody>
						<tr>
								<td class="code-outline">
										<pre class="displaycode">[ian@pinguino ~]$ test "abc" = "def" ;echo $?
1
[ian@pinguino ~]$ [ "abc" != "def" ];echo $?
0
[ian@pinguino ~]$ [ "abc" \&lt; "def" ];echo $?
0
[ian@pinguino ~]$ [ "abc" \&gt; "def" ];echo $?
1
[ian@pinguino ~]$ [ "abc" \&lt;"abc" ];echo $?
1
[ian@pinguino ~]$ [ "abc" \&gt; "abc" ];echo $?
1
</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>表 1 显示了一些更常见的文件测试。如果被测试的文件存在，而且有指定的特征，则结果为 True。</p>
		<table class="data-table-1" cellspacing="0" cellpadding="0" width="50%" summary="" border="0">
				<caption>
						<em>表 1. 一些常见的文件测试</em>
				</caption>
				<tbody>
						<tr valign="top">
								<th valign="bottom">操作符</th>
								<th valign="bottom">特征</th>
						</tr>
						<tr valign="top">
								<td>-d</td>
								<td>目录</td>
						</tr>
						<tr valign="top">
								<td>-e</td>
								<td>存在（也可以用 -a）</td>
						</tr>
						<tr valign="top">
								<td>-f</td>
								<td>普通文件</td>
						</tr>
						<tr valign="top">
								<td>-h</td>
								<td>符号连接（也可以用 -L）</td>
						</tr>
						<tr valign="top">
								<td>-p</td>
								<td>命名管道</td>
						</tr>
						<tr valign="top">
								<td>-r</td>
								<td>可读</td>
						</tr>
						<tr valign="top">
								<td>-s</td>
								<td>非空</td>
						</tr>
						<tr valign="top">
								<td>-S</td>
								<td>套接字</td>
						</tr>
						<tr valign="top">
								<td>-w</td>
								<td>可写</td>
						</tr>
						<tr valign="top">
								<td>-N</td>
								<td>从上次读取之后已经做过修改</td>
						</tr>
				</tbody>
		</table>
		<p>除了上面的单目测试，还可以使用表 2 所示的双目操作符比较两个文件：</p>
		<table class="data-table-1" cellspacing="0" cellpadding="0" width="50%" summary="" border="0">
				<caption>
						<em>表 2. 测试一对文件</em>
				</caption>
				<tbody>
						<tr valign="top">
								<th valign="bottom">操作符</th>
								<th valign="bottom">为 True 的情况 </th>
						</tr>
						<tr valign="top">
								<td>-nt</td>
								<td>测试 file1 是否比 file2 更新。修改日期将用于这次和下次比较。</td>
						</tr>
						<tr valign="top">
								<td>-ot</td>
								<td>测试 file1 是否比 file2 旧。</td>
						</tr>
						<tr valign="top">
								<td>-ef</td>
								<td>测试 file1 是不是 file2 的硬链接。 </td>
						</tr>
				</tbody>
		</table>
		<p>其他一些测试可以用来测试文件许可之类的内容。请参阅 bash 手册获得更多细节或使用 <code>help test</code> 查看内置测试的简要信息。也可以用 <code>help</code> 命令了解其他内置命令。</p>
		<p>
				<code>-o</code> 操作符允许测试利用 <code>set -o <i>选项</i></code> 设置的各种 shell 选项，如果设置了该选项，则返回 True (0)，否则返回 False (1)，如清单 3 所示。</p>
		<br />
		<b>清单 3. 测试 shell 选项</b>
		<br />
		<table cellspacing="0" cellpadding="0" width="75%" border="0">
				<tbody>
						<tr>
								<td class="code-outline">
										<pre class="displaycode">[ian@pinguino ~]$ set +o nounset
[ian@pinguino ~]$ [ -o nounset ];echo $?
1
[ian@pinguino ~]$ set -u
[ian@pinguino ~]$ test  -o nounset; echo $?
0
</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>最后，<code>-a</code> 和 <code>-o</code> 选项允许使用逻辑运算符 AND 和 OR 将表达式组合在一起。单目操作符 <code>!</code> 可以使测试的意义相反。可以用括号把表达式分组，覆盖默认的优先级。请记住 shell 通常要在子 shell 中运行括号中的表达式，所以需要用 \( 和 \) 转义括号，或者把这些操作符括在单引号或双引号内。清单 4 演示了摩根法则在表达式上的应用。</p>
		<br />
		<b>清单 4. 组合和分组测试</b>
		<br />
		<table cellspacing="0" cellpadding="0" width="75%" border="0">
				<tbody>
						<tr>
								<td class="code-outline">
										<pre class="displaycode">[ian@pinguino ~]$ test "a" != "$HOME" -a 3 -ge 4 ; echo $?
1
[ian@pinguino ~]$ [ ! \( "a" = "$HOME" -o 3 -lt 4 \) ]; echo $?
1
[ian@pinguino ~]$ [ ! \( "a" = "$HOME" -o '(' 3 -lt 4 ')' ")" ]; echo $?
1
</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<p>
				<span class="atitle">(( 和 [[</span>
		</p>
		<p>
				<code>test</code> 命令非常强大，但是很难满足其转义需求以及字符串和算术比较之间的区别。幸运的是，bash 提供了其他两种测试方式，这两种方式对熟悉 C、C++ 或 Java® 语法的人来说会更自然些。</p>
		<p>
				<code>(( ))</code>
				<i>复合命令</i> 计算算术表达式，如果表达式求值为 0，则设置退出状态为 1；如果求值为非 0 值，则设置为 0。不需要对 <code>((</code> 和 <code>))</code> 之间的操作符转义。算术只对整数进行。除 0 会产生错误，但不会产生溢出。可以执行 C 语言中常见的算术、逻辑和位操作。 <code>let</code> 命令也能执行一个或多个算术表达式。它通常用来为算术变量分配值。</p>
		<p>
				<br />
				<b>清单 5. 分配和测试算术表达式</b>
				<br />
		</p>
		<table cellspacing="0" cellpadding="0" width="75%" border="0">
				<tbody>
						<tr>
								<td class="code-outline">
										<pre class="displaycode">[ian@pinguino ~]$ let x=2 y=2**3 z=y*3;echo $? $x $y $z
0 2 8 24
[ian@pinguino ~]$ (( w=(y/x) + ( (~ ++x) &amp; 0x0f ) )); echo $? $x $y $w
0 3 8 16
[ian@pinguino ~]$ (( w=(y/x) + ( (~ ++x) &amp; 0x0f ) )); echo $? $x $y $w
0 4 8 13
</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>同使用 <code>(( ))</code> 一样，利用复合命令 <code>[[ ]]</code> 可以对文件名和字符串使用更自然的语法。可以用括号和逻辑操作符把 <code>test</code> 命令支持的测试组合起来。 </p>
		<p>
				<br />
				<b>清单 6. 使用 [[ 复合命令</b>
				<br />
		</p>
		<table cellspacing="0" cellpadding="0" width="75%" border="0">
				<tbody>
						<tr>
								<td class="code-outline">
										<pre class="displaycode">[ian@pinguino ~]$ [[ ( -d "$HOME" ) &amp;&amp; ( -w "$HOME" ) ]] &amp;&amp;  
&gt;  echo "home is a writable directory"
home is a writable directory
</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>在使用 <code>=</code> 或 <code>!=</code> 操作符时，复合命令 <code>[[</code> 还能在字符串上进行模式匹配。匹配的方式就像清单 7 所示的通配符匹配。</p>
		<p>
				<br />
				<b>清单 7. 用 [[ 进行通配符测试</b>
				<br />
		</p>
		<table cellspacing="0" cellpadding="0" width="75%" border="0">
				<tbody>
						<tr>
								<td class="code-outline">
										<pre class="displaycode">[ian@pinguino ~]$ [[ "abc def .d,x--" == a[abc]*\ ?d* ]]; echo $?
0
[ian@pinguino ~]$ [[ "abc def c" == a[abc]*\ ?d* ]]; echo $?
1
[ian@pinguino ~]$ [[ "abc def d,x" == a[abc]*\ ?d* ]]; echo $?
1
</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>甚至还可以在 <code>[[</code> 复合命令内执行算术测试，但是千万要小心。除非在 <code>((</code> 复合命令内，否则 <code>&lt;</code> 和 <code>&gt;</code> 操作符会把操作数当成字符串比较并在当前排序序列中测试它们的顺序。清单 8 用一些示例演示了这一点。</p>
		<p>
				<br />
				<b>清单 8. 用 [[ 包含算术测试</b>
				<br />
		</p>
		<table cellspacing="0" cellpadding="0" width="75%" border="0">
				<tbody>
						<tr>
								<td class="code-outline">
										<pre class="displaycode">[ian@pinguino ~]$ [[ "abc def d,x" == a[abc]*\ ?d* || (( 3 &gt; 2 )) ]]; echo $?
0
[ian@pinguino ~]$ [[ "abc def d,x" == a[abc]*\ ?d* || 3 -gt 2 ]]; echo $?
0
[ian@pinguino ~]$ [[ "abc def d,x" == a[abc]*\ ?d* || 3 &gt; 2 ]]; echo $?
0
[ian@pinguino ~]$ [[ "abc def d,x" == a[abc]*\ ?d* || a &gt; 2 ]]; echo $?
0
[ian@pinguino ~]$ [[ "abc def d,x" == a[abc]*\ ?d* || a -gt 2 ]]; echo $?
-bash: a: unbound variable
</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<p>
				<span class="atitle">条件测试</span>
		</p>
		<p>虽然使用以上的测试和 <code>&amp;&amp;</code>、 <code>||</code> 控制操作符能实现许多编程，但 bash 还包含了更熟悉的 “if, then, else” 和 case 结构。学习完这些之后，将学习循环结构，这样您的工具箱将真正得到扩展。</p>
		<p>
				<span class="smalltitle">If、then、else 语句</span>
		</p>
		<p>bash 的 <code>if</code> 命令是个复合命令，它测试一个测试或命令（<code>$?</code>）的返回值，并根据返回值为 True（0）或 False（不为 0）进行分支。虽然上面的测试只返回 0 或 1 值，但命令可能返回其他值。请参阅 LPI exam 102 prep: Shells, scripting, programming, and compiling 教程学习这方面的更多内容。</p>
		<p>Bash 中的 <code>if</code> 命令有一个 <code>then</code> 子句，子句中包含测试或命令返回 0 时要执行的命令列表，可以有一个或多个可选的 <code>elif</code> 子句，每个子句可执行附加的测试和一个 <code>then</code> 子句，子句中又带有相关的命令列表，最后是可选的 <code>else</code> 子句及命令列表，在前面的测试或 <code>elif</code> 子句中的所有测试都不为真的时候执行，最后使用 <code>fi</code> 标记表示该结构结束。 </p>
		<p>使用迄今为止学到的东西，现在能够构建简单的计算器来计算算术表达式，如清单 9 所示：</p>
		<p>
				<br />
				<b>清单 9. 用 if、then、else 计算表达式</b>
				<br />
		</p>
		<table cellspacing="0" cellpadding="0" width="75%" border="0">
				<tbody>
						<tr>
								<td class="code-outline">
										<pre class="displaycode">[ian@pinguino ~]$ function mycalc ()
&gt; {
&gt;   local x
&gt;   if [ $# -lt 1 ]; then
&gt;     echo "This function evaluates arithmetic for you if you give it some"
&gt;   elif (( $* )); then
&gt;     let x="$*"
&gt;     echo "$* = $x"
&gt;   else
&gt;     echo "$* = 0 or is not an arithmetic expression"
&gt;   fi
&gt; }
[ian@pinguino ~]$ mycalc 3 + 4
3 + 4 = 7
[ian@pinguino ~]$ mycalc 3 + 4**3
3 + 4**3 = 67
[ian@pinguino ~]$ mycalc 3 + (4**3 /2)
-bash: syntax error near unexpected token `('
[ian@pinguino ~]$ mycalc 3 + "(4**3 /2)"
3 + (4**3 /2) = 35
[ian@pinguino ~]$ mycalc xyz
xyz = 0 or is not an arithmetic expression
[ian@pinguino ~]$ mycalc xyz + 3 + "(4**3 /2)" + abc
xyz + 3 + (4**3 /2) + abc = 35
        </pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>这个计算器利用 <code>local</code> 语句将 x 声明为局部变量，只能在 <code>mycalc</code> 函数的范围内使用。<code>let</code> 函数具有几个可用的选项，可以执行与它密切关联的 <code>declare</code> 函数。请参考 bash 手册或使用 <code>help let</code> 获得更多信息。</p>
		<p>如清单 9 所示，需要确保在表达式使用 shell 元字符 —— 例如(、)、*、&gt; 和 &lt; 时 —— 正确地对表达式转义。无论如何，现在有了一个非常方便的小计算器，可以像 shell 那样进行算术计算。</p>
		<p>在清单 9 中可能注意到 <code>else</code> 子句和最后的两个示例。可以看到，把 <code>xyz</code> 传递给 mycalc 并没有错误，但计算结果为 0。这个函数还不够灵巧，不能区分最后使用的示例中的字符值，所以不能警告用户。可以使用字符串模式匹配测试（例如 <br /><code>[[ ! ("$*" == *[a-zA-Z]* ]]</code><br />，或使用适合自己范围的形式）消除包含字母表字符的表达式，但是这会妨碍在输入中使用 16 进制标记，因为使用 16 进制标记时可能要用 0x0f 表示 15。实际上，shell 允许的基数最高为 64（使用 <code><i>base</i>#<i>value</i></code> 标记），所以可以在输入中加入 _ 和 @ 合法地使用任何字母表字符。8 进制和 16 进制使用常用的标记方式，开头为 0 表示八进制，开头为 0x 或 0X 表示 16 进制。清单 10 显示了一些示例。</p>
		<p>
				<br />
				<b>清单 10. 用不同的基数进行计算</b>
				<br />
		</p>
		<table cellspacing="0" cellpadding="0" width="75%" border="0">
				<tbody>
						<tr>
								<td class="code-outline">
										<pre class="displaycode">[ian@pinguino ~]$ mycalc 015
015 = 13
[ian@pinguino ~]$ mycalc 0xff
0xff = 255
[ian@pinguino ~]$ mycalc 29#37
29#37 = 94
[ian@pinguino ~]$ mycalc 64#1az
64#1az = 4771
[ian@pinguino ~]$ mycalc 64#1azA
64#1azA = 305380
[ian@pinguino ~]$ mycalc 64#1azA_@
64#1azA_@ = 1250840574
[ian@pinguino ~]$ mycalc 64#1az*64**3 + 64#A_@
64#1az*64**3 + 64#A_@ = 1250840574
</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>对输入进行的额外处理超出了本技巧的范围，所以请小心使用这个计算器。</p>
		<p>
				<code>elif</code> 语句非常方便。它允许简化缩进，从而有助于脚本编写。在清单 11 中可能会对 <code>type</code> 命令在 <code>mycalc</code> 函数中的输出感到惊讶。</p>
		<p>
				<br />
				<b>清单 11. Type mycalc</b>
				<br />
		</p>
		<table cellspacing="0" cellpadding="0" width="75%" border="0">
				<tbody>
						<tr>
								<td class="code-outline">
										<pre class="displaycode">[ian@pinguino ~]$ type mycalc
mycalc is a function
mycalc ()
{
    local x;
    if [ $# -lt 1 ]; then
        echo "This function evaluates arithmetic for you if you give it some";
    else
        if (( $* )); then
            let x="$*";
            echo "$* = $x";
        else
            echo "$* = 0 or is not an arithmetic expression";
        fi;
    fi
}
 </pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>当然，也可以只用 <code>$(( <i>表达式</i> ))</code> 和 <code>echo </code>命令进行 shell 算术运算，如清单 12 所示。这样就不必学习关于函数或测试的任何内容，但是请注意 shell 不会解释元字符，例如 *，因此元字符不能在 <code>(( <i>表达式</i> ))</code> 或 <code>[[ <i>表达式</i> ]]</code> 中那样正常发挥作用。 </p>
		<p>
				<br />
				<b>清单 12. 在 shell 中用 echo 和 $(( )) 直接进行计算</b>
				<br />
		</p>
		<table cellspacing="0" cellpadding="0" width="75%" border="0">
				<tbody>
						<tr>
								<td class="code-outline">
										<pre class="displaycode">[ian@pinguino ~]$  echo $((3 + (4**3 /2)))
35
 </pre>
								</td>
						</tr>
				</tbody>
		</table>
<img src ="http://www.blogjava.net/huyi2006/aggbug/188617.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huyi2006/" target="_blank">胡意</a> 2008-03-25 23:51 <a href="http://www.blogjava.net/huyi2006/articles/188617.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>shell 技巧</title><link>http://www.blogjava.net/huyi2006/articles/188614.html</link><dc:creator>胡意</dc:creator><author>胡意</author><pubDate>Tue, 25 Mar 2008 15:09:00 GMT</pubDate><guid>http://www.blogjava.net/huyi2006/articles/188614.html</guid><wfw:comment>http://www.blogjava.net/huyi2006/comments/188614.html</wfw:comment><comments>http://www.blogjava.net/huyi2006/articles/188614.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huyi2006/comments/commentRss/188614.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huyi2006/services/trackbacks/188614.html</trackback:ping><description><![CDATA[kill -9 pid &amp;&gt; /dev/null           <strong>屏蔽标准输出和标准错误输出<br /><br />[root@localhost shell]# echo $BASH_VERSION<br />2.05b.0(1)-release<br />[root@localhost shell]# echo $PATH<br />/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/huyi/bin<br />[root@localhost shell]# $PATH=$HOME:/usr/bin<br />bash: /usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/huyi/bin=/root:/usr/bin: ????<br />[root@localhost shell]# <br />[root@localhost shell]# export PATH<br />[root@localhost shell]# hash<br />hits    command<br />   1    /bin/egrep<br />   1    /bin/bash<br />   1    /bin/cat<br />   1    /bin/cp<br />   1    /bin/stty<br />  15    /bin/ls<br />[root@localhost shell]# $!<br /><br />[root@localhost shell]# echo ${newfruit:-apple} <br />apple<br />[root@localhost shell]# echo ${fruit:-peach}<br />orange<br /><br />[root@localhost shell]# food=grapes<br />[root@localhost shell]# echo ${food:+pears}<br />pears<br />[root@localhost shell]# echo $food<br />grapes<br /><br /></strong><img src ="http://www.blogjava.net/huyi2006/aggbug/188614.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huyi2006/" target="_blank">胡意</a> 2008-03-25 23:09 <a href="http://www.blogjava.net/huyi2006/articles/188614.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>centos 中vim不能显示彩色。</title><link>http://www.blogjava.net/huyi2006/articles/187903.html</link><dc:creator>胡意</dc:creator><author>胡意</author><pubDate>Sat, 22 Mar 2008 08:38:00 GMT</pubDate><guid>http://www.blogjava.net/huyi2006/articles/187903.html</guid><wfw:comment>http://www.blogjava.net/huyi2006/comments/187903.html</wfw:comment><comments>http://www.blogjava.net/huyi2006/articles/187903.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huyi2006/comments/commentRss/187903.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huyi2006/services/trackbacks/187903.html</trackback:ping><description><![CDATA[
		<p>今天用的centos下的vi时不能显示彩色，查看了下有关vi的rpm包有四个<br />[huyi@localhost ~]$ rpm -qa|grep vim<br />vim-enhanced-7.0.109-3.el5.3<br />vim-common-7.0.109-3.el5.3<br />vim-minimal-7.0.109-3.el5.3<br />还少一个包vim-X11-7.0.109-3.el5.3， 用centos的yum -install vim-X11,下载安装后。<br />vi 能正常显示彩色了<br /></p>
<img src ="http://www.blogjava.net/huyi2006/aggbug/187903.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huyi2006/" target="_blank">胡意</a> 2008-03-22 16:38 <a href="http://www.blogjava.net/huyi2006/articles/187903.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>vim 配置</title><link>http://www.blogjava.net/huyi2006/articles/187901.html</link><dc:creator>胡意</dc:creator><author>胡意</author><pubDate>Sat, 22 Mar 2008 08:09:00 GMT</pubDate><guid>http://www.blogjava.net/huyi2006/articles/187901.html</guid><wfw:comment>http://www.blogjava.net/huyi2006/comments/187901.html</wfw:comment><comments>http://www.blogjava.net/huyi2006/articles/187901.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huyi2006/comments/commentRss/187901.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huyi2006/services/trackbacks/187901.html</trackback:ping><description><![CDATA[
		<font size="2">%whereis vim<br />vim: /usr/ports/editors/vim<br /><br />在终端下使用vim进行编辑时，默认情况下，编辑的界面上是没有显示行号、语法高亮度显示、智能缩进等功能的。为了更好的在vim下进行工作，需要手动设置一个配置文件：.vimrc。<br />在启动vim时，当前用户根目录下的.vimrc文件会被自动读取，该文件可以包含一些设置甚至脚本，所以，一般情况下把.vimrc文件创建在当前用户的根目录下比较方便，即创建的命令为：<br />$</font>
		<font color="#0000ff" size="2">vi ~/.vimrc</font>
		<font size="2">
				<br />设置完后<br />$:x 或者 $wq<br />进行保存退出即可。<br />下面给出一个例子，其中列出了经常用到的设置，详细的设置信息请参照参考资料：<br /><br />“双引号开始的行为注释行，下同<br />"<font color="#800000">棕红表示缩写形式</font><br />“去掉讨厌的有关vi一致性模式，避免以前版本的一些bug和局限<br /><font color="#0000ff">set nocompatible</font><br /><br />“显示行号<br /><font color="#0000ff">set nummber   <font color="#800000">(set nu)</font></font><br /><br />“检测文件的类型<br /><font color="#0000ff">filetype on</font><br /><br />“记录历史的行数<br /><font color="#0000ff">set history</font>=1000<br /><br />“背景使用黑色<br /><font color="#0000ff">set background</font>=dark<br /><br />“语法高亮度显示<br /><font color="#0000ff">syntax on</font><br /><br />“下面两行在进行编写代码时，在格式对起上很有用；<br />“第一行，vim使用自动对起，也就是把当前行的对起格式应用到下一行；<br />“第二行，依据上面的对起格式，智能的选择对起方式，对于类似C语言编<br />“写上很有用<br /><font color="#0000ff">set autoindent<br />set smartindent</font><br /><br />“第一行设置tab键为4个空格，第二行设置当行之间交错时使用4个空格<br /><font color="#0000ff">set tabstop=4         <font color="#800000">(set ts=4)</font><br />set shiftwidth=4</font><br /><br />“设置匹配模式，类似当输入一个左括号时会匹配相应的那个右括号<br /><font color="#0000ff">set showmatch</font><br /><br />“去除vim的GUI版本中的toolbar<br /><font color="#0000ff">set guioptions</font>-=T<br /><br />“当vim进行编辑时，如果命令错误，会发出一个响声，该设置去掉响声<br /><font color="#0000ff">set vb t_vb</font>=<br /><br />“在编辑过程中，在右下角显示光标位置的状态行<br /><font color="#0000ff">set ruler</font><br /><br />“默认情况下，寻找匹配是高亮度显示的，该设置关闭高亮显示<br /><font color="#0000ff">set nohls</font><br /><br />“查询时非常方便，如要查找book单词，当输入到/b时，会自动找到第一<br />“个b开头的单词，当输入到/bo时，会自动找到第一个bo开头的单词，依<br />“次类推，进行查找时，使用此设置会快速找到答案，当你找要匹配的单词<br />“时，别忘记回车<br /><font color="#0000ff">set incsearch</font><br /><br />“修改一个文件后，自动进行备份，备份的文件名为原文件名加“~“后缀<br />if has(“vms”)<br />set nobackup<br />else<br />set backup<br />endif<br /><br />如果去除注释后，一个完整的.vimrc配置信息如下所示：<br /><br />set nocompatible<br /><br />set nummber<br /><br />filetype on<br /><br />set history=1000<br /><br />set background=dark<br /><br />syntax on<br /><br />set autoindent<br />set smartindent<br /><br />set tabstop=4<br />set shiftwidth=4<br /><br />set showmatch<br /><br />set guioptions-=T<br /><br />set vb t_vb=<br /><br />set ruler<br /><br />set nohls<br /><br />set incsearch<br /><br />if has(“vms”)<br />set nobackup<br />else<br />set backup<br />endif<br /><br />如果设置完后，发现功能没有起作用，检查一下系统下是否安装了vim-enhanced包，查询命令为：<br />$rpm –q vim-enhanced<br />参考资料：<br /><br />1．vim的完全翻译版在下面连接处可以找到<br />http://vimcdoc.sourceforge.net/<br />可以下栽其中的一个PDF版本，里面介绍的很详细，强烈推荐：）<br />2．更详细的vim信息可以访问：<br />http://www.vim.org<br />3．一个带有英文注释的.vimrc例子<br />http://www.vi-improved.org/vimrc.php<br />主要实现自动缩进，换行等功能。<br />一个很简单的.vimrc<br />主要实现自动缩进，换行等功能。<br />set nocompatible<br />set columns=80<br />set tabstop=4<br />set ruler<br />set noexpandtab<br />set number<br />set ignorecase<br />set wrapmargin=15<br />set cindent<br />set shiftwidth=4<br />syntax on<br /><br />"关掉备份文件<br />set nobackup<br /><br />"暂时没用，留着吧<br />hi CursorLine guibg=LightBlue<br /><br />"高亮当前行<br />set cursorline<br /><br />"设置颜色方案<br />colorscheme torte<br /><br />"显示行号<br />set number<br /><br />"关掉工具条<br />set go=e<br /><br />Windows 和 Linux 下适用，无需更改，除了要重新设置用到的程序路径；<br />GUI 和 Console 或终端下适用，无需更改。<br /><br />可在我的站点上下载/查看： _vimrc, _vimrc.txt, _vimrc.html<br />http://linxiao.li.googlepages.com/vim<br />http://www.leal.cn<br /><br />使用前需要先下载一些 scripts， 见 _vimrc 或 plugin_list.txt, plugin_list.html<br />同上网址。<br /><br />使用前先查看 vimrc 的使用说明。<br /><br />Good Luck！</font>
<img src ="http://www.blogjava.net/huyi2006/aggbug/187901.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huyi2006/" target="_blank">胡意</a> 2008-03-22 16:09 <a href="http://www.blogjava.net/huyi2006/articles/187901.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux 学习笔记，不断添加中</title><link>http://www.blogjava.net/huyi2006/articles/187899.html</link><dc:creator>胡意</dc:creator><author>胡意</author><pubDate>Sat, 22 Mar 2008 07:26:00 GMT</pubDate><guid>http://www.blogjava.net/huyi2006/articles/187899.html</guid><wfw:comment>http://www.blogjava.net/huyi2006/comments/187899.html</wfw:comment><comments>http://www.blogjava.net/huyi2006/articles/187899.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huyi2006/comments/commentRss/187899.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huyi2006/services/trackbacks/187899.html</trackback:ping><description><![CDATA[重启网卡<br /># /etc/init.d/network restart<br /><br />配置网卡<br /># ifconfig eth0 10.8.0.9 netmask 255.255.255.0 <br /><br />linux下添加默认网关<br /># /etc/sysconfig/network-scripts/ifcfg-eth0<br /># /etc/init.d/network restart<br /><br />重启eth0<br />ifconfig eth0 down/up<br /><br />ipaddr add 192.168.1.1/24 edv eth0    添加192.168.1.1/24到eth0网卡<br /><br />改DNS<br />more    /etc/resolv.conf<br /><br />关闭iptables<br />/etc/rc.d/init.d/iptables stop<br /><br />修改启动等级<br />/etc/inittab<img src ="http://www.blogjava.net/huyi2006/aggbug/187899.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huyi2006/" target="_blank">胡意</a> 2008-03-22 15:26 <a href="http://www.blogjava.net/huyi2006/articles/187899.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>bash循环读入文件的每一行并处理</title><link>http://www.blogjava.net/huyi2006/articles/178496.html</link><dc:creator>胡意</dc:creator><author>胡意</author><pubDate>Wed, 30 Jan 2008 04:15:00 GMT</pubDate><guid>http://www.blogjava.net/huyi2006/articles/178496.html</guid><wfw:comment>http://www.blogjava.net/huyi2006/comments/178496.html</wfw:comment><comments>http://www.blogjava.net/huyi2006/articles/178496.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huyi2006/comments/commentRss/178496.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huyi2006/services/trackbacks/178496.html</trackback:ping><description><![CDATA[
		<p>bash循环读入文件的每一行并处理</p>
		<p>cat afile | while read oneline<br />do<br />    echo $oneline<br />done<br />这只是个简单例子，把文件afile的每一行读入，然后显示出来。</p>
		<p>也可以这样(如果行中有空格或者tab则无法使用此方法,不好意思啊,呵呵):<br />for i in `cat afile`<br />do<br />echo $i<br />done<br /></p>
<img src ="http://www.blogjava.net/huyi2006/aggbug/178496.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huyi2006/" target="_blank">胡意</a> 2008-01-30 12:15 <a href="http://www.blogjava.net/huyi2006/articles/178496.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>写了一个简单的防止IP攻击的脚本</title><link>http://www.blogjava.net/huyi2006/articles/178495.html</link><dc:creator>胡意</dc:creator><author>胡意</author><pubDate>Wed, 30 Jan 2008 04:14:00 GMT</pubDate><guid>http://www.blogjava.net/huyi2006/articles/178495.html</guid><wfw:comment>http://www.blogjava.net/huyi2006/comments/178495.html</wfw:comment><comments>http://www.blogjava.net/huyi2006/articles/178495.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huyi2006/comments/commentRss/178495.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huyi2006/services/trackbacks/178495.html</trackback:ping><description><![CDATA[
		<p>写了一个简单的防止IP攻击的脚本<br />由于工作需要我就自己写了一个简单的防止IP攻击的脚本,可以防止linux虚拟主机一些小方面的IP攻击</p>
		<p>系统是基于RHEL的centos,包括3,4,5三个版本,当然自己也初学shell,中间肯定用了很多笨的办法,效果也不一定怎么样,请大家给点意见</p>
		<p>注意:这个脚本是根据apache服务器的server-status和系统的dmesg分析结果进行防范的,所以非apache用户和没有开启server-status的朋友没法使用</p>
		<p>可以在服务器的crontab里设定每一分钟运行一次脚本, <br />复制下面的脚本到autoblock.sh,<br />root用户下# chmod u+x autoblock.sh</p>
		<p>#!/bin/bash<br /># author hao32</p>
		<p># basic setting<br />echo 1 &gt; /proc/sys/net/ipv4/tcp_syncookies</p>
		<p># find  server-status  name<br />ss_name="/usr/local/autoblock"</p>
		<p>if [ -e $ss_name/ss_name ];then<br />ss_n=`cat $ss_name/ss_name`<br />else<br />mkdir /usr/local/autoblock &gt;/dev/null 2&gt;&amp;1<br />cat `locate httpd.conf|grep -E "httpd/conf/httpd.conf$|apache_ssl/conf/httpd.conf$"`\<br />|grep "n /server-status"|cut -d/ -f2|cut -d\&gt; -f1 &gt; $ss_name/ss_name<br />ss_n=`cat $ss_name/ss_name`<br />fi</p>
		<p># block setting<br />#设定排除的IP地址<br />ip_exclude="192.168.1.*|60.195.249.*|222.76.212.*|218.241.156.*|58.215.87.*|218.107.216.110"<br />ip_amou=25<br />ss_url="<a href="http://127.0.0.1/$ss_n?notable">http://127.0.0.1/$ss_n?notable</a>"</p>
		<p>ss_tmp="/tmp/server-status"<br />poss_ip="/tmp/poss_ip"<br />real_ip="/tmp/real_ip"</p>
		<p># block start...<br />if [ -e "$poss_ip" ];then<br />echo "" &gt; $poss_ip<br />fi<br />if [ -e "$real_ip" ];then<br />echo "" &gt; $real_ip<br />fi</p>
		<p># analysedemsg<br />dmesg |grep "short"|awk '{if($4!="From"){print $4} else {print $5}}'|awk -F: '{print $1}'|sort|uniq&gt;$poss_ip</p>
		<p>wget -q -O "$ss_tmp" "$ss_url"</p>
		<p>grep "&lt;i&gt;" $ss_tmp|grep -vE $ip_exclude|awk '{print $1}'|sed 's/&lt;i&gt;//g'|sort|uniq -c\<br />|awk '{if($1&gt;'$ip_amou') print $2}'&gt;&gt;$poss_ip</p>
		<p>#iptables -nvL|grep "DROP  "|awk '{print $8}'|sort|uniq|sed 's/0\/24/*/g'&gt;$rule_ip<br />rule_ip=`iptables -nvL|grep "DROP  "|awk '{print $8}'|sort|uniq|sed 's/0\/24/*/g'|xargs|sed 's/\ /|/g'`<br />if [ -z $rule_ip ];then<br />for i in `cat $poss_ip`<br />do<br />/sbin/iptables -I INPUT -p all -s $i -j DROP<br />done<br />else<br />cat $poss_ip|grep -vE "$rule_ip" &gt; $real_ip<br />for i in `cat $real_ip`<br />do<br />/sbin/iptables -I INPUT -p all -s $i -j DROP<br />done</p>
		<p>fi</p>
<img src ="http://www.blogjava.net/huyi2006/aggbug/178495.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huyi2006/" target="_blank">胡意</a> 2008-01-30 12:14 <a href="http://www.blogjava.net/huyi2006/articles/178495.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【原】linux安装expect终极解决方法</title><link>http://www.blogjava.net/huyi2006/articles/175385.html</link><dc:creator>胡意</dc:creator><author>胡意</author><pubDate>Tue, 15 Jan 2008 02:19:00 GMT</pubDate><guid>http://www.blogjava.net/huyi2006/articles/175385.html</guid><wfw:comment>http://www.blogjava.net/huyi2006/comments/175385.html</wfw:comment><comments>http://www.blogjava.net/huyi2006/articles/175385.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huyi2006/comments/commentRss/175385.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huyi2006/services/trackbacks/175385.html</trackback:ping><description><![CDATA[
		<p>安装总结<br />需要两个安装程序<br />tcl8.4.11<br />expect-5.43<br />首先安装tcl8.4.11<br />Tcl 的 configure 脚本有一个语法错误，下面的命令可以纠正它：<br />sed -i "s/relid'/relid/" configure<br />编译tcl<br />cd unix<br />./configure --prefix=/tools<br />make<br />make install<br />需要的内容都拷贝到/tools目录,<br />！！！！安装完毕完先不要删除源码，以后还要用到<br />将头文件目录export到环境变量，<br />cd ..<br />export TCLPATH='pwd'<br />不晓得为什么我在configure时还是报找不到头文件的错误<br />建一个必须的符号链接<br />ln -sv tclsh8.4 /tools/bin/tclsh</p>
		<p>好了，下面就是编译expect了<br />我用的是<br />./configure --prefix=/tools --with-tcl=/tools/lib --with-x=no<br />如果报<br />checking for Tcl private headers... checking for tclInt.h... no <br />configure: error: Can't find Tcl private headers <br />再添加一个头文件目录参数<br /> --with-tclinclude=../tcl8.4.11/generic<br />脚本运行正常，进行执行make进行编译<br />make<br />编译过程中未出现错误，执行安装：<br />make install</p>
<img src ="http://www.blogjava.net/huyi2006/aggbug/175385.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huyi2006/" target="_blank">胡意</a> 2008-01-15 10:19 <a href="http://www.blogjava.net/huyi2006/articles/175385.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转]在shell脚本中用expect 实现 scp 文件的时候不手动输入密码</title><link>http://www.blogjava.net/huyi2006/articles/175296.html</link><dc:creator>胡意</dc:creator><author>胡意</author><pubDate>Mon, 14 Jan 2008 13:14:00 GMT</pubDate><guid>http://www.blogjava.net/huyi2006/articles/175296.html</guid><wfw:comment>http://www.blogjava.net/huyi2006/comments/175296.html</wfw:comment><comments>http://www.blogjava.net/huyi2006/articles/175296.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huyi2006/comments/commentRss/175296.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huyi2006/services/trackbacks/175296.html</trackback:ping><description><![CDATA[#!/usr/bin/expect -f<br /><br />set password 密码<br /><br />spawn scp 用户名@目标机器ip:拷贝文件的路径 存放本地文件的路径 <br />set timeout 300 <br />expect "用户名@目标机器ip's password:" #注意：这里的“用户名@目标机器ip” 跟上面的一致<br />set timeout 300 <br />send "$password\r"<br />set timeout 300 <br />send "exit\r"<br /><br />expect eof<br /><br />附：scp参数<br />-r：拷贝目录<br />-c：允许压缩<br /><br />一个完整的例子<br /><br />#!/usr/bin/expect -f<br />set password 123456<br />#download<br />spawn scp root@192.168.1.218:/root/a.wmv /home/yangyz/<br />set timeout 300 <br />expect "root@192.168.1.218's password:"<br />set timeout 300 <br />send "$password\r"<br />set timeout 300 <br />send "exit\r"<br />expect eof <br /><br />#upload<br />spawn scp /home/yangyz/abc.sql root@192.168.1.218:/root/test.sql <br />set timeout 300 <br />expect "root@192.168.1.218's password:"<br />set timeout 300 <br />send "$password\r"<br />set timeout 300 <br />send "exit\r"<br />expect eof<br /><br />Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1697005<img src ="http://www.blogjava.net/huyi2006/aggbug/175296.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huyi2006/" target="_blank">胡意</a> 2008-01-14 21:14 <a href="http://www.blogjava.net/huyi2006/articles/175296.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用Squid实现反向代理</title><link>http://www.blogjava.net/huyi2006/articles/169127.html</link><dc:creator>胡意</dc:creator><author>胡意</author><pubDate>Thu, 20 Dec 2007 10:45:00 GMT</pubDate><guid>http://www.blogjava.net/huyi2006/articles/169127.html</guid><wfw:comment>http://www.blogjava.net/huyi2006/comments/169127.html</wfw:comment><comments>http://www.blogjava.net/huyi2006/articles/169127.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huyi2006/comments/commentRss/169127.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huyi2006/services/trackbacks/169127.html</trackback:ping><description><![CDATA[
		<div class="content">
				<p class="MsoNormal">
						<b style="mso-bidi-font-weight: normal">
								<i style="mso-bidi-font-style: normal">
										<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">背景介绍</span>
								</i>
						</b>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">：<span lang="EN-US"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">
								<o:p> </o:p>
						</span>
				</p>
				<p class="MsoNormal">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">
								<span style="mso-tab-count: 1">    </span>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">代理服务器是使用非常普遍的一种将局域网主机联入互联网的一种方式，使用代理上网可以节约紧缺的<span lang="EN-US">IP</span>地址资源，而且可以阻断外部主机对内部主机的访问，使内部网主机免受外部网主机的攻击。但是，如果想让互联网上的主机访问内部网的主机资源（例如：<span lang="EN-US">Web</span>站点），又想使内部网主机免受外部网主机攻击，一般的代理服务是不能实现的，需要使用反向代理来实现。<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">
								<span style="mso-tab-count: 1">    </span>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">本文将详细介绍反向代理服务的概念以及如何利用反向代理服务器提高<span lang="EN-US">WEB</span>服务器的性能和安全性。<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal">
						<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">
								<o:p> </o:p>
						</span>
				</p>
				<p class="MsoNormal" style="MARGIN-LEFT: 36pt; TEXT-INDENT: -36pt; mso-list: l1 level1 lfo5; tab-stops: list 36.0pt">
						<b style="mso-bidi-font-weight: normal">
								<span lang="EN-US" style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体">
										<span style="mso-list: Ignore">一．<span style="FONT: 7pt 'Times New Roman'">       </span></span>
								</span>
						</b>
						<b style="mso-bidi-font-weight: normal">
								<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">反向代理的概念 <span lang="EN-US"><o:p></o:p></span></span>
						</b>
				</p>
				<p class="MsoNormal">
						<b style="mso-bidi-font-weight: normal">
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">
										<o:p> </o:p>
								</span>
						</b>
				</p>
				<p class="MsoNormal" style="TEXT-INDENT: 21pt">
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-bidi-font-size: 10.5pt">什么是反向代理呢？其实，反向代理也就是通常所说的<span lang="EN-US">WEB</span>服务器加速，它是一种通过在繁忙的<span lang="EN-US">WEB</span>服务器和<span lang="EN-US">Internet</span>之间增加一个高速的<span lang="EN-US">WEB</span>缓冲服务器（即：<span lang="EN-US">WEB</span>反向代理服务器）来降低实际的<span lang="EN-US">WEB</span>服务器的负载。典型的结构如下图所示：<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal" style="TEXT-INDENT: 21pt">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-bidi-font-size: 10.5pt">
								<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /?>
								<v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path=" m@4@5 l@4@11@9@11@9@5 xe" filled="f" stroked="f">
										<v:stroke joinstyle="miter">
										</v:stroke>
										<v:formulas>
												<v:f eqn="if lineDrawn pixelLineWidth 0 ">
												</v:f>
												<v:f eqn="sum @0 1 0 ">
												</v:f>
												<v:f eqn="sum 0 0 @1 ">
												</v:f>
												<v:f eqn="prod @2 1 2 ">
												</v:f>
												<v:f eqn="prod @3 21600 pixelWidth ">
												</v:f>
												<v:f eqn="prod @3 21600 pixelHeight ">
												</v:f>
												<v:f eqn="sum @0 0 1 ">
												</v:f>
												<v:f eqn="prod @6 1 2 ">
												</v:f>
												<v:f eqn="prod @7 21600 pixelWidth ">
												</v:f>
												<v:f eqn="sum @8 21600 0 ">
												</v:f>
												<v:f eqn="prod @7 21600 pixelHeight ">
												</v:f>
												<v:f eqn="sum @10 21600 0 ">
												</v:f>
										</v:formulas>
										<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect">
										</v:path>
										<o:lock v:ext="edit" aspectratio="t">
										</o:lock>
								</v:shapetype>
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal" style="TEXT-INDENT: 21pt">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
								<span style="mso-spacerun: yes">
										<img alt="" hspace="0" src="http://www.opendigest.org/showimg.php?iid=6" align="baseline" border="0" /> </span>
						</span>
				</p>
				<p class="MsoNormal" style="TEXT-INDENT: 21pt">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
								<span style="mso-spacerun: yes">
								</span>
						</span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">Web</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">服务器加速（反向代理）是针对<span lang="EN-US">Web</span>服务器提供加速功能的。它作为代理<span lang="EN-US">Cache</span>，但并不针对浏览器用户，而针对一台或多台特定<span lang="EN-US">Web</span>服务器（这也是反向代理名称的由来）。实施反向代理（如上图所示），只要将<span lang="EN-US">Reverse Proxy Cache</span>设备放置在一台或多台<span lang="EN-US">Web</span>服务器前端即可。当互联网用户访问某个<span lang="EN-US">WEB</span>服务器时，通过<span lang="EN-US">DNS</span>服务器解析后的<span lang="EN-US">IP</span>地址是<span lang="EN-US">Reverse Proxy Server</span>的<span lang="EN-US">IP</span>地址<span lang="EN-US">,</span>而非原始<span lang="EN-US">Web</span>服务器的<span lang="EN-US">IP</span>地址<span lang="EN-US">,</span>这时<span lang="EN-US">Reverse Proxy Server</span>设备充当<span lang="EN-US">Web</span>服务器，浏览器可以与它连接，无需再直接与<span lang="EN-US">Web</span>服务器相连。因此，大量<span lang="EN-US">Web</span>服务工作量被卸载到反向代理服务上。不但能够防止外部网主机直接和<span lang="EN-US">web</span>服务器直接通信带来的安全隐患，而且能够很大程度上减轻<span lang="EN-US">web</span>服务器的负担，提高访问速度。</span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-bidi-font-size: 10.5pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-bidi-font-size: 10.5pt">
								<o:p> </o:p>
						</span>
				</p>
				<p class="MsoNormal" style="MARGIN-LEFT: 36pt; TEXT-INDENT: -36pt; mso-list: l1 level1 lfo5; tab-stops: list 36.0pt">
						<b>
								<span lang="EN-US" style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体">
										<span style="mso-list: Ignore">二．<span style="FONT: 7pt 'Times New Roman'">       </span></span>
								</span>
						</b>
						<b>
								<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">反向代理和其它代理的比较<span lang="EN-US"><o:p></o:p></span></span>
						</b>
				</p>
				<p class="MsoNormal">
						<b>
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">
										<o:p> </o:p>
								</span>
						</b>
				</p>
				<p class="MsoNormal">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-bidi-font-size: 10.5pt">
								<span style="mso-tab-count: 1">    </span>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">下面将对几种典型的代理服务作一个简单的比较。</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">在网络上常见的代理服务器有三种：<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal" style="MARGIN-LEFT: 39pt; TEXT-INDENT: -18pt; mso-list: l4 level1 lfo4; tab-stops: list 39.0pt">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体">
								<span style="mso-list: Ignore">1．<span style="FONT: 7pt 'Times New Roman'">  </span></span>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">标准的代理缓冲服务器<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal" style="MARGIN-LEFT: 21pt">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">
								<span style="mso-tab-count: 1">    </span>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">一个标准的代理缓冲服务被用于缓存静态的网页（例如：<span lang="EN-US">html</span>文件和图片文件等）到本地网络上的一台主机上（即代理服务器）。当被缓存的页面被第二次访问的时候，浏览器将直接从本地代理服务器那里获取请求数据而不再向原<span lang="EN-US">web</span>站点请求数据。这样就节省了宝贵的网络带宽，而且提高了访问速度。但是，要想实现这种方式，必须在每一个内部主机的浏览器上明确指明代理服务器的<span lang="EN-US">IP</span>地址和端口号。客户端上网时，每次都把请求送给代理服务器处理，代理服务器根据请求确定是否连接到远程<span lang="EN-US">web</span>服务器获取数据。如果在本地缓冲区有目标文件，则直接将文件传给用户即可。如果没有的话则先取回文件，先在本地保存一份缓冲，然后将文件发给客户端浏览器。<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal" style="MARGIN-LEFT: 39pt; TEXT-INDENT: -18pt; mso-list: l4 level1 lfo4; tab-stops: list 39.0pt">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体">
								<span style="mso-list: Ignore">2．<span style="FONT: 7pt 'Times New Roman'">  </span></span>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">透明代理缓冲服务器<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal" style="MARGIN-LEFT: 21pt">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">
								<span style="mso-tab-count: 1">    </span>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">透明代理缓冲服务和标准代理服务器的功能完全相同。但是，代理操作对客户端的浏览器是透明的（即不需指明代理服务器的<span lang="EN-US">IP</span>和端口）。透明代理服务器阻断网络通信，并且过滤出访问外部的<span lang="EN-US">HTTP</span>（<span lang="EN-US">80</span>端口）流量。如果客户端的请求在本地有缓冲则将缓冲的数据直接发给用户，如果在本地没有缓冲则向远程<span lang="EN-US">web</span>服务器发出请求，其余操作和标准的代理服务器完全相同。对于<span lang="EN-US">Linux</span>操作系统来说，透明代理使用<span lang="EN-US">Iptables</span>或者<span lang="EN-US">Ipchains</span>实现。因为不需要对浏览器作任何设置，所以，透明代理对于<span lang="EN-US">ISP</span>（<span lang="EN-US">Internet</span>服务器提供商）特别有用。<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal" style="MARGIN-LEFT: 39pt; TEXT-INDENT: -18pt; mso-list: l4 level1 lfo4; tab-stops: list 39.0pt">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体">
								<span style="mso-list: Ignore">3．<span style="FONT: 7pt 'Times New Roman'">  </span></span>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">反向代理缓冲服务器<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal" style="MARGIN-LEFT: 21pt">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">
								<span style="mso-spacerun: yes">    </span>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">反向代理是和前两种代理完全不同的一种代理服务。使用它可以降低原始<span lang="EN-US">WEB</span>服务器的负载。反向代理服务器承担了对原始<span lang="EN-US">WEB</span>服务器的静态页面的请求，防止原始服务器过载。它位于本地<span lang="EN-US">WEB</span>服务器和<span lang="EN-US">Internet</span>之间，处理所有对<span lang="EN-US">WEB</span>服务器的请求，组织了<span lang="EN-US">WEB</span>服务器和<span lang="EN-US">Internet</span>的直接通信。如果互联网用户请求的页面在代理服务器上有缓冲的话，代理服务器直接将缓冲内容发送给用户。如果没有缓冲则先向<span lang="EN-US">WEB</span>服务器发出请求，取回数据，本地缓存后再发送给用户。这种方式通过降低了向<span lang="EN-US">WEB</span>服务器的请求数从而降低了<span lang="EN-US">WEB</span>服务器的负载。<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-bidi-font-size: 10.5pt">
								<o:p> </o:p>
						</span>
				</p>
				<p class="MsoNormal">
						<b>
								<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">三．反向代理工作原理<span lang="EN-US"><o:p></o:p></span></span>
						</b>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-bidi-font-size: 10.5pt">
								<span style="mso-tab-count: 1">    </span>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">反向代理服务器位于本地<span lang="EN-US">WEB</span>服务器和<span lang="EN-US">Internet</span>之间<span lang="EN-US">,</span>如下图所示：</span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">
						</span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
						</span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p>
						<span style="FONT-SIZE: 10.5pt; mso-bidi-font-family: Arial">
								<img alt="" hspace="0" src="http://www.opendigest.org/showimg.php?iid=82" align="baseline" border="0" />
						</span>
				</p>
				<p>
						<span style="FONT-SIZE: 10.5pt; mso-bidi-font-family: Arial">当用户浏览器发出一个<span lang="EN-US">HTTP</span>请求时，通过域名解析将请求定向到反向代理服务器（如果要实现多个<span lang="EN-US">WEB</span>服务器的反向代理，需要将多个<span lang="EN-US">WEB</span>服务器的域名都指向反向代理服务器）。由反向代理服务器处理器请求。反向代理一般只缓存可缓冲的数据（比如<span lang="EN-US">html</span>网页和图片等），而一些<span lang="EN-US">CGI</span>脚本程序或者<span lang="EN-US">ASP</span>之类的程序不缓存。它根据从<span lang="EN-US">WEB</span>服务器返回的<span lang="EN-US">HTTP</span>头标记来缓冲静态页面。有四个最重要<span lang="EN-US">HTTP</span>头标记：<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<ul type="disc">
						<li class="MsoNormal" style="TEXT-ALIGN: left; mso-list: l2 level1 lfo3; tab-stops: list 36.0pt; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto">
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">Last-Modified: </span>
								<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">告诉反向代理页面什么时间被修改</span>
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
										<o:p>
										</o:p>
								</span>
						</li>
						<li class="MsoNormal" style="TEXT-ALIGN: left; mso-list: l2 level1 lfo3; tab-stops: list 36.0pt; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto">
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">Expires: </span>
								<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">告诉反向代理页面什么时间应该从缓冲区中删除</span>
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
										<o:p>
										</o:p>
								</span>
						</li>
						<li class="MsoNormal" style="TEXT-ALIGN: left; mso-list: l2 level1 lfo3; tab-stops: list 36.0pt; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto">
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">Cache-Control: </span>
								<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">告诉反向代理页面是否应该被缓冲</span>
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
										<o:p>
										</o:p>
								</span>
						</li>
						<li class="MsoNormal" style="TEXT-ALIGN: left; mso-list: l2 level1 lfo3; tab-stops: list 36.0pt; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto">
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">Pragma: </span>
								<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">告诉反向代理页面是否应该被缓冲<span lang="EN-US">.</span></span>
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
										<o:p>
										</o:p>
								</span>
						</li>
				</ul>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">例如：在默认情况下，<span lang="EN-US">ASP</span>页面返回<span lang="EN-US">” Cache-control: private.” </span>，所以<span lang="EN-US">ASP</span>页面时不会在反向代理服务器缓存的<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<b style="mso-bidi-font-weight: normal">
								<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">四．</span>
						</b>
						<b>
								<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">代理服务器软件<span lang="EN-US">squid</span>简介</span>
						</b>
						<b style="mso-bidi-font-weight: normal">
								<span lang="EN-US" style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">
										<o:p>
										</o:p>
								</span>
						</b>
				</p>
				<p class="MsoNormal" style="TEXT-INDENT: 21pt">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">Squid Internet Object Cache (Harvest Project</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">的后续版本<span lang="EN-US">) </span>是美国政府大力助的一项研究计划，其目的为解决网络带宽不足的问题，是现在<span lang="EN-US">Unix</span>系统上使用者最多功能也最完整的一套软体。<span lang="EN-US">Apache</span>和<span lang="EN-US">Netscape</span>虽附有相关的<span lang="EN-US">Proxy</span>模块，但因其功能简单而不够普及。有关<span lang="EN-US">squid</span>的详细说明可到<span lang="EN-US">squid</span>网站<span lang="EN-US">(http://www.squid-cache.org)</span>查询。<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal" style="TEXT-INDENT: 21pt">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">Squid</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">最典型的应用是代理局域网的机器联入互联网，它支持现在流行的网络协议。</span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">Squid</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">的另一项非常出色的功能就是实现反向代理功能。</span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-bidi-font-size: 10.5pt">
								<o:p> </o:p>
						</span>
				</p>
				<p class="MsoNormal">
						<b>
								<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">五．使用<span lang="EN-US">Squid</span>配置反向代理（<span lang="EN-US">HTTP </span>加速器）<span lang="EN-US"><o:p></o:p></span></span>
						</b>
				</p>
				<p>
						<span lang="EN-US" style="FONT-SIZE: 10.5pt">
								<span style="mso-tab-count: 1">    </span>
						</span>
						<span style="FONT-SIZE: 10.5pt">通过<span lang="EN-US">squid</span>配置反向代理主要就是配置“<span lang="EN-US">squid.conf</span>”这个配置文件。下面以<span lang="EN-US">Linux</span>操作系统为例进行介绍，其它版本的在<span lang="EN-US">UNIX</span>也同样适用。在<span lang="EN-US">Linux</span>中<span lang="EN-US">squid</span>如果是以源代码方式安装的话，这个文件一般在“<span lang="EN-US">/usr/local/squid/etc/</span>”目录下。如果是系统自带的<span lang="EN-US">squid</span>，一般配置文件在“<span lang="EN-US">/etc/squid/</span>”目录下。<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p style="MARGIN-LEFT: 39pt; TEXT-INDENT: -18pt; mso-list: l1 level2 lfo5; tab-stops: list 39.0pt">
						<span lang="EN-US" style="FONT-SIZE: 10.5pt">
								<span style="mso-list: Ignore">1．<span style="FONT: 7pt 'Times New Roman'">  </span></span>
						</span>
						<span lang="EN-US" style="FONT-SIZE: 10.5pt">Squid</span>
						<span style="FONT-SIZE: 10.5pt">反向代理单个后台<span lang="EN-US">WEB</span>服务器<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p style="MARGIN-LEFT: 21pt">
						<span style="FONT-SIZE: 10.5pt">如果<span lang="EN-US">WEB</span>服务器和反向代理服务器是两台单独的机器（一般的反向代理应该有两块网卡分别连接了内外部网络）。那么，应该修改下面的内容来设置反向代理服务。<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p>
						<i style="mso-bidi-font-style: normal">
								<span lang="EN-US" style="FONT-SIZE: 10.5pt; BACKGROUND: #d9d9d9; mso-bidi-font-family: 'Courier New'; mso-shading: white; mso-pattern: gray-15 auto">http_port 80 # squid</span>
						</i>
						<i style="mso-bidi-font-style: normal">
								<span style="FONT-SIZE: 10.5pt; BACKGROUND: #d9d9d9; mso-bidi-font-family: 'Courier New'; mso-shading: white; mso-pattern: gray-15 auto">监听的端口<span lang="EN-US"><br />httpd_accel_host 172.16.250.250 # </span>内部<span lang="EN-US">WEB</span>服务器的<span lang="EN-US">IP</span>地址<span lang="EN-US"><br />httpd_accel_port 80 # WEB</span>服务器的<span lang="EN-US">IP</span>地址<span lang="EN-US"><br />httpd_accel_single_host on # </span>转发为缓冲的请求到一台单独的机器<span lang="EN-US"><br />httpd_accel_with_proxy on #<br />httpd_accel_uses_host_header off</span></span>
						</i>
						<i style="mso-bidi-font-style: normal">
								<span lang="EN-US" style="FONT-SIZE: 10.5pt; BACKGROUND: #d9d9d9; mso-shading: white; mso-pattern: gray-15 auto">
								</span>
						</i>
						<i style="mso-bidi-font-style: normal">
								<span lang="EN-US" style="FONT-SIZE: 10.5pt; BACKGROUND: #d9d9d9; mso-bidi-font-family: 'Courier New'; mso-shading: white; mso-pattern: gray-15 auto">
										<o:p>
										</o:p>
								</span>
						</i>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">
								<span style="mso-tab-count: 1">    </span>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">如果<span lang="EN-US">WEB</span>服务器和反向代理服务器是同一台机器。那么，应该设置<span lang="EN-US">WEB</span>服务器的监听端口为非<span lang="EN-US">80</span>端口（比如：<span lang="EN-US">81</span>端口）。要修改的内容如下：</span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<i style="mso-bidi-font-style: normal">
								<span lang="EN-US" style="BACKGROUND: #d9d9d9; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 'Courier New'; mso-shading: white; mso-pattern: gray-15 auto">http_port 80 # squid</span>
						</i>
						<i style="mso-bidi-font-style: normal">
								<span style="BACKGROUND: #d9d9d9; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 'Courier New'; mso-shading: white; mso-pattern: gray-15 auto">监听的端口<span lang="EN-US"><br />httpd_accel_host localhost # </span>内部<span lang="EN-US">WEB</span>服务器的<span lang="EN-US">IP</span>地址<span lang="EN-US"><br />httpd_accel_port 81 # WEB</span>服务器的<span lang="EN-US">IP</span>地址<span lang="EN-US"><br />httpd_accel_single_host on # </span>转发为缓冲的请求到一台单独的机器<span lang="EN-US"><br />httpd_accel_with_proxy on #<br />httpd_accel_uses_host_header off</span></span>
						</i>
						<i style="mso-bidi-font-style: normal">
								<span lang="EN-US" style="BACKGROUND: #d9d9d9; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-shading: white; mso-pattern: gray-15 auto">
										<o:p>
										</o:p>
								</span>
						</i>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">下面解释一下配置指令。</span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<b>
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">http_port 80</span>
						</b>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">选项<span lang="EN-US"> http_port </span>指定<span lang="EN-US">squid</span>监听<span lang="EN-US">HTTP</span>请求的端口，一般都设置成<span lang="EN-US">80</span>端口，这样使用户感觉不到反向代理的存在，就像访问真正的<span lang="EN-US">WEB</span>服务器一样。</span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan" align="left">
						<b>
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">httpd_accel_host 172.16.250.250</span>
						</b>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">
						</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">和 </span>
						<b>
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">httpd_accel_port 80</span>
						</b>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">选项<span lang="EN-US">httpd_accel_host </span>和<span lang="EN-US"> httpd_accel_port </span>指定<span lang="EN-US">WEB</span>服务器的<span lang="EN-US">IP</span>地址和端口号，可以根据自己的<span lang="EN-US">WEB</span>服务器的实际情况而定。</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
								<span lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<b>
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">httpd_accel_single_host on</span>
						</b>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">选项</span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">httpd_accel_single_host </span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">为<span lang="EN-US">on </span>时，<span lang="EN-US">squid</span>被设置成仅对单一的<span lang="EN-US">web</span>服务器作反向代理。不考虑<span lang="EN-US">HTTP</span>头信息，<span lang="EN-US">Squid</span>转发所有的未被缓冲的页面请求到这个<span lang="EN-US">web</span>服务器。如果<span lang="EN-US">squid</span>需要做多个<span lang="EN-US">web</span>服务器反向代理，必须将此选项设置为<span lang="EN-US">off</span>，并且使用转向器或者<span lang="EN-US">DNS</span>去映射请求到合适的后台<span lang="EN-US">WEB</span>服务器。</span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<b>
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">httpd_accel_with_proxy on</span>
						</b>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">如果希望<span lang="EN-US">squid</span>既作反向代理服务器又作本地机器的上网代理，需要将<span lang="EN-US" style="mso-bidi-font-weight: bold">httpd_accel_with_proxy</span><span lang="EN-US"></span></span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">改为 </span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">on</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">，默认情况下是<span lang="EN-US">off</span></span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<b>
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">httpd_accel_uses_host_header off</span>
						</b>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">在<span lang="EN-US">HTTP</span>协议<span lang="EN-US">1.1</span>中，<span lang="EN-US">HTTP</span>请求包括一个主机头信息，指定<span lang="EN-US">URL</span>的主机名或者主机的<span lang="EN-US">IP</span>地址。这个选项可以用来完成多个后台<span lang="EN-US">WEB</span>服务器的反向代理功能。</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
						</span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal">
						<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">2</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">．</span>
						<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">Squid</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">反向代理多个后台</span>
						<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">WEB</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">服务器</span>
						<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal">
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们可以用</span>
						<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">Squid</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">反向代理多个后台</span>
						<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">WEB</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">服务器。例如：我们可以配置</span>
						<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">squid</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">同时反向代理</span>
						<span lang="EN-US" style="mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial">www.abc.com, www.xyz.com, www.lmn.com</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">三个后台</span>
						<span lang="EN-US" style="mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial">WEB</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">服务器，示意图如下：</span>
						<b>
								<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">
										<o:p>
										</o:p>
								</span>
						</b>
				</p>
				<p>
						<span lang="EN-US" style="FONT-SIZE: 10.5pt; mso-bidi-font-weight: bold">
								<span style="mso-tab-count: 1">    <img alt="" hspace="0" src="http://www.opendigest.org/showimg.php?iid=83" align="baseline" border="0" /></span>
						</span>
						<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p>
						<span lang="EN-US" style="FONT-SIZE: 10.5pt">Squid</span>
						<span style="FONT-SIZE: 10.5pt">的配置如下：<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<i style="mso-bidi-font-style: normal">
								<span lang="EN-US" style="BACKGROUND: #d9d9d9; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt; mso-shading: white; mso-pattern: gray-15 auto">httpd_accel_host virtual<br />httpd_accel_port 80 <br />httpd_accel_single_host off <br />httpd_accel_uses_host_header on</span>
						</i>
						<i style="mso-bidi-font-style: normal">
								<span lang="EN-US" style="BACKGROUND: #d9d9d9; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-shading: white; mso-pattern: gray-15 auto">
										<o:p>
										</o:p>
								</span>
						</i>
				</p>
				<p>
						<i style="mso-bidi-font-style: normal">
								<span style="FONT-SIZE: 10.5pt; BACKGROUND: #d9d9d9; mso-bidi-font-family: Arial; mso-shading: white; mso-pattern: gray-15 auto">（注意<span lang="EN-US">:</span>编译<span lang="EN-US">Squid</span>时需激活<span lang="EN-US">Internal DNS</span>选项）<span lang="EN-US"><o:p></o:p></span></span>
						</i>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">然后设置设置反响代理需要的域名解析（<span lang="EN-US">Internet</span>用户通过这里解析三个网站的域名）如下：</span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<i style="mso-bidi-font-style: normal">
								<span lang="EN-US" style="BACKGROUND: #d9d9d9; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt; mso-shading: white; mso-pattern: gray-15 auto">www.abc.com 202.102.240.74<br />www.xyz.com 202.102.240.74<br />www.lmn.com 202.102.240.74</span>
						</i>
						<i style="mso-bidi-font-style: normal">
								<span lang="EN-US" style="BACKGROUND: #d9d9d9; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-shading: white; mso-pattern: gray-15 auto">
										<o:p>
										</o:p>
								</span>
						</i>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">使三个域名都指向反向代理服务器的<span lang="EN-US">IP</span>地址<span lang="EN-US">202.102.240.74</span>。<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">下面设置反向代理所需要的<span lang="EN-US">DNS</span>入口信息（即设置内部<span lang="EN-US">DNS</span>，仅仅是<span lang="EN-US">squid</span>在内部使用，<span lang="EN-US">Internet</span>用户不可见）。有两种方法可以设置内部<span lang="EN-US">DNS</span>，使用内部<span lang="EN-US">DNS</span>服务器来解析或者使用<span lang="EN-US">/etc/hosts</span>文件来实现。<span lang="EN-US"><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">使用内部<span lang="EN-US">DNS</span>服务器的资源记录如下：</span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">
								<br />
								<i style="mso-bidi-font-style: normal">
										<span style="BACKGROUND: #d9d9d9; mso-shading: white; mso-pattern: gray-15 auto">www.abc.com IN A 172.16.1.2<br />www.xyz.com IN A 172.16.1.3<br />www.lmn.com IN A 172.16.1.4</span>
								</i>
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="MsoNormal" style="TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align="left">
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">如果使用<span lang="EN-US">/etc/hosts</span>文件来实现内部<span lang="EN-US">DNS</span>（编译时应使用<span lang="EN-US">disable internal dns</span>选项）<span lang="EN-US">,</span>编辑<span lang="EN-US">/etc/hosts</span>文件添加如下条目： <span lang="EN-US"><br /><i style="mso-bidi-font-style: normal"><span style="BACKGROUND: #d9d9d9; mso-shading: white; mso-pattern: gray-15 auto">172.16.1.2 www.abc.com<br />172.16.1.3 www.xyz.com<br />172.16.1.4 www.lmn.com</span></i><o:p></o:p></span></span>
				</p>
				<p class="MsoNormal">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-bidi-font-style: italic; mso-bidi-font-size: 10.5pt">
								<o:p> </o:p>
						</span>
				</p>
				<p class="MsoNormal">
						<b>
								<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-style: italic">结论<span lang="EN-US"><o:p></o:p></span></span>
						</b>
				</p>
				<p class="MsoNormal">
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-bidi-font-style: italic; mso-bidi-font-size: 10.5pt">
								<span style="mso-tab-count: 1">    </span>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-bidi-font-style: italic; mso-bidi-font-size: 10.5pt">通过本文中的论述和相关实例，可以看出，反向代理方式不单是一种<span lang="EN-US">WEB</span>服务器加速器，而且使也一种对外提供<span lang="EN-US">Web</span>发布时使用的有效的防火墙技术，使用它不但能节约紧缺的<span lang="EN-US">IP</span>地址资源，加速<span lang="EN-US">WEB</span>服务器的访问速度，而且能够保护<span lang="EN-US">WEB</span>主机，因此能够适应多种应用场合。</span>
						<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">
								<o:p>
								</o:p>
						</span>
				</p>
		</div>
<img src ="http://www.blogjava.net/huyi2006/aggbug/169127.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huyi2006/" target="_blank">胡意</a> 2007-12-20 18:45 <a href="http://www.blogjava.net/huyi2006/articles/169127.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>添加samba用户</title><link>http://www.blogjava.net/huyi2006/articles/161156.html</link><dc:creator>胡意</dc:creator><author>胡意</author><pubDate>Fri, 16 Nov 2007 15:35:00 GMT</pubDate><guid>http://www.blogjava.net/huyi2006/articles/161156.html</guid><wfw:comment>http://www.blogjava.net/huyi2006/comments/161156.html</wfw:comment><comments>http://www.blogjava.net/huyi2006/articles/161156.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huyi2006/comments/commentRss/161156.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huyi2006/services/trackbacks/161156.html</trackback:ping><description><![CDATA[通过smbpasswd来添加用户，通过读取/etc/passwd文件中存在的用户名<br />smbpasswd  -a linuxsir<br />然后修改 /etc/samba/smbpass.conf配置，<br />重启　service smb restart<img src ="http://www.blogjava.net/huyi2006/aggbug/161156.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huyi2006/" target="_blank">胡意</a> 2007-11-16 23:35 <a href="http://www.blogjava.net/huyi2006/articles/161156.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用光盘及软盘</title><link>http://www.blogjava.net/huyi2006/articles/160363.html</link><dc:creator>胡意</dc:creator><author>胡意</author><pubDate>Tue, 13 Nov 2007 15:17:00 GMT</pubDate><guid>http://www.blogjava.net/huyi2006/articles/160363.html</guid><wfw:comment>http://www.blogjava.net/huyi2006/comments/160363.html</wfw:comment><comments>http://www.blogjava.net/huyi2006/articles/160363.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huyi2006/comments/commentRss/160363.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huyi2006/services/trackbacks/160363.html</trackback:ping><description><![CDATA[在Linux的文字模式下要使用光盘或软盘，并不是只将光盘或软盘放入即可，用户需要运行加载的命令，才可读写数据。所谓加载就是将存储介质(如光盘和软盘)指定成系统中的某个目录(如/mnt/cdrom或mnt/floppy)。通过直接存取此加载目录，即可读写存储介质中的数据。以下就来看看文字模式下的加载及卸载命令。
<p>　　1，加载的mount命令</p><p>　　要使用光盘时先把光盘放入光驱，然后执行加载的mount命令，将光盘加载至系统中:</p><p>　　# mount/dev/cdrom/mnt/cdrom ← 加载光盘</p><p>　　同理，使用软盘之前也需要和光盘一样，必须先加载后才能使用:</p><p>　　# mount/dev/fd0/mut/floppy ← 加载软盘</p><p>　　2，卸载的umount命令</p><p>　　如果不需要使用光盘或软盘，则需先执行卸载命令之后，才能将光盘或软盘退出。范例如下:</p><p>　　# umount / mnt/cdrom ← 光盘卸载</p><p>　　在不使用软盘时执行umount 命令卸载软盘，再将软盘拿出</p><p>　　# umount / mnt/ ← 软盘卸载</p><img src ="http://www.blogjava.net/huyi2006/aggbug/160363.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huyi2006/" target="_blank">胡意</a> 2007-11-13 23:17 <a href="http://www.blogjava.net/huyi2006/articles/160363.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux下NFS(网络文件系统)的建立与配置方法</title><link>http://www.blogjava.net/huyi2006/articles/158685.html</link><dc:creator>胡意</dc:creator><author>胡意</author><pubDate>Tue, 06 Nov 2007 15:56:00 GMT</pubDate><guid>http://www.blogjava.net/huyi2006/articles/158685.html</guid><wfw:comment>http://www.blogjava.net/huyi2006/comments/158685.html</wfw:comment><comments>http://www.blogjava.net/huyi2006/articles/158685.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huyi2006/comments/commentRss/158685.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huyi2006/services/trackbacks/158685.html</trackback:ping><description><![CDATA[网络文件系统（NFS，Network File System）是一种将远程主机上的分区（目录）经网络挂载到本地系统的一种机制，通过对网络文件系统的支持，用户可以在本地系统上像操作本地分区一样来对远程主机的共享分区（目录）进行操作。 
<p>    在嵌入式Linux 的开发过程中，开发者需要在Linux 服务器上进行所有的软件开发，交叉编译后，通用FTP 方式将可执行文件下载到嵌入式系统运行，但这种方式不但效率低下，且无法实现在线的调试。因此，可以通过建立NFS，把Linux 服务器上的特定分区共享到待调试的嵌入式目标系统上，就可以直接在嵌入式目标系统上操作Linux 服务器，同时可以在线对程序进行调试和修改，大大的方便了软件的开发。因此，NFS 的是嵌入式Linux 开发的一个重要的组成部分，本部分内容将详细说明如何配置嵌入式Linux 的NFS 开发环境。 </p><p>    嵌入式Linux 的NFS 开发环境的实现包括两个方面：一是Linux 服务器端的NFS 服务器支持；二是嵌入式目标系统的NFS 客户端的支持。因此，NFS 开发环境的建立需要配置linux 服务器端和嵌入式目标系统端。 </p><p><strong>一、Linux 服务器端NFS 服务器的配置</strong></p><p><br />    以root 身份登陆Linux 服务器，编辑/etc 目录下的共享目录配置文件exports，指定共享目录及权限等。 </p><p>    执行如下命令编辑文件/etc/exports： </p><p>   # vi /etc/exports </p><p>   在该文件里添加如下内容： </p><p>   /home/work 192.168.0.*（rw,sync,no_root_squash） </p><p>   然后保存退出。 </p><p>   添加的内容表示：允许ip 地址范围在192.168.0.*的计算机以读写的权限来访问/home/work 目录。 </p><p>   /home/work 也称为服务器输出共享目录。 </p><p>   括号内的参数意义描述如下： </p><p>   rw：读/写权限，只读权限的参数为ro； </p><p>   sync：数据同步写入内存和硬盘，也可以使用async，此时数据会先暂存于内存中，而不立即写入硬盘。 <br /> <br />   no_root_squash：NFS 服务器共享目录用户的属性，如果用户是 root，那么对于这个共享目录来说就具有 root 的权限。 </p><p>   接着执行如下命令，启动端口映射： </p><p>   # /etc/rc.d/init.d/portmap start </p><p>   最后执行如下命令启动NFS 服务，此时NFS 会激活守护进程，然后就开始监听 Client 端的请求： </p><p>   # /etc/rc.d/init.d/nfs start </p><p>   用户也可以重新启动Linux 服务器，自动启动NFS 服务。 </p><p>   在NFS 服务器启动后，还需要检查Linux 服务器的防火墙等设置（一般需要关闭防火墙服务），确保没有屏蔽掉NFS 使用的端口和允许通信的主机，主要是检查Linux 服务器iptables，ipchains 等选项的设置，以及/etc/hosts.deny，/etc/hosts.allow 文件。 </p><p>   我们首先在Linux 服务器上进行NFS 服务器的回环测试，验证共享目录是否能够被访问。在Linux 服务器上运行如下命令： <br /> <br />   # mount –t nfs 192.168.0.20:/home/work /mnt </p><p>   # ls /mnt </p><p>   命令将Linux 服务器的NFS 输出共享目录挂载到/mnt 目录下，因此，如果NFS 正常工作，应该能够在/mnt 目录看到/home/work 共享目录中的内容。 </p><p><strong>二、嵌入式目标系统NFS 客户端的配置</strong></p><p><br />   在Linux 服务器设置好后，还需要对客户端进行相关配置。在配置内核时选择Load an Alternate Configuration File输入配置文件的路径和文件名添加内核对NFS的支持： </p><p>   选中networking options－》IP:kernel level auloconfiguralion项 </p><p>   选中file systems－》network file systems－》下的root file system on nfs 和nfs file system support重新编译内核下载bootloader和kernel到开发板上 </p><p>    在嵌入式目标系统的Linux Shell 下，执行如下命令来进行NFS 共享目录挂载： </p><p>    # mkdir /mnt/nfs //建立Linux 服务器输出共享目录的挂载点； </p><p>    # mount –t nfs 192.168.0.20:/home/work /mnt/nfs –o nolock </p><p>    # cd /mnt/nfs <br />  <br />    # ls </p><p>    此时，嵌入式目标系统端所显示的内容即为Linux 服务器的输出目录的内容，即Linux 服务器的输出目。 </p><p>    录/home/work 通过NFS 映射到了嵌入式目标系统的/mnt/nfs 目录。用户可以用增/删/修改文件的方式来验证实际效果。mount 命令中的192.168.0.20 为Linux 服务器的IP 地址，/home/work 为Linux 服务器端所配置的共享输出目录，/mnt/nfs 为嵌入式设备上的本地目录。 </p><p>    在开发过程中，来回输入命令非常烦人，我写了两个简单的脚本来完成nfs的启动，挂载。 </p><p>    host启动nfs：<br />    snfs<br />    #!/bin/bash<br />    ifconfig eth0 192.168.0.20<br />    /etc/rc.d/init.d/portmap start<br />    /etc/rc.d/init.d/nfs start<br />    嵌入式目标机挂载nfs：<br />    mnfs：<br /> <br />    #!/bin/sh<br />    mount -t nfs 192.168.0.20:/home/work/nfs /mnt/nfs -o nolock<br />    echo “nfs ok！”</p><img src ="http://www.blogjava.net/huyi2006/aggbug/158685.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huyi2006/" target="_blank">胡意</a> 2007-11-06 23:56 <a href="http://www.blogjava.net/huyi2006/articles/158685.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>