{"id":5379,"date":"2013-07-21T10:30:00","date_gmt":"2013-07-21T02:30:00","guid":{"rendered":"http:\/\/jpuyy.com\/?p=5379"},"modified":"2013-07-21T10:30:15","modified_gmt":"2013-07-21T02:30:15","slug":"tmpfs-usage","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=5379","title":{"rendered":"tmpfs\u4f7f\u7528\u65b9\u6cd5"},"content":{"rendered":"<p>\u5728\u4f7f\u7528df -h\u547d\u4ee4\uff0c\u4f1a\u53d1\u73b0\u5982\u4e0b\u4e00\u6761<\/p>\n<p>Filesystem \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Size \u00a0Used Avail Use% Mounted on<br \/>\n&#8230;<br \/>\ntmpfs \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a06.3G \u00a0 13M \u00a06.3G \u00a0 1% \/run\/shm<br \/>\n&#8230;<\/p>\n<p>tmpfs\u662fLinux\/Unix\u7cfb\u7edf\u4e0a\u7684\u4e00\u79cd\u57fa\u4e8e\u5185\u5b58\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u7c7b\u4f3c\u4e8eext3, ext4\u3002tmpfs\u53ef\u4ee5\u4f7f\u7528\u60a8\u7684\u5185\u5b58\u6216swap\u5206\u533a\u6765\u5b58\u50a8\u6587\u4ef6\u3002temfs\u4e3b\u8981\u5b58\u50a8\u6682\u5b58\u7684\u6587\u4ef6\u3002\u4ed6\u6709\u5982\u4e0b\u4e09\u4e2a\u4f18\u52bf\uff1a<br \/>\n1.\u52a8\u6001\u6587\u4ef6\u7cfb\u7edf\u7684\u5927\u5c0f\u3002<br \/>\n2.tmpfs \u7684\u53e6\u4e00\u4e2a\u4e3b\u8981\u7684\u597d\u5904\u662f\u5b83\u7684\u901f\u5ea6\u3002\u56e0\u4e3atmpfs\u4f4d\u7f6e\u4e3a\u5185\u5b58\u4e2d\uff0c\u8bfb\u5199\u51e0\u4e4e\u53ef\u4ee5\u662f\u77ac\u95f4\u7684\u3002<br \/>\n3.tmpfs \u6570\u636e\u5728\u91cd\u65b0\u542f\u52a8\u4e4b\u540e\u4e0d\u4f1a\u4fdd\u7559\uff0c\u56e0\u4e3a\u865a\u62df\u5185\u5b58\u672c\u8d28\u4e0a\u5c31\u662f\u6613\u5931\u7684\u3002\u6240\u4ee5\u6709\u5fc5\u8981\u505a\u4e00\u4e9b\u811a\u672c\u505a\u8bf8\u5982\u52a0\u8f7d\uff0c\u7ed1\u5b9a\u7684\u64cd\u4f5c\u3002tmpfs\u4e0d\u5177\u5907\u6301\u4e45\u6027\uff0c\u91cd\u542f\u540e\u6570\u636e\u4e0d\u4fdd\u7559\uff0c\u539f\u56e0\u5f88\u660e\u663e\uff0c\u5b83\u662f\u57fa\u4e8e\u5185\u5b58\u7684\u3002<\/p>\n<p>\u4e8c.\/dev\/shm\/\u76f8\u5173<\/p>\n<p>\/dev\/shm\u5c31\u662ftmpfs\u7684\u6302\u8f7d\u70b9\u4e86\uff0c\u5b83\u7684\u5927\u5c0f\u4e00\u822c\u4e3a\u5185\u5b58\u7684\u4e00\u534a(CentOS)\u3002\u5982\u679c\u8981\u4fee\u6539\/dev\/shm\u7684\u5927\u5c0f\u4e3a4GB\uff0c\u4fee\u6539\/etc\/fstab<\/p>\n<pre>tmpfs \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/dev\/shm \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0tmpfs \u00a0 defaults \u00a0 \u00a0 \u00a0 \u00a00 0<\/pre>\n<p>\u6539\u4e3a<\/p>\n<pre>tmpfs \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/dev\/shm \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0tmpfs \u00a0 defaults, size=4G \u00a0 \u00a0 \u00a0 \u00a00 0<\/pre>\n<p>\u7136\u540e\u91cd\u65b0\u6302\u8f7d\u751f\u6548<\/p>\n<pre>mount -o remount \/dev\/shm<\/pre>\n<p>\u4e09.tmpfs\uff08\/dev\/shm\uff09\u7684\u5e94\u7528<\/p>\n<p>\u65e2\u7136tmpfs\u901f\u5ea6\u5f88\u5feb\uff0c\u90a3\u5f88\u591a\u4e0d\u6015\u4e22\u7684\u4e1c\u897f\u653e\u5185\u5b58\u662f\u6700\u597d\u7684\u3002\u6bd4\u5982\u7ecf\u5e38\u4f7f\u7528\u7684\/tmp\u76ee\u5f55\uff0c\u53ef\u4ee5\u4f7f\u7528mount &#8211;bind\u547d\u4ee4\u5c06\/tmp\u6302\u8f7d\u6210tmpfs\u3002<\/p>\n<p>mkdir \/dev\/shm\/tmp<br \/>\nchmod 1777 \/dev\/shm\/tmp \/\/\u6ce8\u610f\u6743\u9650<br \/>\nmount &#8211;bind \/dev\/shm\/tmp \/tmp<\/p>\n<p>\u63a5\u4e0b\u6765\u5f88\u591a\u5e94\u7528\u7684\u4e34\u65f6\u6587\u4ef6, cache\u5c31\u53ef\u4ee5\u653e\u5728\/tmp\u4e0b\uff0c\u5982<\/p>\n<p>(1)\u5c06squid\u7684\u7f13\u5b58\u76ee\u5f55cache_dir\u653e\u5230\/tmp\u4e0b<br \/>\nvi \/etc\/squid\/squid.conf<br \/>\n\u4fee\u6539\u6210<br \/>\ncache_dir ufs \/tmp 256 16 256<br \/>\n\u8fd9\u91cc\u7684\u7b2c\u4e00\u4e2a256\u8868\u793a\u4f7f\u7528256M\u5185\u5b58,\u91cd\u542f\u4e00\u4e0bsquid\u670d\u52a1\uff0c\u8fd9\u6837\u7f13\u5b58\u76ee\u5f55\u90fd\u653e\u5728\u4e86tmpfs\u6587\u4ef6\u4e2d\u4e86\uff0c\u901f\u5ea6\u4e0d\u7528\u8bf4\u5427\u3002<\/p>\n<p>(2)\u5c06php\u7684session\u6587\u4ef6\u653e\u5728\/tmp\u4e0b<br \/>\n\u5bf9\u4e8e\u4e00\u4e2a\u8bbf\u95ee\u91cf\u5927\u7684\u4ee5apache php\u7684\u7f51\u7ad9\uff0c\u53ef\u80fdtmp\u4e0b\u7684\u4e34\u65f6\u6587\u4ef6\u90fd\u4f1a\u5f88\u591a\uff0c\u6bd4\u5982seesion\u6216\u8005\u4e00\u4e9b\u7f13\u5b58\u6587\u4ef6\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u628a\u5b83\u4fdd\u5b58\u5230tmpfs\u6587\u4ef6\u3002\u4fdd\u5b58seesion\u7684\u65b9\u6cd5\u5f88\u7b80\u5355\u4e86:\u53ea\u8981\u4fee\u6539php.ini\u5c31\u884c\u4e86\uff0c\u901a\u8fc7phpinfo\u6d4b\u8bd5\u6587\u4ef6\u67e5\u770b\u4f60\u7684php session\u5b58\u50a8\u4f4d\u7f6e\uff0c\u5982\u679c\u4e0d\u5728\/tmp\u4e0b\uff0c\u4fee\u6539php.ini\u6587\u4ef6\uff0c\u4fee\u6539\u5982\u4e0b\uff1a<br \/>\nsession.save_path = \u201c\/tmp\u201d<\/p>\n<p>(3)\u5c06\u670d\u52a1\u7684socket\u6587\u4ef6\u653e\u5728\/tmp\u4e0b<br \/>\nnginx.socket\u548cmysql.sock<\/p>\n<p>\u81f3\u4e8etmpfs\u7684\u5176\u4ed6\u5e94\u7528\uff0c\u6211\u60f3\u5927\u5bb6\u53ef\u80fd\u901a\u8fc7\u8fd9\u7bc7\u6587\u7ae0\u4f1a\u6709\u6240\u542f\u53d1\u3002\u518d\u6b21\u5f3a\u8c03\u4e0b\uff1atmpfs \u6570\u636e\u5728\u91cd\u65b0\u542f\u52a8\u4e4b\u540e\u4e0d\u4f1a\u4fdd\u7559\uff0c\u91cd\u542ftmpfs \u6570\u636e\u4f1a\u4e22\u5931\uff0c\u6240\u4ee5\u6709\u5fc5\u8981\u505a\u4e00\u4e9b\u811a\u672c\u505a\u8bf8\u5982\u52a0\u8f7d\uff0c\u7ed1\u5b9a\u7684\u64cd\u4f5c\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4f7f\u7528df -h\u547d\u4ee4\uff0c\u4f1a\u53d1\u73b0\u5982\u4e0b\u4e00\u6761 Filesystem \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Size \u00a0Used Avail Use% Mounted on &#8230; tmpfs \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a06.3G \u00a0 13M \u00a06.3G \u00a0 1% \/run\/shm &#8230; tmpfs\u662fLinux\/Unix\u7cfb\u7edf\u4e0a\u7684\u4e00\u79cd\u57fa\u4e8e\u5185\u5b58\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u7c7b\u4f3c\u4e8eext3, ext4\u3002tmpfs\u53ef\u4ee5\u4f7f\u7528\u60a8\u7684\u5185\u5b58\u6216swap\u5206\u533a\u6765\u5b58\u50a8\u6587\u4ef6\u3002temfs\u4e3b\u8981\u5b58\u50a8\u6682\u5b58\u7684\u6587\u4ef6\u3002\u4ed6\u6709\u5982\u4e0b\u4e09\u4e2a\u4f18\u52bf\uff1a 1.\u52a8\u6001\u6587\u4ef6\u7cfb\u7edf\u7684\u5927\u5c0f\u3002 2.tmpfs \u7684\u53e6\u4e00\u4e2a\u4e3b\u8981\u7684\u597d\u5904\u662f\u5b83\u7684\u901f\u5ea6\u3002\u56e0\u4e3atmpfs\u4f4d\u7f6e\u4e3a\u5185\u5b58\u4e2d\uff0c\u8bfb\u5199\u51e0\u4e4e\u53ef\u4ee5\u662f\u77ac\u95f4\u7684\u3002 3.tmpfs \u6570\u636e\u5728\u91cd\u65b0\u542f\u52a8\u4e4b\u540e\u4e0d\u4f1a\u4fdd\u7559\uff0c\u56e0\u4e3a\u865a\u62df\u5185\u5b58\u672c\u8d28\u4e0a\u5c31\u662f\u6613\u5931\u7684\u3002\u6240\u4ee5\u6709\u5fc5\u8981\u505a\u4e00\u4e9b\u811a\u672c\u505a\u8bf8\u5982\u52a0\u8f7d\uff0c\u7ed1\u5b9a\u7684\u64cd\u4f5c\u3002tmpfs\u4e0d\u5177\u5907\u6301\u4e45\u6027\uff0c\u91cd\u542f\u540e\u6570\u636e\u4e0d\u4fdd\u7559\uff0c\u539f\u56e0\u5f88\u660e\u663e\uff0c\u5b83\u662f\u57fa\u4e8e\u5185\u5b58\u7684\u3002 \u4e8c.\/dev\/shm\/\u76f8\u5173 \/dev\/shm\u5c31\u662ftmpfs\u7684\u6302\u8f7d\u70b9\u4e86\uff0c\u5b83\u7684\u5927\u5c0f\u4e00\u822c\u4e3a\u5185\u5b58\u7684\u4e00\u534a(CentOS)\u3002\u5982\u679c\u8981\u4fee\u6539\/dev\/shm\u7684\u5927\u5c0f\u4e3a4GB\uff0c\u4fee\u6539\/etc\/fstab tmpfs \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[157],"class_list":["post-5379","post","type-post","status-publish","format-standard","hentry","category-linux","tag-tmpfs"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/5379","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5379"}],"version-history":[{"count":5,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/5379\/revisions"}],"predecessor-version":[{"id":5386,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/5379\/revisions\/5386"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}