{"id":1147,"date":"2012-09-05T11:51:29","date_gmt":"2012-09-05T03:51:29","guid":{"rendered":"http:\/\/www.strongd.net\/?p=1147"},"modified":"2012-09-05T11:51:29","modified_gmt":"2012-09-05T03:51:29","slug":"linux-%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=1147","title":{"rendered":"linux \u5e38\u7528\u547d\u4ee4"},"content":{"rendered":"<table cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td id=\"postmessage_15560786\">1.\u5220\u96640\u5b57\u8282\u6587\u4ef6<\/p>\n<p>find -type f -size 0 -exec rm -rf {} \\;<\/p>\n<p>2.\u67e5\u770b\u8fdb\u7a0b<\/p>\n<p>\u6309\u5185\u5b58\u4ece\u5927\u5230\u5c0f\u6392\u5217<\/p>\n<p>ps -e -o &#8220;%C : %p : %z : %a&#8221;|sort -k5 -nr<\/p>\n<p>3.\u6309cpu\u5229\u7528\u7387\u4ece\u5927\u5230\u5c0f\u6392\u5217<\/p>\n<p>ps -e -o &#8220;%C : %p : %z : %a&#8221;|sort -nr<\/p>\n<p>4.\u6253\u5370\u8bf4cache\u91cc\u7684URL<\/p>\n<p>grep -r -a jpg \/data\/cache\/* | strings | grep &#8220;http:&#8221; | awk -F&#8217;http:&#8217; &#8216;{print &#8220;http:&#8221;$2;}&#8217;<\/p>\n<p>5.\u67e5\u770bhttp\u7684\u5e76\u53d1\u8bf7\u6c42\u6570\u53ca\u5176TCP\u8fde\u63a5\u72b6\u6001\uff1a<\/p>\n<p>netstat -n | awk &#8216;\/^tcp\/ {++S[$NF]} END {for(a in S) print a, S[a]}&#8217;<\/p>\n<p>6. sed -i &#8216;\/Root\/s\/no\/yes\/&#8217; \/etc\/ssh\/sshd_config sed\u5728\u8fd9\u4e2a\u6587\u91ccRoot\u7684\u4e00\u884c\uff0c\u5339\u914dRoot\u4e00\u884c\uff0c\u5c06no\u66ff\u6362\u6210yes.<\/p>\n<p>7.1.\u5982\u4f55\u6740\u6389mysql\u8fdb\u7a0b\uff1a<\/p>\n<p>ps aux|grep mysql|grep -v grep|awk &#8216;{print $2}&#8217;|xargs kill -9 (\u4ece\u4e2d\u4e86\u89e3\u5230awk\u7684\u7528\u9014)<\/p>\n<p>pgrep mysql |xargs kill -9 [\u7f51\u53cb:&amp;FROST]<\/p>\n<p>killall -TERM mysqld<\/p>\n<p>kill -9 `cat \/usr\/local\/apache2\/logs\/httpd.pid` \u8bd5\u8bd5\u67e5\u6740\u8fdb\u7a0bPID<\/p>\n<p>8.\u663e\u793a\u8fd0\u884c3\u7ea7\u522b\u5f00\u542f\u7684\u670d\u52a1:<\/p>\n<p>ls \/etc\/rc3.d\/S* |cut -c 15- (\u4ece\u4e2d\u4e86\u89e3\u5230cut\u7684\u7528\u9014\uff0c\u622a\u53d6\u6570\u636e)<\/p>\n<p>9.\u5982\u4f55\u5728\u7f16\u5199SHELL\u663e\u793a\u591a\u4e2a\u4fe1\u606f\uff0c\u7528EOF<\/p>\n<p>cat Apache\u7684\u5e76\u53d1\u8bf7\u6c42\u6570\u53ca\u5176TCP\u8fde\u63a5\u72b6\u6001\uff1a<\/p>\n<p>netstat -n | awk &#8216;\/^tcp\/ {++S[$NF]} END {for(a in S) print a, S[a]}&#8217;<\/p>\n<p>15.\u56e0\u4e3a\u540c\u4e8b\u8981\u7edf\u8ba1\u4e00\u4e0b\u670d\u52a1\u5668\u4e0b\u9762\u6240\u6709\u7684jpg\u7684\u6587\u4ef6\u7684\u5927\u5c0f,\u5199\u4e86\u4e2ashell\u7ed9\u4ed6\u6765\u7edf\u8ba1.\u539f\u6765\u7528xargs\u5b9e\u73b0,\u4f46\u4ed6\u4e00\u6b21\u5904\u7406\u4e00\u90e8\u5206,\u641e\u7684\u6709\u591a\u4e2a\u603b\u548c&#8230;.,\u4e0b\u9762\u7684\u547d\u4ee4\u5c31\u80fd\u89e3\u51b3\u5566.<\/p>\n<p>find \/ -name *.jpg -exec wc -c {} \\;|awk &#8216;{print $1}&#8217;|awk &#8216;{a+=$1}END{print a}&#8217;<\/p>\n<p>CPU\u7684\u6570\u91cf\uff08\u591a\u6838\u7b97\u591a\u4e2aCPU\uff0ccat \/proc\/cpuinfo |grep -c processor\uff09\u8d8a\u591a\uff0c\u7cfb\u7edf\u8d1f\u8f7d\u8d8a\u4f4e\uff0c\u6bcf\u79d2\u80fd\u5904\u7406\u7684\u8bf7\u6c42\u6570\u4e5f\u8d8a\u591a\u3002<\/p>\n<p>16 CPU\u8d1f\u8f7d # cat \/proc\/loadavg<\/p>\n<p>\u68c0\u67e5\u524d\u4e09\u4e2a\u8f93\u51fa\u503c\u662f\u5426\u8d85\u8fc7\u4e86\u7cfb\u7edf\u903b\u8f91CPU\u76844\u500d\u3002<\/p>\n<p>18 CPU\u8d1f\u8f7d #mpstat 1 1<\/p>\n<p>\u68c0\u67e5%idle\u662f\u5426\u8fc7\u4f4e(\u6bd4\u5982\u5c0f\u4e8e5%)<\/p>\n<p>19 \u5185\u5b58\u7a7a\u95f4 # free<\/p>\n<p>\u68c0\u67e5free\u503c\u662f\u5426\u8fc7\u4f4e \u4e5f\u53ef\u4ee5\u7528 # cat \/proc\/meminfo<\/p>\n<p>20 swap\u7a7a\u95f4 # free<\/p>\n<p>\u68c0\u67e5swap used\u503c\u662f\u5426\u8fc7\u9ad8 \u5982\u679cswap used\u503c\u8fc7\u9ad8\uff0c\u8fdb\u4e00\u6b65\u68c0\u67e5swap\u52a8\u4f5c\u662f\u5426\u9891\u7e41\uff1a<\/p>\n<p># vmstat 1 5<\/p>\n<p>\u89c2\u5bdfsi\u548cso\u503c\u662f\u5426\u8f83\u5927<\/p>\n<p>21 \u78c1\u76d8\u7a7a\u95f4 # df -h<\/p>\n<p>\u68c0\u67e5\u662f\u5426\u6709\u5206\u533a\u4f7f\u7528\u7387(Use%)\u8fc7\u9ad8(\u6bd4\u5982\u8d85\u8fc790%) \u5982\u53d1\u73b0\u67d0\u4e2a\u5206\u533a\u7a7a\u95f4\u63a5\u8fd1\u7528\u5c3d\uff0c\u53ef\u4ee5\u8fdb\u5165\u8be5\u5206\u533a\u7684\u6302\u8f7d\u70b9\uff0c\u7528\u4ee5\u4e0b\u547d\u4ee4\u627e\u51fa\u5360\u7528\u7a7a\u95f4\u6700\u591a\u7684\u6587\u4ef6\u6216\u76ee\u5f55\uff1a<\/p>\n<p># du -cks * | sort -rn | head -n 10<\/p>\n<p>22 \u78c1\u76d8I\/O\u8d1f\u8f7d # iostat -x 1 2<\/p>\n<p>\u68c0\u67e5I\/O\u4f7f\u7528\u7387(%util)\u662f\u5426\u8d85\u8fc7100%<\/p>\n<p>23 \u7f51\u7edc\u8d1f\u8f7d # sar -n DEV<\/p>\n<p>\u68c0\u67e5\u7f51\u7edc\u6d41\u91cf(rxbyt\/s, txbyt\/s)\u662f\u5426\u8fc7\u9ad8<\/p>\n<p>24 \u7f51\u7edc\u9519\u8bef # netstat -i<\/p>\n<p>\u68c0\u67e5\u662f\u5426\u6709\u7f51\u7edc\u9519\u8bef(drop fifo colls carrier) \u4e5f\u53ef\u4ee5\u7528\u547d\u4ee4\uff1a# cat \/proc\/net\/dev<\/p>\n<p>25 \u7f51\u7edc\u8fde\u63a5\u6570\u76ee # netstat -an | grep -E \u201c^(tcp)\u201d | cut -c 68- | sort | uniq -c | sort -n<\/p>\n<p>26 \u8fdb\u7a0b\u603b\u6570 # ps aux | wc -l<\/p>\n<p>\u68c0\u67e5\u8fdb\u7a0b\u4e2a\u6570\u662f\u5426\u6b63\u5e38 (\u6bd4\u5982\u8d85\u8fc7250)<\/p>\n<p>27 \u53ef\u8fd0\u884c\u8fdb\u7a0b\u6570\u76ee # vmwtat 1 5<\/p>\n<p>\u5217\u7ed9\u51fa\u7684\u662f\u53ef\u8fd0\u884c\u8fdb\u7a0b\u7684\u6570\u76ee\uff0c\u68c0\u67e5\u5176\u662f\u5426\u8d85\u8fc7\u7cfb\u7edf\u903b\u8f91CPU\u76844\u500d<\/p>\n<p>28 \u8fdb\u7a0b # top -id 1<\/p>\n<p>\u89c2\u5bdf\u662f\u5426\u6709\u5f02\u5e38\u8fdb\u7a0b\u51fa\u73b0<\/p>\n<p>29 \u7f51\u7edc\u72b6\u6001 \u68c0\u67e5DNS, \u7f51\u5173\u7b49\u662f\u5426\u53ef\u4ee5\u6b63\u5e38\u8fde\u901a<\/p>\n<p>30 \u7528\u6237 # who | wc -l<\/p>\n<p>\u68c0\u67e5\u767b\u5f55\u7528\u6237\u662f\u5426\u8fc7\u591a (\u6bd4\u5982\u8d85\u8fc750\u4e2a) \u4e5f\u53ef\u4ee5\u7528\u547d\u4ee4\uff1a# uptime<\/p>\n<p>31 \u7cfb\u7edf\u65e5\u5fd7 # cat \/var\/log\/rflogview\/*errors<\/p>\n<p>\u68c0\u67e5\u662f\u5426\u6709\u5f02\u5e38\u9519\u8bef\u8bb0\u5f55 \u4e5f\u53ef\u4ee5\u641c\u5bfb\u4e00\u4e9b\u5f02\u5e38\u5173\u952e\u5b57\uff0c\u4f8b\u5982\uff1a<\/p>\n<p># grep -i error \/var\/log\/messages<\/p>\n<p># grep -i fail \/var\/log\/messages<\/p>\n<p># egrep -i &#8216;error|warn&#8217; \/var\/log\/messages \u67e5\u770b\u7cfb\u7edf\u5f02\u5e38<\/p>\n<p>32 \u6838\u5fc3\u65e5\u5fd7 # dmesg<\/p>\n<p>\u68c0\u67e5\u662f\u5426\u6709\u5f02\u5e38\u9519\u8bef\u8bb0\u5f55<\/p>\n<p>33 \u7cfb\u7edf\u65f6\u95f4 # date<\/p>\n<p>\u68c0\u67e5\u7cfb\u7edf\u65f6\u95f4\u662f\u5426\u6b63\u786e<\/p>\n<p>34 \u6253\u5f00\u6587\u4ef6\u6570\u76ee # lsof | wc -l<\/p>\n<p>\u68c0\u67e5\u6253\u5f00\u6587\u4ef6\u603b\u6570\u662f\u5426\u8fc7\u591a<\/p>\n<p>35 \u65e5\u5fd7 # logwatch \u2013print \u914d\u7f6e\/etc\/log.d\/logwatch.conf\uff0c\u5c06 Mailto \u8bbe\u7f6e\u4e3a\u81ea\u5df1\u7684email \u5730\u5740\uff0c\u542f\u52a8mail\u670d\u52a1 (sendmail\u6216\u8005postfix)\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u6bcf\u5929\u6536\u5230\u65e5\u5fd7\u62a5\u544a\u4e86\u3002<\/p>\n<p>\u7f3a\u7701logwatch\u53ea\u62a5\u544a\u6628\u5929\u7684\u65e5\u5fd7\uff0c\u53ef\u4ee5\u7528# logwatch \u2013print \u2013range all \u83b7\u5f97\u6240\u6709\u7684\u65e5\u5fd7\u5206\u6790\u7ed3\u679c\u3002<\/p>\n<p>\u53ef\u4ee5\u7528# logwatch \u2013print \u2013detail high \u83b7\u5f97\u66f4\u5177\u4f53\u7684\u65e5\u5fd7\u5206\u6790\u7ed3\u679c(\u800c\u4e0d\u4ec5\u4ec5\u662f\u51fa\u9519\u65e5\u5fd7)\u3002<\/p>\n<p>36.\u6740\u638980\u7aef\u53e3\u76f8\u5173\u7684\u8fdb\u7a0b<\/p>\n<p>lsof -i :80|grep -v &#8220;PID&#8221;|awk &#8216;{print &#8220;kill -9&#8221;,$2}&#8217;|sh<\/p>\n<p>37.\u6e05\u9664\u50f5\u6b7b\u8fdb\u7a0b\u3002<\/p>\n<p>ps -eal | awk &#8216;{ if ($2 == &#8220;Z&#8221;) {print $4}}&#8217; | kill -9<\/p>\n<p>38.tcpdump \u6293\u5305 \uff0c\u7528\u6765\u9632\u6b6280\u7aef\u53e3\u88ab\u4eba\u653b\u51fb\u65f6\u53ef\u4ee5\u5206\u6790\u6570\u636e<\/p>\n<p># tcpdump -c 10000 -i eth0 -n dst port 80 &gt; \/root\/pkts<\/p>\n<p>39.\u7136\u540e\u68c0\u67e5IP\u7684\u91cd\u590d\u6570 \u5e76\u4ece\u5c0f\u5230\u5927\u6392\u5e8f \u6ce8\u610f &#8220;-t\\ +0&#8243; \u4e2d\u95f4\u662f\u4e24\u4e2a\u7a7a\u683c<\/p>\n<p># less pkts | awk {&#8216;printf $3&#8243;\\n&#8221;&#8216;} | cut -d. -f 1-4 | sort | uniq -c | awk {&#8216;printf $1&#8221; &#8220;$2&#8243;\\n&#8221;&#8216;} | sort -n -t\\ +0<\/p>\n<p>40.\u67e5\u770b\u6709\u591a\u5c11\u4e2a\u6d3b\u52a8\u7684php-cgi\u8fdb\u7a0b<\/p>\n<p>netstat -anp | grep php-cgi | grep ^tcp | wc -l<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>1.\u5220\u96640\u5b57\u8282\u6587\u4ef6 find -type f -size 0 -exec rm -rf {} \\; 2.\u67e5\u770b\u8fdb\u7a0b \u6309\u5185\u5b58\u4ece\u5927\u5230\u5c0f\u6392\u5217 ps -e -o &#8220;%C : %p : %z : %a&#8221;|sort -k5 -nr 3.\u6309cpu\u5229\u7528\u7387\u4ece\u5927\u5230\u5c0f\u6392\u5217 ps -e -o &#8220;%C : %p : %z : %a&#8221;|sort -nr 4.\u6253\u5370\u8bf4cache\u91cc\u7684URL grep -r -a jpg \/data\/cache\/* | strings | grep &#8220;http:&#8221; | awk -F&#8217;http:&#8217; &#8216;{print &#8220;http:&#8221;$2;}&#8217; 5.\u67e5\u770bhttp\u7684\u5e76\u53d1\u8bf7\u6c42\u6570\u53ca\u5176TCP\u8fde\u63a5\u72b6\u6001\uff1a netstat &hellip; <a href=\"https:\/\/www.strongd.net\/?p=1147\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">linux \u5e38\u7528\u547d\u4ee4<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-1147","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1147"}],"version-history":[{"count":1,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1147\/revisions"}],"predecessor-version":[{"id":1148,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1147\/revisions\/1148"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}