{"id":1964,"date":"2019-08-31T14:25:26","date_gmt":"2019-08-31T07:25:26","guid":{"rendered":"https:\/\/tino.vn\/?post_type=ht_kb&#038;p=1964"},"modified":"2019-09-15T10:34:46","modified_gmt":"2019-09-15T03:34:46","slug":"cach-su-dung-thu-muc-dev-shm-ram-disk","status":"publish","type":"ht_kb","link":"https:\/\/tino.vn\/blog\/docs\/cach-su-dung-thu-muc-dev-shm-ram-disk\/","title":{"rendered":"C\u00e1ch s\u1eed d\u1ee5ng th\u01b0 m\u1ee5c \/dev\/shm  RAM disk."},"content":{"rendered":"<p>RAM Disk l\u00e0 m\u1ed9t ph\u1ea7n dung l\u01b0\u1ee3ng v\u1eadt l\u00fd c\u1ee7a RAM \u0111\u01b0\u1ee3c format d\u01b0\u1edbi d\u1ea1ng file system (t\u1eadp tin h\u1ec7 th\u1ed1ng). T\u1eeb file sytsem n\u00e0y b\u1ea1n c\u00f3 th\u1ec3 mount n\u00f3 v\u00e0o 1 th\u01b0 m\u1ee5c v\u00e0 s\u1eed d\u1ee5ng nh\u01b0 1 ph\u00e2n v\u00f9ng \u1ed5 c\u1ee9ng.<\/p>\n<p>Th\u01b0 m\u1ee5c n\u00e0y th\u01b0\u1eddng d\u00f9ng v\u1edbi m\u1ee5c \u0111\u00edch l\u01b0u tr\u1eef c\u00e1c file th\u1eddi h\u1ea1n l\u00e2u d\u00e0i, d\u1ec5 thay \u0111\u1ed5i n\u1ed9i dung, ghi \u0111\u00e8, xo\u00e1 v\u00e0 dung l\u01b0\u1ee3ng nh\u1ecf.<\/p>\n<p class=\"\"><span class=\"text-node\">Ph\u1ea7n l\u1edbn c\u00e1c h\u1ec7 \u0111i\u1ec1u h\u00e0nh\u00a0<\/span><b><span class=\"text-node\">Linux\u00a0<\/span><\/b><span class=\"text-node\">hi\u1ec7n nay \u0111\u1ec1u c\u00f3 s\u1eb5n\u00a0<\/span><b><span class=\"text-node\">RAM disk<\/span><\/b><span class=\"text-node\">. \u0110\u00e2y l\u00e0 m\u1ed9t\u00a0<\/span><b><span class=\"text-node\">module\u00a0<\/span><\/b><span class=\"text-node\">trong\u00a0<\/span><b><span class=\"text-node\">Kernel<\/span><\/b><span class=\"text-node\">. H\u1ec7 \u0111i\u1ec1u h\u00e0nh\u00a0<\/span><b><span class=\"text-node\">Ubuntu<\/span><span class=\"text-node\">\u00a0&amp;<\/span><span class=\"text-node\">CentOS<\/span>\u00a0<\/b><span class=\"text-node\">th\u01b0\u1eddng m\u1eb7c \u0111\u1ecbnh g\u1eafn n\u00f3 v\u00e0o th\u01b0 m\u1ee5c<\/span><b class=\"\"><span class=\"text-node\">\u00a0\/dev\/shm<\/span><\/b><span class=\"text-node\">. V\u00e0 v\u1edbi dung l\u01b0\u1ee3ng b\u1eb1ng n\u1eeda s\u1ed1\u00a0<\/span><b><span class=\"text-node\">RAM\u00a0<\/span><\/b><span class=\"text-node\">m\u00e0 b\u1ea1n \u0111ang c\u00f3.<\/span><br \/>\n<em><span class=\"text-node\">Xem dung l\u01b0\u1ee3ng:<\/span><\/em><\/p>\n<pre>$ df -h \/dev\/shm<\/pre>\n<div class=\"\"><\/div>\n<pre>Filesystem Size Used Avail Use% Mounted on\r\ntmpfs 920M 0 920M 0% \/dev\/shm<\/pre>\n<div><\/div>\n<p class=\"\"><span class=\"text-node\">\u0110\u1ec3 thay \u0111\u1ed5i dung l\u01b0\u1ee3ng n\u00e0y, c\u00f3 th\u1ec3 thay \u0111\u1ed5i file \/etc\/fstab hay th\u00eam d\u00f2ng sau:<\/span><\/p>\n<pre>$ mount -o remount,size=1G \/dev\/shm<\/pre>\n<p>Ki\u1ec3m tra :<\/p>\n<pre>Filesystem Size Used Avail Use% Mounted on\r\n\/dev\/vda1 55G 26G 27G 49% \/\r\ndevtmpfs 909M 0 909M 0% \/dev\r\ntmpfs 1.0G 64K 1.0G 1% \/dev\/shm\r\ntmpfs 920M 8.5M 911M 1% \/run\r\ntmpfs 920M 0 920M 0% \/sys\/fs\/cgroup\r\ntmpfs 184M 0 184M 0% \/run\/user\/0<\/pre>\n<p>B\u1ea1n c\u00f3 th\u1ec3 th\u1ea5y th\u01b0 m\u1ee5c \/dev\/shm dung l\u01b0\u1ee3ng hi\u1ec7n t\u1ea1i l\u00e0 1GB.<\/p>\n<p><em id=\"__mceDel\"><b><span class=\"text-node\">L\u01b0u c\u1ea5u h\u00ecnh v\u0129nh vi\u1ec5n:<\/span><\/b><\/em><\/p>\n<p>S\u1eeda ho\u1eb7c th\u00eam d\u00f2ng c\u1ea5u h\u00ecnh sau v\u00e0o file: \/etc\/fstab<\/p>\n<pre>none      \/dev\/shm        tmpfs   defaults,size=1G        0 0<\/pre>\n<div><\/div>\n<p>&nbsp;<\/p>\n<p><strong>T\u1ea1o th\u01b0 m\u1ee5c ramdisk t\u01b0\u01a1ng t\u1ef1.<\/strong><\/p>\n<p class=\"\"><span class=\"text-node\">Ngo\u00e0i ra t\u01b0\u01a1ng t\u1ef1 v\u1edbi c\u00e1c th\u01b0 m\u1ee5c ramdisk kh\u00e1c, B\u1ea1n c\u00f2n c\u00f3 th\u1ec3 d\u00f9ng l\u1ec7nh <\/span><b><span class=\"text-node\">mount\u00a0<\/span><\/b><span class=\"text-node\">nh\u01b0 sau \u0111\u1ec3 t\u1ea1o m\u1edbi m\u1ed9t ramdisk. Ch\u1eb3ng h\u1ea1n t\u00f4i c\u1ea7n 1 th\u01b0 m\u1ee5c ramdisk v\u1edbi \u0111\u01b0\u1eddng d\u1eabn : <strong>\/tmp\/ramdisk\/\u00a0<\/strong><\/span><\/p>\n<pre>$ mkdir \/tmp\/ramdisk; chmod 777 \/tmp\/ramdisk \r\n<span class=\"text-node\">$ mount -t tmpfs -o size=256M tmpfs \/tmp\/ramdisk\/<\/span><\/pre>\n<div><\/div>\n<div class=\"\"><em id=\"__mceDel\"><b><span class=\"text-node\">Kh\u1eafc ph\u1ee5c nh\u01b0\u1ee3c \u0111i\u1ec3m m\u1ea5t d\u1eef li\u1ec7u khi t\u1eaft m\u00e1y<\/span><\/b><\/em><\/div>\n<div>L\u01b0u \u00fd: Khi reboot m\u00e1y m\u1ecdi d\u1eef li\u1ec7u tr\u00ean ramdisk s\u1ebd m\u1ea5t.<\/div>\n<p class=\"\"><em id=\"__mceDel\"><span class=\"text-node\">B\u1ea1n n\u00ean t\u1ea1o m\u1ed9t th\u01b0 m\u1ee5c c\u00f3 c\u00f9ng n\u1ed9i dung v\u1edbi\u00a0<\/span><b><span class=\"text-node\">RAM disk<\/span><\/b><span class=\"text-node\">. Sau \u0111\u00f3 d\u00f9ng\u00a0<\/span><b><span class=\"text-node\">rsync\u00a0<\/span><\/b><span class=\"text-node\">\u0111\u1ec3 \u0111\u1ed3ng b\u1ed9 h\u00f3a d\u1eef li\u1ec7u. C\u0169ng c\u00f3 th\u1ec3 k\u1ebft h\u1ee3p v\u1edbi\u00a0<\/span><b><span class=\"text-node\">cron\u00a0<\/span><\/b><span class=\"text-node\">\u0111\u1ec3 \u0111\u1ecbnh k\u1ef3 \u0111\u1ed3ng b\u1ed9 d\u1eef li\u1ec7u. \u0110\u1ec3 t\u1ea3i d\u1eef li\u1ec7u l\u00ean khi b\u1eadt m\u00e1y, c\u1ea7n t\u1ea1o m\u1ed9t\u00a0<\/span><b><span class=\"text-node\">script<\/span><\/b><span class=\"text-node\">v\u00e0 \u0111\u1eb7t t\u1ea1i th\u01b0 m\u1ee5c<\/span><b class=\"\"><span class=\"text-node\">\u00a0\/etc\/init.d<\/span><\/b><span class=\"text-node\">. Sau \u0111\u00f3 d\u00f9ng l\u1ec7nh\u00a0<\/span><b><span class=\"text-node\">update-rc.d<\/span><\/b><span class=\"text-node\">\u00a0\u0111\u1ec3 th\u00eam v\u00e0o danh s\u00e1ch c\u00e1c ph\u1ea7n m\u1ec1m c\u1ea7n kh\u1edfi \u0111\u1ed9ng c\u00f9ng\u00a0<\/span><b><span class=\"text-node\">Linux<\/span><\/b><span class=\"text-node\">.<\/span><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>RAM Disk l\u00e0 m\u1ed9t ph\u1ea7n dung l\u01b0\u1ee3ng v\u1eadt l\u00fd c\u1ee7a RAM \u0111\u01b0\u1ee3c format d\u01b0\u1edbi d\u1ea1ng file system (t\u1eadp tin h\u1ec7 th\u1ed1ng). T\u1eeb file sytsem n\u00e0y b\u1ea1n c\u00f3 th\u1ec3 mount n\u00f3 v\u00e0o 1 th\u01b0 m\u1ee5c v\u00e0 s\u1eed d\u1ee5ng nh\u01b0 1 ph\u00e2n v\u00f9ng \u1ed5 c\u1ee9ng. Th\u01b0 m\u1ee5c n\u00e0y th\u01b0\u1eddng d\u00f9ng v\u1edbi m\u1ee5c \u0111\u00edch l\u01b0u tr\u1eef c\u00e1c file [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":16424,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"tags":[],"ht_kb_category":[17],"class_list":["post-1964","ht_kb","type-ht_kb","status-publish","format-standard","has-post-thumbnail","hentry","ht_kb_category-huong-dan-ve-cloud-vps"],"_links":{"self":[{"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/ht_kb\/1964","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/ht_kb"}],"about":[{"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/comments?post=1964"}],"version-history":[{"count":0,"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/ht_kb\/1964\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/media\/16424"}],"wp:attachment":[{"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/media?parent=1964"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/tags?post=1964"},{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/tino.vn\/blog\/wp-json\/wp\/v2\/ht_kb_category?post=1964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}