﻿<?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</title><link>http://www.blogjava.net/caojianhua/category/46513.html</link><description>你必须承认，我们生存的这个世界取决于自身的能力而非别人的保护(AW)</description><language>zh-cn</language><lastBuildDate>Thu, 11 Aug 2011 09:32:17 GMT</lastBuildDate><pubDate>Thu, 11 Aug 2011 09:32:17 GMT</pubDate><ttl>60</ttl><item><title>查询系统负载---uptime命令</title><link>http://www.blogjava.net/caojianhua/archive/2011/08/10/356276.html</link><dc:creator>初一七月</dc:creator><author>初一七月</author><pubDate>Wed, 10 Aug 2011 13:49:00 GMT</pubDate><guid>http://www.blogjava.net/caojianhua/archive/2011/08/10/356276.html</guid><wfw:comment>http://www.blogjava.net/caojianhua/comments/356276.html</wfw:comment><comments>http://www.blogjava.net/caojianhua/archive/2011/08/10/356276.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/caojianhua/comments/commentRss/356276.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/caojianhua/services/trackbacks/356276.html</trackback:ping><description><![CDATA[<div><div>Linux系统监控的过程中少不了对主机运行时间和系统负责等信息进行查询，这时候就可以使用Linux uptime命令。uptime命令可以显示系统运行多久、当前有多少的用户登录、在过去的1，5，15分钟里平均负载时多少，其用法十分简单。<br /><br /><div>用法：直接输入uptime即可，以下显示输入uptime的信息：</div><div><div><div>04:03:58 up 10 days, 13:19, &nbsp;1 user, &nbsp;load average: 0.54, 0.40, 0.20</div></div></div></div></div><div><br /><div><div>1.04:03:58 &nbsp;当前时间</div><div>2.10 days, 13:19 系统已运行的时间，时间越大，说明你的机器越稳定</div><div>3.1 user &nbsp;当前在线用户，是总连接数而不是用户数</div><div>4.0.54, 0.40, 0.20最近1分钟、5分钟、15分钟系统的平均负载<br /><br /><div><div>系统平均负载被定义为在特定时间间隔内运行队列中的平均进程数。如果一个进程满足以下条件则其就会位于运行队列中：&nbsp;</div><div>- 它没有在等待I/O操作的结果&nbsp;</div><div>- 它没有主动进入等待状态(也就是没有调用'wait')&nbsp;</div><div>- 没有被停止(例如：等待终止)<br /><div><div></div><div>一般来说，每个CPU内核当前活动进程数不大于3，则系统运行表现良好！当然这里说的是每个cpu内核，也就是如果你的主机是四核cpu的话，那么只要uptime最后输出的一串字符数值小于12即表示系统负载不是很严重，当然如果达到20，那就表示当前系统负载非常严重。<br /><br /><br /></div></div></div></div></div></div></div><img src ="http://www.blogjava.net/caojianhua/aggbug/356276.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/caojianhua/" target="_blank">初一七月</a> 2011-08-10 21:49 <a href="http://www.blogjava.net/caojianhua/archive/2011/08/10/356276.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux开机启动脚本顺序</title><link>http://www.blogjava.net/caojianhua/archive/2011/04/01/347490.html</link><dc:creator>初一七月</dc:creator><author>初一七月</author><pubDate>Fri, 01 Apr 2011 12:30:00 GMT</pubDate><guid>http://www.blogjava.net/caojianhua/archive/2011/04/01/347490.html</guid><wfw:comment>http://www.blogjava.net/caojianhua/comments/347490.html</wfw:comment><comments>http://www.blogjava.net/caojianhua/archive/2011/04/01/347490.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/caojianhua/comments/commentRss/347490.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/caojianhua/services/trackbacks/347490.html</trackback:ping><description><![CDATA[第一步：启动内核<br />
<br />
第二步：执行init （配置文件/etc/inittab）<br />
<br />
第三步：启动相应的脚本，并且打开终端/etc/init.d rc.sysinit rc.d(里面的脚本） rc.local<br />
<br />
第四步：启动login登录界面login<br />
<br />
第五步:在用户登录的时候执行sh脚本的顺序：每次登录的时候都会完全执行的 /etc/profile /etc/bashrc /root/.bashrc /root/.bash_profile<br />
<br />
所以用户自定义的环境变量可以放到第五步的文件里，有些服务(比如作为web服务器的机器的Nginx、Resin服务)，可以放到rc.local中，这样就可以开机自动运行。<br />
<br />
转自http://www.cnblogs.com/feisky/archive/2010/05/30/1747484.html<br />
<img src ="http://www.blogjava.net/caojianhua/aggbug/347490.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/caojianhua/" target="_blank">初一七月</a> 2011-04-01 20:30 <a href="http://www.blogjava.net/caojianhua/archive/2011/04/01/347490.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux 中 crontab 详解及示例(转载)</title><link>http://www.blogjava.net/caojianhua/archive/2011/01/07/342532.html</link><dc:creator>初一七月</dc:creator><author>初一七月</author><pubDate>Fri, 07 Jan 2011 10:30:00 GMT</pubDate><guid>http://www.blogjava.net/caojianhua/archive/2011/01/07/342532.html</guid><wfw:comment>http://www.blogjava.net/caojianhua/comments/342532.html</wfw:comment><comments>http://www.blogjava.net/caojianhua/archive/2011/01/07/342532.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/caojianhua/comments/commentRss/342532.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/caojianhua/services/trackbacks/342532.html</trackback:ping><description><![CDATA[<span style="font-size: 18pt;">
<span style="font-size: 24pt;">
<span style="font-size: 14pt;"><span style="font-size: 24pt;"><span style="font-size: 12pt;">
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">转载自<span style="font-family: Simsun; line-height: normal; font-size: medium;"><a href="http://www.cn-java.com/www1/?uid-560221-action-viewspace-itemid-8377">http://www.cn-java.com/www1/?uid-560221-action-viewspace-itemid-8377</a></span></p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">cron是一个linux下的定时执行工具，可以在无需人工干预的情况下运行作业。由于Cron 是Linux的内置服务，但它不自动起来，可以用以下的方法启动、关闭这个服务：</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">&nbsp;/sbin/service crond start //启动服务&nbsp;<br style="line-height: normal ! important;" />
/sbin/service crond stop //关闭服务&nbsp;<br style="line-height: normal ! important;" />
/sbin/service crond restart //重启服务&nbsp;<br style="line-height: normal ! important;" />
/sbin/service crond reload //重新载入配置</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">你也可以将这个服务在系统启动的时候自动启动：&nbsp;<br style="line-height: normal ! important;" />
在/etc/rc.d/rc.local这个脚本的末尾加上：&nbsp;<br style="line-height: normal ! important;" />
/sbin/service crond start</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">现在Cron这个服务已经在进程里面了，我们就可以用这个服务了，Cron服务提供以下几种接口供大家使用：</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">&nbsp;1、直接用crontab命令编辑</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">&nbsp;cron服务提供crontab命令来设定cron服务的，以下是这个命令的一些参数与说明：</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">crontab -u //设定某个用户的cron服务，一般root用户在执行这个命令的时候需要此参数&nbsp;<br style="line-height: normal ! important;" />
crontab -l //列出某个用户cron服务的详细内容&nbsp;<br style="line-height: normal ! important;" />
crontab -r //删除某个用户的cron服务&nbsp;<br style="line-height: normal ! important;" />
crontab -e //编辑某个用户的cron服务</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;"><br style="line-height: normal ! important;" />
比如说root查看自己的cron设置：crontab -u root -l&nbsp;<br style="line-height: normal ! important;" />
再例如，root想删除fred的cron设置：crontab -u fred -r&nbsp;<br style="line-height: normal ! important;" />
在编辑cron服务时，编辑的内容有一些格式和约定，输入：crontab -u root -e&nbsp;<br style="line-height: normal ! important;" />
进入vi编辑模式，编辑的内容一定要符合下面的格式：*/1 * * * * ls &gt;&gt; /tmp/ls.txt</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">这个格式的前一部分是对时间的设定，后面一部分是要执行的命令，如果要执行的命令太多，可以把这些命令写到一个脚本里面，然后在这里直接调用这个脚本就可以了，调用的时候记得写出命令的完整路径。时间的设定我们有一定的约定，前面五个*号代表五个数字，数字的取值范围和含义如下：</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">&nbsp;分钟 （0-59）&nbsp;<br style="line-height: normal ! important;" />
小時 （0-23）&nbsp;<br style="line-height: normal ! important;" />
日期 （1-31）&nbsp;<br style="line-height: normal ! important;" />
月份 （1-12）&nbsp;<br style="line-height: normal ! important;" />
星期 （0-6）//0代表星期天</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">&nbsp;除了数字还有几个个特殊的符号就是"*"、"/"和"-"、","，*代表所有的取值范围内的数字，"/"代表每的意思,"*/5"表示每5个单位，"-"代表从某个数字到某个数字,","分开几个离散的数字。以下举几个例子说明问题：</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">每天早上6点</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">0 6 * * * echo "Good morning." &gt;&gt; /tmp/test.txt //注意单纯echo，从屏幕上看不到任何输出，因为cron把任何输出都email到root的信箱了。</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">每两个小时</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">0 */2 * * * echo "Have a break now." &gt;&gt; /tmp/test.txt</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">晚上11点到早上8点之间每两个小时，早上八点</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">0 23-7/2，8 * * * echo "Have a good dream：）" &gt;&gt; /tmp/test.txt</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">每个月的4号和每个礼拜的礼拜一到礼拜三的早上11点</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">0 11 4 * 1-3 command line</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">1月1日早上4点</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">0 4 1 1 * command line</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">每次编辑完某个用户的cron设置后，cron自动在/var/spool/cron下生成一个与此用户同名的文件，此用户的cron信息都记录在这个文件中，这个文件是不可以直接编辑的，只可以用crontab -e 来编辑。cron启动后每过一份钟读一次这个文件，检查是否要执行里面的命令。因此此文件修改后不需要重新启动cron服务。</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">2、编辑/etc/crontab 文件配置cron</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">cron服务每分钟不仅要读一次/var/spool/cron内的所有文件，还需要读一次/etc/crontab,因此我们配置这个文件也能运用 cron服务做一些事情。用crontab配置是针对某个用户的，而编辑/etc/crontab是针对系统的任务。此文件的文件格式是：</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">SHELL=/bin/bash</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">PATH=/sbin:/bin:/usr/sbin:/usr/bin</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">MAILTO=root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //如果出现错误，或者有数据输出，数据作为邮件发给这个帐号</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">HOME=/&nbsp;&nbsp;&nbsp; //使用者运行的路径,这里是根目录</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;"># run-parts</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">01 * * * * root run-parts /etc/cron.hourly //每小时执行/etc/cron.hourly内的脚本&nbsp;<br style="line-height: normal ! important;" />
02 4 * * * root run-parts /etc/cron.daily //每天执行/etc/cron.daily内的脚本<br style="line-height: normal ! important;" />
22 4 * * 0 root run-parts /etc/cron.weekly //每星期执行/etc/cron.weekly内的脚本&nbsp;<br style="line-height: normal ! important;" />
42 4 1 * * root run-parts /etc/cron.monthly //每月去执行/etc/cron.monthly内的脚本</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">大家注意"run-parts"这个参数了，如果去掉这个参数的话，后面就可以写要运行的某个脚本名，而不是文件夹名了。</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">--------------------------------------<br style="line-height: normal ! important;" />
基本格式 :<br style="line-height: normal ! important;" />
*  *  *  *  *  command<br style="line-height: normal ! important;" />
分 时 日 月 周 命令</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">第1列表示分钟1～59 每分钟用*或者 */1表示<br style="line-height: normal ! important;" />
第2列表示小时1～23（0表示0点）<br style="line-height: normal ! important;" />
第3列表示日期1～31<br style="line-height: normal ! important;" />
第4列表示月份1～12<br style="line-height: normal ! important;" />
第5列标识号星期0～6（0表示星期天）<br style="line-height: normal ! important;" />
第6列要运行的命令</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">&nbsp;crontab文件的一些例子：</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">&nbsp;30 21 * * * /usr/local/etc/rc.d/lighttpd restart<br style="line-height: normal ! important;" />
上面的例子表示每晚的21:30重启lighttpd 。</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">&nbsp;45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart<br style="line-height: normal ! important;" />
上面的例子表示每月1、10、22日的4 : 45重启lighttpd 。</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">&nbsp;10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart<br style="line-height: normal ! important;" />
上面的例子表示每周六、周日的1 : 10重启lighttpd 。</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">&nbsp;0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart<br style="line-height: normal ! important;" />
上面的例子表示在每天18 : 00至23 : 00之间每隔30分钟重启lighttpd 。</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">&nbsp;0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart<br style="line-height: normal ! important;" />
上面的例子表示每星期六的11 : 00 pm重启lighttpd 。</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">* */1 * * * /usr/local/etc/rc.d/lighttpd restart<br style="line-height: normal ! important;" />
每一小时重启lighttpd</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">&nbsp;* 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart<br style="line-height: normal ! important;" />
晚上11点到早上7点之间，每隔一小时重启lighttpd</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">&nbsp;0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart<br style="line-height: normal ! important;" />
每月的4号与每周一到周三的11点重启lighttpd</p>
<p style="line-height: 1.8em ! important; margin: 10px 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">&nbsp;0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart<br style="line-height: normal ! important;" />
一月一号的4点重启lighttpd</p>
</span></span></span>
</span>
</span>
<img src ="http://www.blogjava.net/caojianhua/aggbug/342532.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/caojianhua/" target="_blank">初一七月</a> 2011-01-07 18:30 <a href="http://www.blogjava.net/caojianhua/archive/2011/01/07/342532.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>