{"id":294371,"date":"2024-11-15T12:11:06","date_gmt":"2024-11-15T04:11:06","guid":{"rendered":"https:\/\/lrxjmw.cn\/lyhthnhtdtxf.html"},"modified":"2024-11-15T12:11:06","modified_gmt":"2024-11-15T04:11:06","slug":"lyhthnhtdtxf","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/lyhthnhtdtxf.html","title":{"rendered":"Linux \u7528\u6237\u6001\u548c\u5185\u6838\u6001\u7684\u901a\u4fe1\u65b9\u5f0f\u6709\u54ea\u4e9b\uff1f\u8fd9\u7bc7\u6587\u7ae0\u544a\u8bc9\u4f60"},"content":{"rendered":"
\u672c\u6587\u9996\u53d1\u4e8e\u6211\u7684\u516c\u4f17\u53f7Linux<\/a>\u4e91\u4f30\u7b97\u7f51\u8def\uff08id:cloud_dev\uff09\uff0c\u4e13\u6ce8\u4e8e\u5e72\u8d27\u5206\u4eab\uff0c\u53f7\u5185\u670910T\u4e66\u7c4d\u548c\u89c6\u9891\u8d44\u6e90\uff0c\u540e\u53f0\u56de\u590d\u300c1024\u300d\u5373\u53ef\u7533\u9886\uff0c\u6b22\u8fce\u4f60\u4eec\u5173\u6ce8\uff0c\u4e8c\u7ef4\u7801\u6587\u672b\u53ef\u4ee5\u626b\u3002<\/p>\n Linux\u7528\u6237\u6001\u548c\u5185\u6838\u6001\u56e0\u4e3aCPU\u6743\u9650\u7684\u9650\u5236\uff0c\u901a\u8baf\u5e76\u4e0d\u50cf\u60f3\u50cf\u4e2d\u7684\u4f7f\u7528\u8fdb\u7a0b\u95f4\u901a\u8baf\u65b9\u6cd5\u8fd9\u4e48\u7b80\u5355\uff0c\u660e\u5929\u8fd9\u7bc7\u6587\u7ae0\u5c31\u6765\u77a7\u77a7Linux\u7528\u6237\u6001\u548c\u5185\u6838\u6001\u5230\u5e95\u6709\u4ec0\u4e48\u901a\u8baf\u65b9\u6cd5\u3002<\/p>\n \u6211\u4eec\u5e73\u65f6\u5728\u5199\u4ee3\u7801\u65f6\uff0c\u901a\u5e38\u662f\u5728\u7528\u6237\u7a7a\u95f4\uff0c\u901a\u8fc7\u7cfb\u7edf\u8c03\u7528\u51fd\u6570\u6765\u8bbf\u95ee\u5185\u6838\u7a7a\u95f4\uff0c\u8fd9\u662f\u6700\u5e38\u7528\u7684\u4e00\u79cd\u7528\u6237\u6001\u548c\u5185\u6838\u6001\u901a\u8baf\u7684\u5f62\u5f0f\u3002\uff08\u5173\u4e8eLinux\u7528\u6237\u6001\u548c\u5185\u6838\u6001\u53ef\u4ee5\u53c2\u8003xx\uff09<\/p>\n \u9664\u6b64\u4e4b\u5916\uff0c\u8fd8\u6709\u4ee5\u4e0b\u56db\u79cd\u5f62\u5f0f\uff1a<\/p>\n procfs(\/proc)<\/p>\n procfs\u662f\u8fdb\u7a0b\u6587\u4ef6\u7cfb\u7edf\u7684\u7b80\u5199\uff0c\u5b83\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u4f2a\u6587\u4ef6\u7cfb\u7edf\uff0c\u4e3a\u4f55\u8bf4\u662f\u4f2a\u6587\u4ef6\u7cfb\u7edf\u5462\uff1f\u7531\u4e8e\u5b83\u4e0d\u5360\u7528\u5916\u90e8\u50a8\u5b58\u7a7a\u95f4\uff0c\u53ea\u662f\u5360\u7528\u5c11\u91cf\u7684\u663e\u5b58\uff0c\u4e00\u822c\u662f\u6302\u8f7d\u5728\/proc\u76ee\u5f55\u4e0b\u3002<\/p>\n \u6211\u4eec\u5728\u8be5\u76ee\u5f55\u4e0b\u770b\u89c1\u7684\u4e00\u4e2a\u6587\u4ef6\uff0c\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u5185\u6838\u53d8\u91cf\u3002\u5185\u6838\u5c31\u662f\u901a\u8fc7\u8fd9\u4e2a\u76ee\u5f55\uff0c\u4ee5\u6587\u4ef6\u7684\u65b9\u5f0f\u8be0\u91ca\u81ea\u5df1\u7684\u5185\u90e8\u4fe1\u606f\uff0c\u76f8\u5f53\u4e8e\/proc\u76ee\u5f55\u4e3a\u7528\u6237\u6001\u548c\u5185\u6838\u6001\u4e4b\u95f4\u7684\u4ea4\u4e92\u642d\u5efa\u4e86\u4e00\u4e2a\u6865\u6881\uff0c\u7528\u6237\u6001\u8bfb\u5199\/proc\u4e0b\u7684\u6587\u4ef6\uff0c\u5c31\u662f\u8bfb\u5199\u5185\u6838\u76f8\u5173\u7684\u914d\u7f6e\u53c2\u6570\u3002<\/p>\n \u4f8b\u5982\u5e38\u89c1\u7684\/proc\/cpuinfo\u3001\/proc\/meminfo\u548c\/proc\/net\u5c31\u5206\u522b\u63d0\u4f9b\u4e86CPU\u3001\u5185\u5b58\u3001\u7f51\u7edc\u7684\u76f8\u5173\u53c2\u6570\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u8fd8\u6709\u597d\u591a\u7684\u53c2\u6570\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n \n <\/p>\n10 1145 1357 148 20 23 290 332 396 442 64 7019 77 asound dma kallsyms mdstat schedstat thread-self\n1042 1149 1361 149 2084 2425 291 34 398 45 65 7029 8 buddyinfo driver kcore meminfo scsi timer_list\n1044 1150 1363 15 2087 25 3 3455 413 46 66 7079 83 bus execdomains keys misc self timer_stats\n1046 1151 1371 16 2090 256 30 35 418 47 6600 7080 884 cgroups fb key-users modules slabinfo tty\n1048 1153 1372 17 21 26 302 36 419 5 67 71 9 cmdline filesystems kmsg mounts softirqs uptime\n11 1190 1390 18 22 27 31 37 420 518 6749 72 96 consoles fs kpagecgroup mtrr stat version\n1126 12 143 182 2214 28 32 373 421 524 68 73 97 cpuinfo interrupts kpagecount net swaps version_signature\n1137 1252 1434 184 2215 280 327 38 422 525 69 74 98 crypto iomem kpageflags pagetypeinfo sys vmallocinfo\n1141 13 144 190 2262 281 33 39 425 5940 7 75 985 devices ioports loadavg partitions sysrq-trigger vmstat<\/code><\/pre>\n<\/p>\n <\/p>\n \u53ef\u4ee5\u770b\u89c1\uff0c\u8fd9\u513f\u9762\u6709\u597d\u591a\u7684\u6570\u5b57\u8868\u793a\u7684\u6587\u4ef6\uff0c\u8fd9\u79cd\u663e\u7136\u662f\u5f53\u524d\u7cfb\u7edf\u8fd0\u884c\u7684\u8fdb\u7a0b\u6587\u4ef6\uff0c\u6570\u5b57\u8868\u793a\u8fdb\u7a0b\u53f7\uff08PID\uff09\uff0c\u6bcf\u4f4d\u6587\u4ef6\u5305\u542b\u8be5\u8fdb\u7a0b\u6240\u6709\u7684\u914d\u7f6e\u4fe1\u606f\uff0c\u5305\u62ec\u8fdb\u7a0b\u72b6\u6001\u3001\u6587\u4ef6\u63cf\u8ff0\u7b26\u3001\u5185\u5b58\u6620\u5c04\u7b49\u7b49\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u4e0b\uff1a<\/p>\n \n \u7efc\u4e0a\uff0c\u5185\u6838\u901a\u8fc7\u4e00\u4e2a\u4e2a\u7684\u6587\u4ef6\u6765\u66dd\u9732\u81ea\u5df1\u7684\u7cfb\u7edf\u914d\u7f6e\u4fe1\u606f\uff0c\u8fd9\u79cd\u6587\u4ef6\uff0c\u6709\u4e9b\u662f\u53ea\u8bfb\u7684\uff0c\u6709\u4e9b\u662f\u53ef\u5199\u7684\uff0c\u6709\u4e9b\u662f\u52a8\u6001\u53d8\u5316\u7684\uff0c\u4f8b\u5982\u8fdb\u7a0b\u6587\u4ef6\uff0c\u5f53\u5e94\u7528\u7a0b\u5e8f\u8bfb\u53d6\u67d0\u4e2a\/proc\/\u6587\u4ef6\u65f6\uff0c\u5185\u6838\u5c31\u4f1a\u53bb\u6ce8\u518c\u8fd9\u4e2a\u6587\u4ef6\uff0c\u4e4b\u540e\u518d\u8c03\u7528\u4e00\u7ec4\u5185\u6838\u51fd\u6570\u6765\u5904\u7406\uff0c\u5c06\u76f8\u5e94\u7684\u5185\u6838\u53c2\u6570\u62f7\u8d1d\u5230\u7528\u6237\u6001\u7a7a\u95f4\uff0c\u8fd9\u6837\u7528\u6237\u8bfb\u8fd9\u4e2a\u6587\u4ef6\u5c31\u53ef\u4ee5\u83b7\u53d6\u5230\u5185\u6838\u7684\u4fe1\u606f\u3002\u4e00\u4e2a\u5927\u7ea6\u7684\u56fe\u793a\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n sysctl<\/p>\n \u6211\u4eec\u719f\u6089\u7684sysctl\u662f\u4e00\u4e2aLinux\u547d\u4ee4<\/a>\uff0cmansysctl\u53ef\u4ee5\u770b\u89c1\u5b83\u7684\u529f\u80fd\u548c\u7528\u6cd5\u3002\u5b83\u4e3b\u8981\u662f\u88ab\u62ff\u6765\u66f4\u6539\u5185\u6838\u7684\u8fd0\u884c\u65f6\u53c2\u6570\uff0c\u6362\u53e5\u8bdd\u8bf4\uff0c\u5b83\u53ef\u4ee5\u5728\u5185\u6838\u8fd0\u884c\u8fc7\u7a0b\u4e2d\uff0c\u52a8\u6001\u66f4\u6539\u5185\u6838\u53c2\u6570\u3002<\/p>\n \u5b83\u672c\u8d28\u4e0a\u8fd8\u662f\u7528\u5230\u4e86\u6587\u4ef6\u7684\u8bfb\u5199\u64cd\u4f5c\uff0c\u6765\u5b8c\u6210\u7528\u6237\u6001\u548c\u5185\u6838\u6001\u7684\u901a\u8baf\u3002\u5b83\u4f7f\u7528\u7684\u662f\/proc\u7684\u4e00\u4e2a\u5b50\u76ee\u5f55\/proc\/sys\u3002\u548cprocfs\u7684\u533a\u522b\u5728\u4e8e\uff1a<\/p>\n procfs\u4e3b\u8981\u662f\u8f93\u51fa\u53ea\u8bfb\u6570\u636e\uff0c\u800csysctl\u8f93\u51fa\u7684\u5927\u90e8\u4efd\u4fe1\u606f\u662f\u53ef\u5199\u7684\u3002<\/p>\n \u6bd4\u5982\uff0c\u6211\u4eec\u6bd4\u8f83\u5e38\u89c1\u7684\u662f\u901a\u8fc7cat\/proc\/sys\/net\/ipv4\/ip_forward\u6765\u83b7\u53d6\u5185\u6838\u7f51\u8def\u5c42\u662f\u5426\u5bb9\u8bb8\u8f6c\u53d1IP\u6570\u636e\u5305\uff0c\u901a\u8fc7echo1>\/proc\/sys\/net\/ipv4\/ip_forward\u6216\u5219sysctl-wnet.ipv4.ip_forward=1\u6765\u8bbe\u7f6e\u5185\u6838\u7f51\u8def\u5c42\u5bb9\u8bb8\u8f6c\u53d1IP\u6570\u636e\u5305\u3002<\/p>\n \u540c\u6837\u7684\u64cd\u4f5c\uff0cLinux\u4e5f\u63d0\u4f9b\u4e86\u6587\u4ef6\/etc\/sysctl.conf\u6765\u8ba9\u4f60\u8fdb\u884c\u6279\u91cf\u66f4\u6539\u3002<\/p>\n sysfs<\/p>\n sysfs\u662fLinux2.6\u624d\u5f15\u5165\u7684\u4e00\u79cd\u865a\u62df\u6587\u4ef6\u7cfb\u7edf\uff0c\u5b83\u7684\u505a\u6cd5\u4e5f\u662f\u901a\u8fc7\u6587\u4ef6\/sys\u6765\u5b8c\u6210\u7528\u6237\u6001\u548c\u5185\u6838\u7684\u901a\u8baf\u3002\u548cprocfs\u4e0d\u540c\u7684\u662f\u4e2d\u56fdlinux\uff0csysfs\u662f\u5c06\u4e00\u4e9b\u672c\u6765\u5728procfs\u4e2d\u7684\uff0c\u5173\u4e8e\u8bbe\u5907\u548c\u9a71\u52a8\u7684\u90e8\u4efd\uff0c\u72ec\u7acb\u4e0b\u6765\uff0c\u4ee5\u201c\u8bbe\u5907\u6811\u201d\u7684\u65b9\u5f0f\u5448\u73b0\u7ed9\u7528\u6237\u3002<\/p>\n sysfs\u9664\u4e86\u53ef\u4ee5\u4ece\u5185\u6838\u7a7a\u95f4\u8bfb\u53d6\u8bbe\u5907\u548c\u9a71\u52a8\u7a0b\u5e8f\u7684\u4fe1\u606flinux\u5185\u6838\u7a7a\u95f4\u8bbf\u95ee\u7528\u6237\u7a7a\u95f4<\/strong>\uff0c\u4e5f\u53ef\u4ee5\u5bf9\u8bbe\u5907\u548c\u9a71\u52a8\u8fdb\u884c\u914d\u7f6e\u3002<\/p>\n <\/p>\n \u6211\u4eec\u770b\u4e0b\/sys\u4e0b\u6709\u54ea\u4e9b\uff1a<\/p>\n \n \u53ef\u4ee5\u89c1\u5230\u8fd9\u79cd\u6587\u4ef6\u57fa\u672c\u4e0a\u90fd\u8ddf\u8ba1\u7b97\u673a\u7684\u8bbe\u5907\u548c\u9a71\u52a8\u7b49\u606f\u606f\u76f8\u5173\u7684\u3002\u66f4\u591a\u5173\u4e8e\u90a3\u4e9b\u6587\u4ef6\u7684\u89e3\u91ca\u4f60\u4eec\u53ef\u4ee5\u81ea\u884c\u4e86\u89e3linux\u5185\u6838\u7a7a\u95f4\u8bbf\u95ee\u7528\u6237\u7a7a\u95f4<\/strong>\uff0c\u8fd9\u513f\u5c31\u4e0d\u8fc7\u591a\u5c55\u5f00\u4e86\u3002<\/p>\n netlink<\/p>\n netlink\u662fLinux\u7528\u6237\u6001\u4e0e\u5185\u6838\u6001\u901a\u8baf\u6700\u5e38\u7528\u7684\u4e00\u79cd\u65b9\u6cd5\u3002Linuxkernel2.6.14\u7248\u672c\u624d\u5f00\u59cb\u652f\u6301\u3002\u5b83\u672c\u8d28\u4e0a\u662f\u4e00\u79cdsocket\uff0c\u5e38\u89c4socket\u4f7f\u7528\u7684\u6807\u51c6API\uff0c\u5728\u5b83\u5934\u4e0a\u540c\u6837\u9002\u7528\u3002\u8bf8\u5982\u521b\u5efa\u4e00\u4e2anetlinksocket\uff0c\u53ef\u4ee5\u8c03\u7528\u5982\u4e0b\u7684socket\u51fd\u6570\uff1a<\/p>\n \n <\/p>\nnetlink_socket = socket(AF_NETLINK, socket_type, netlink_family);<\/a><\/code><\/pre>\n<\/p>\n netlink\u8fd9\u4e9b\u7075\u6d3b\u7684\u5f62\u5f0f\uff0c\u81f4\u4f7f\u5b83\u53ef\u4ee5\u7528\u4e8e\u5185\u6838\u4e0e\u591a\u79cd\u7528\u6237\u8fdb\u7a0b\u4e4b\u95f4\u7684\u6d88\u606f\u4f20\u9012\u7cfb\u7edf\uff0c\u4f8b\u5982\u8def\u7531\u5b50\u7cfb\u7edf\uff0c\u9632\u706b\u5899\uff08Netfilter\uff09\uff0cipsec\u5b89\u5168\u7b56\u7565\u7b49\u7b49\u3002<\/p>\n \u5f15\u7533\uff1a<\/p>\n net-tools\u5de5\u5177\u901a\u8fc7procfs(\/proc)\u548cioctl\u7cfb\u7edf\u8c03\u7528\u53bb\u8bbf\u95ee\u548c\u6539\u53d8\u5185\u6838\u7f51\u8def\u53c2\u6570\u914d\u7f6e\uff0c\u800ciproute2\u5219\u901a\u8fc7netlink\u5957\u63a5\u5b57\u63d2\u53e3\u4e0e\u5185\u6838\u901a\u8baf\uff0c\u540e\u8005\u65e9\u5df2\u88ab\u6dd8\u6c70\u4e86\uff0c\u524d\u8005\u9010\u6e10\u6210\u4e3a\u6807\u51c6\u3002<\/p>\n \u603b\u7ed3<\/p>\n Linux\u7528\u6237\u6001\u548c\u5185\u6838\u6001\u901a\u8baf\u4e3b\u8981\u7684\u56db\u79cd\u5f62\u5f0f\uff0c\u5176\u4e2dnetlink\u548cprocfs\u662f\u6700\u5e38\u89c1\u7684\u5f62\u5f0f\u3002<\/p>\n \u540e\u53f0\u56de\u590d\u201c\u52a0\u7fa4\u201d\uff0c\u5e26\u4f60\u6b65\u5165\u524d\u8f88\u5982\u4e91\u4ea4\u6d41\u7fa4<\/p>\n \u6211\u7684\u516c\u4f17\u53f7\u300cLinux\u4e91\u4f30\u7b97\u7f51\u8def\u300d(id:cloud_dev)\uff0c\u53f7\u5185\u670910T\u4e66\u7c4d\u548c\u89c6\u9891\u8d44\u6e90\uff0c\u540e\u53f0\u56de\u590d\u300c1024\u300d\u5373\u53ef\u7533\u9886\u7ea2\u65d7linux6.0\uff0c\u5206\u4eab\u7684\u5185\u5bb9\u5305\u62ec\u4f46\u4e0d\u9650\u4e8eLinux\u3001\u7f51\u7edc\u3001\u4e91\u4f30\u7b97\u865a\u62df\u5316\u3001\u5bb9\u5668Docker\u3001OpenStack\u3001Kubernetes\u3001\u5de5\u5177\u3001SDN\u3001OVS\u3001DPDK\u3001Go\u3001Python\u3001C\/C++\u7f16\u7a0b\u6280\u672f\u7b49\u5185\u5bb9\uff0c\u6b22\u8fce\u4f60\u4eec\u5173\u6ce8\u3002<\/p>\n \u53c2\u8003\uff1a<\/p>\n","protected":false},"excerpt":{"rendered":" \u7528\u6237\u6001\u548c\u5185\u6838\u6001\u7a76\u7adf\u6709\u54ea\u4e9b\u901a\u4fe1\u65b9\u5f0f\u3002\u6211\u4eec\u5e73\u5e38\u5728\u5199\u4ee3\u7801\u65f6\uff0c\u4e00\u822c\u662f\u5728\u7528\u6237\u7a7a\u95f4\uff0c\u901a\u8fc7\u7cfb\u7edf\u8c03\u7528\u51fd\u6570\u6765\u8bbf\u95ee\u5185\u6838\u7a7a\u95f4\uff0c\u8fd9\u662f\u6700\u5e38\u7528\u7684\u4e00\u79cd\u7528\u6237\u6001\u548c\u5185\u6838\u6001\u901a\u4fe1\u7684\u65b9\u5f0f\u3002\u5b83\u672c\u8d28\u4e0a\u8fd8\u662f\u7528\u5230\u4e86\u6587\u4ef6\u7684\u8bfb\u5199\u64cd\u4f5c\uff0c\u6765\u5b8c\u6210\u7528\u6237\u6001\u548c\u5185\u6838\u6001\u7684\u901a\u4fe1\u3002\u6765\u5b8c\u6210\u7528\u6237\u6001\u548c\u5185\u6838\u7684\u901a\u4fe1\u3002\u7528\u6237\u6001\u4e0e\u5185\u6838\u6001\u901a\u4fe1\u6700\u5e38\u7528\u7684\u4e00\u79cd\u65b9\u5f0f\u3002<\/p>\n","protected":false},"author":1,"featured_media":294372,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[4275,4273,4276,4274,1008],"class_list":["post-294371","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-nhcs-2","tag-nhbl","tag-yhtkj","tag-jcwj","tag-tx"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/294371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=294371"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/294371\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/294372"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=294371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=294371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=294371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}root@ubuntu:~# ls \/proc\/\n1 1143 1345 1447 2 2292 29 331 393 44 63 70 76 acpi diskstats irq locks sched_debug sysvipc zoneinfo\n
root@ubuntu:~# ls \/proc\/1\/\nattr\/ cmdline environ io mem ns\/ pagemap schedstat stat timers\nautogroup comm exe limits mountinfo numa_maps personality sessionid statm uid_map\nauxv coredump_filter fd\/ loginuid mounts oom_adj projid_map setgroups status wchan\ncgroup cpuset fdinfo\/ map_files\/ mountstats oom_score root\/ smaps syscall \nclear_refs cwd\/ gid_map maps net\/ oom_score_adj sched stack task\/<\/code><\/pre>\n<\/p>\n
# ls \/sys\nblock bus class dev devices firmware fs hypervisor kernel module power<\/code><\/pre>\n<\/p>\n
#include \n#include \n#include \n