{"id":3061,"date":"2018-01-27T14:55:34","date_gmt":"2018-01-27T06:55:34","guid":{"rendered":"http:\/\/cn.hostease.com\/xueyuan\/?p=3061"},"modified":"2018-01-27T14:55:34","modified_gmt":"2018-01-27T06:55:34","slug":"linux%e4%b8%8b%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4%e6%9f%a5%e7%9c%8b%e7%ab%af%e5%8f%a3%e5%8d%a0%e7%94%a8","status":"publish","type":"post","link":"https:\/\/cn.hostease.com\/xueyuan\/hemanual\/linux%e4%b8%8b%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4%e6%9f%a5%e7%9c%8b%e7%ab%af%e5%8f%a3%e5%8d%a0%e7%94%a8\/","title":{"rendered":"linux\u4e0b\u5e38\u7528\u547d\u4ee4\u67e5\u770b\u7aef\u53e3\u5360\u7528"},"content":{"rendered":"<p>\u5728Linux\u4f7f\u7528\u8fc7\u7a0b\u4e2d\uff0c\u9700\u8981\u4e86\u89e3\u5f53\u524d\u7cfb\u7edf\u5f00\u653e\u4e86\u54ea\u4e9b\u7aef\u53e3\uff0c\u5e76\u4e14\u8981\u67e5\u770b\u5f00\u653e\u8fd9\u4e9b\u7aef\u53e3\u7684\u5177\u4f53\u8fdb\u7a0b\u548c\u7528\u6237\uff0c\u53ef\u4ee5\u901a\u8fc7netstat\u547d\u4ee4\u8fdb\u884c\u7b80\u5355\u67e5\u8be2<br \/>\nnetstat\u547d\u4ee4\u5404\u4e2a\u53c2\u6570\u8bf4\u660e\u5982\u4e0b\uff1a<br \/>\n-t : \u6307\u660e\u663e\u793aTCP\u7aef\u53e3<br \/>\n-u : \u6307\u660e\u663e\u793aUDP\u7aef\u53e3<br \/>\n-l : \u4ec5\u663e\u793a\u76d1\u542c\u5957\u63a5\u5b57(\u6240\u8c13\u5957\u63a5\u5b57\u5c31\u662f\u4f7f\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u8bfb\u5199\u4e0e\u6536\u53d1\u901a\u8baf\u534f\u8bae(protocol)\u4e0e\u8d44\u6599\u7684\u7a0b\u5e8f)<br \/>\n-p : \u663e\u793a\u8fdb\u7a0b\u6807\u8bc6\u7b26\u548c\u7a0b\u5e8f\u540d\u79f0\uff0c\u6bcf\u4e00\u4e2a\u5957\u63a5\u5b57\/\u7aef\u53e3\u90fd\u5c5e\u4e8e\u4e00\u4e2a\u7a0b\u5e8f\u3002<br \/>\n-n : \u4e0d\u8fdb\u884cDNS\u8f6e\u8be2\uff0c\u663e\u793aIP(\u53ef\u4ee5\u52a0\u901f\u64cd\u4f5c)<br \/>\n\u5373\u53ef\u663e\u793a\u5f53\u524d\u670d\u52a1\u5668\u4e0a\u6240\u6709\u7aef\u53e3\u53ca\u8fdb\u7a0b\u670d\u52a1\uff0c\u4e8egrep\u7ed3\u5408\u53ef\u67e5\u770b\u67d0\u4e2a\u5177\u4f53\u7aef\u53e3\u53ca\u670d\u52a1\u60c5\u51b5\u00b7\u00b7<br \/>\nnetstat -ntlp \u00a0 \/\/\u67e5\u770b\u5f53\u524d\u6240\u6709tcp\u7aef\u53e3\u00b7<br \/>\nnetstat -ntulp |grep 80 \u00a0 \/\/\u67e5\u770b\u6240\u670980\u7aef\u53e3\u4f7f\u7528\u60c5\u51b5\u00b7<\/p>\n<p>netstat -ntulp | grep 3306 \u00a0 \/\/\u67e5\u770b\u6240\u67093306\u7aef\u53e3\u4f7f\u7528\u60c5\u51b5\u00b7<\/p>\n<p>&nbsp;<\/p>\n<p>Linux\u67e5\u770b\u7a0b\u5e8f\u7aef\u53e3\u5360\u7528\u60c5\u51b5<br \/>\n\u4f7f\u7528\u547d\u4ee4\uff1a<br \/>\nps -aux | grep tomcat<br \/>\n\u53d1\u73b0\u5e76\u6ca1\u67098080\u7aef\u53e3\u7684Tomcat\u8fdb\u7a0b\u3002<br \/>\n\u4f7f\u7528\u547d\u4ee4\uff1anetstat \u2013apn<br \/>\n\u67e5\u770b\u6240\u6709\u7684\u8fdb\u7a0b\u548c\u7aef\u53e3\u4f7f\u7528\u60c5\u51b5\u3002\u53d1\u73b0\u4e0b\u9762\u7684\u8fdb\u7a0b\u5217\u8868\uff0c\u5176\u4e2d\u6700\u540e\u4e00\u680f\u662fPID\/Program name<br \/>\n\u53d1\u73b08080\u7aef\u53e3\u88abPID\u4e3a9658\u7684Java\u8fdb\u7a0b\u5360\u7528\u3002<br \/>\n\u8fdb\u4e00\u6b65\u4f7f\u7528\u547d\u4ee4\uff1aps -aux | grep java\uff0c\u6216\u8005\u76f4\u63a5\uff1aps -aux | grep pid \u67e5\u770b<br \/>\n\u5c31\u53ef\u4ee5\u660e\u786e\u77e5\u90538080\u7aef\u53e3\u662f\u88ab\u54ea\u4e2a\u7a0b\u5e8f\u5360\u7528\u4e86\uff01\u7136\u540e\u5224\u65ad\u662f\u5426\u4f7f\u7528KILL\u547d\u4ee4\u5e72\u6389\uff01<br \/>\n\u65b9\u6cd5\u4e8c\uff1a\u76f4\u63a5\u4f7f\u7528 netstat \u00a0 -anp \u00a0 | \u00a0 grep \u00a0portno<br \/>\n\u5373\uff1anetstat -anp|grep 8080<\/p>\n<p>netstat -anp|grep 8080 &#8211;&gt; tcp \u00a0 \u00a0 \u00a0 \u00a00 \u00a0 \u00a0 \u00a00 0.0.0.0:8080 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a00.0.0.0:* \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 LISTEN \u00a0 \u00a0 \u00a028500\/java<br \/>\nps -aux | grep 28500 \u00a0&#8211;&gt; r\/local\/tomcat9-jforum\/tomcat<\/p>\n<p>\u5b89\u88c5lsof list open files\/\/&#8212;\u4e5f\u53ef\u4ee5 \u00a0netstat -tunlp|grep \u7aef\u53e3\u53f7 \u00a0netstat -anp|grep \u7aef\u53e3\u53f7<br \/>\nyum install lsof<br \/>\nlsof -i:8080 \u67e5\u770b8080\u7aef\u53e3\u5360\u7528<br \/>\nlsof abc.txt \u663e\u793a\u5f00\u542f\u6587\u4ef6abc.txt\u7684\u8fdb\u7a0b<br \/>\nlsof -c abc \u663e\u793aabc\u8fdb\u7a0b\u73b0\u5728\u6253\u5f00\u7684\u6587\u4ef6<br \/>\nlsof -c -p 1234 \u5217\u51fa\u8fdb\u7a0b\u53f7\u4e3a1234\u7684\u8fdb\u7a0b\u6240\u6253\u5f00\u7684\u6587\u4ef6<br \/>\nlsof -g gid \u663e\u793a\u5f52\u5c5egid\u7684\u8fdb\u7a0b\u60c5\u51b5<br \/>\nlsof +d \/usr\/local\/ \u663e\u793a\u76ee\u5f55\u4e0b\u88ab\u8fdb\u7a0b\u5f00\u542f\u7684\u6587\u4ef6<br \/>\nlsof +D \/usr\/local\/ \u540c\u4e0a\uff0c\u4f46\u662f\u4f1a\u641c\u7d22\u76ee\u5f55\u4e0b\u7684\u76ee\u5f55\uff0c\u65f6\u95f4\u8f83\u957f<br \/>\nlsof -d 4 \u663e\u793a\u4f7f\u7528fd\u4e3a4\u7684\u8fdb\u7a0b<br \/>\nlsof -i \u7528\u4ee5\u663e\u793a\u7b26\u5408\u6761\u4ef6\u7684\u8fdb\u7a0b\u60c5\u51b5<br \/>\nlsof -i[46] [protocol][@hostname|hostaddr][:service|port]<br \/>\n46 &#8211;&gt; IPv4 or IPv6<br \/>\nprotocol &#8211;&gt; TCP or UDP<br \/>\nhostname &#8211;&gt; Internet host name<br \/>\nhostaddr &#8211;&gt; IPv4\u5730\u5740<br \/>\nservice &#8211;&gt; \/etc\/service\u4e2d\u7684 service name (\u53ef\u4ee5\u4e0d\u6b62\u4e00\u4e2a)<br \/>\nport &#8211;&gt; \u7aef\u53e3\u53f7 (\u53ef\u4ee5\u4e0d\u6b62\u4e00\u4e2a)<br \/>\nlsof -i \/\/\u663e\u793a\u6240\u6709\u6253\u5f00\u7684\u7aef\u53e3<br \/>\nlsof -i:80 \/\/\u663e\u793a\u6240\u6709\u6253\u5f0080\u7aef\u53e3\u7684\u8fdb\u7a0b<br \/>\nlsof -i -U \/\/\u663e\u793a\u6240\u6709\u6253\u5f00\u7684\u7aef\u53e3\u548cUNIX domain\u6587\u4ef6<\/p>\n<p>\u5176\u5b9e\u6211\u4e00\u822c\u8fd9\u6837\u7528:<\/p>\n<p>[root@VM_39_230_centos bin]# lsof -i:3306<br \/>\nCOMMAND \u00a0 PID \u00a0USER \u00a0 FD \u00a0 TYPE DEVICE SIZE\/OFF NODE NAME<br \/>\nmysqld \u00a016422 mysql \u00a0 19u \u00a0IPv6 148794 \u00a0 \u00a0 \u00a00t0 \u00a0TCP *:mysql (LISTEN)<br \/>\nmysqld \u00a016422 mysql \u00a0 39u \u00a0IPv6 643698 \u00a0 \u00a0 \u00a00t0 \u00a0TCP localhost:mysql-&gt;localhost:36582 (ESTABLISHED)<br \/>\nmysqld \u00a016422 mysql \u00a0 45u \u00a0IPv6 643699 \u00a0 \u00a0 \u00a00t0 \u00a0TCP localhost:mysql-&gt;localhost:36584 (ESTABLISHED)<br \/>\nmysqld \u00a016422 mysql \u00a0 46u \u00a0IPv6 643700 \u00a0 \u00a0 \u00a00t0 \u00a0TCP localhost:mysql-&gt;localhost:36586 (ESTABLISHED)<br \/>\nmysqld \u00a016422 mysql \u00a0 47u \u00a0IPv6 643702 \u00a0 \u00a0 \u00a00t0 \u00a0TCP localhost:mysql-&gt;localhost:36588 (ESTABLISHED)<br \/>\nmysqld \u00a016422 mysql \u00a0 48u \u00a0IPv6 643704 \u00a0 \u00a0 \u00a00t0 \u00a0TCP localhost:mysql-&gt;localhost:36590 (ESTABLISHED)<br \/>\njava \u00a0 \u00a017302 \u00a0root \u00a0122u \u00a0IPv4 643695 \u00a0 \u00a0 \u00a00t0 \u00a0TCP localhost:36582-&gt;localhost:mysql (ESTABLISHED)<br \/>\njava \u00a0 \u00a017302 \u00a0root \u00a0123u \u00a0IPv4 643701 \u00a0 \u00a0 \u00a00t0 \u00a0TCP localhost:36588-&gt;localhost:mysql (ESTABLISHED)<br \/>\njava \u00a0 \u00a017302 \u00a0root \u00a0124u \u00a0IPv4 643696 \u00a0 \u00a0 \u00a00t0 \u00a0TCP localhost:36586-&gt;localhost:mysql (ESTABLISHED)<br \/>\njava \u00a0 \u00a017302 \u00a0root \u00a0125u \u00a0IPv4 643697 \u00a0 \u00a0 \u00a00t0 \u00a0TCP localhost:36584-&gt;localhost:mysql (ESTABLISHED)<br \/>\njava \u00a0 \u00a017302 \u00a0root \u00a0126u \u00a0IPv4 643703 \u00a0 \u00a0 \u00a00t0 \u00a0TCP localhost:36590-&gt;localhost:mysql (ESTABLISHED)<\/p>\n<p>\u6216\u8005<br \/>\n[root@VM_39_230_centos bin]# netstat -ntulp | grep 3306<br \/>\ntcp6 \u00a0 \u00a0 \u00a0 0 \u00a0 \u00a0 \u00a00 :::3306 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 :::* \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0LISTEN \u00a0 \u00a0 \u00a016422\/mysqld<\/p>\n<p>&nbsp;<\/p>\n<p>\u627e\u5230pid \u00a0\u7136\u540e<\/p>\n<p>[root@VM_39_230_centos bin]# ps -aux | grep 16422<br \/>\nmysql \u00a0 \u00a016422 \u00a00.0 47.7 1340428 485944 ? \u00a0 \u00a0 \u00a0Sl \u00a0 Jun29 \u00a0 1:46 \/usr\/sbin\/mysqld &#8211;basedir=\/usr &#8211;datadir=\/var\/lib\/mysql &#8211;plugin-dir=\/usr\/lib64\/mysql\/plugin &#8211;log-error=\/var\/lib\/mysql\/VM_39_230_centos.err &#8211;pid-file=\/var\/lib\/mysql\/VM_39_230_centos.pid<br \/>\nroot \u00a0 \u00a0 25713 \u00a00.0 \u00a00.0 112616 \u00a0 700 pts\/0 \u00a0 \u00a0R+ \u00a0 17:04 \u00a0 0:00 grep &#8211;color=auto 16422<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Linux\u4f7f\u7528\u8fc7\u7a0b\u4e2d\uff0c\u9700\u8981\u4e86\u89e3\u5f53\u524d\u7cfb\u7edf\u5f00\u653e\u4e86\u54ea\u4e9b\u7aef\u53e3\uff0c\u5e76\u4e14\u8981\u67e5\u770b\u5f00\u653e\u8fd9\u4e9b\u7aef\u53e3\u7684\u5177\u4f53\u8fdb\u7a0b\u548c\u7528\u6237\uff0c\u53ef\u4ee5\u901a\u8fc7net &#8230; <a title=\"linux\u4e0b\u5e38\u7528\u547d\u4ee4\u67e5\u770b\u7aef\u53e3\u5360\u7528\" class=\"read-more\" href=\"https:\/\/cn.hostease.com\/xueyuan\/hemanual\/linux%e4%b8%8b%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4%e6%9f%a5%e7%9c%8b%e7%ab%af%e5%8f%a3%e5%8d%a0%e7%94%a8\/\" aria-label=\"\u9605\u8bfb linux\u4e0b\u5e38\u7528\u547d\u4ee4\u67e5\u770b\u7aef\u53e3\u5360\u7528\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,49,5],"tags":[444],"class_list":["post-3061","post","type-post","status-publish","format-standard","hentry","category-hemanual","category-linux","category-jishu","tag-linux"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/3061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/comments?post=3061"}],"version-history":[{"count":1,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/3061\/revisions"}],"predecessor-version":[{"id":3062,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/3061\/revisions\/3062"}],"wp:attachment":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/media?parent=3061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/categories?post=3061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/tags?post=3061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}