
{"id":4057,"date":"2014-11-04T12:19:40","date_gmt":"2014-11-04T12:19:40","guid":{"rendered":"http:\/\/tapchicntt.com\/?p=4057"},"modified":"2023-08-01T11:44:59","modified_gmt":"2023-08-01T04:44:59","slug":"cach-tao-ram-ao-phan-vung-swap-cho-vps-linux","status":"publish","type":"post","link":"https:\/\/tapchicntt.com\/cach-tao-ram-ao-phan-vung-swap-cho-vps-linux\/","title":{"rendered":"C\u00e1ch t\u1ea1o ram \u1ea3o (ph\u00e2n v\u00f9ng swap) cho VPS Linux"},"content":{"rendered":"\n<p>Th\u00f4ng th\u01b0\u1eddng khi mua VPS \u1edf n\u01b0\u1edbc ngo\u00e0i th\u00ec VPS s\u1ebd kh\u00f4ng setup s\u1eb5n Ram \u1ea3o (Virtual memory) cho m\u00ecnh. N\u00ean ch\u00edng ch\u00fang ta ph\u1ea3i t\u1ea1o ra n\u00f3 n\u1ebfu b\u1ea1n mu\u1ed1n s\u1eed d\u1ee5ng. B\u00e0i h\u01b0\u1edbng d\u1eabn n\u00e0y s\u1ebd h\u01b0\u1edbng d\u1eabn c\u00e1c b\u1ea1n t\u1ea1o ram \u1ea3o cho vps c\u1ee7a m\u00ecnh.<\/p>\n\n\n\n<p>Virtual memory l\u00e0 g\u00ec v\u00e0 t\u1ea1i sao ph\u1ea3i d\u00f9ng ?<\/p>\n\n\n\n<p>Khi h\u1ec7 \u0111i\u1ec1u h\u00e0nh th\u1ef1c thi m\u1ed9t t\u00e1c v\u1ee5, m\u1ed9t c\u00f4ng vi\u1ec7c n\u00e0o \u0111\u00f3 th\u00ec n\u00f3 c\u1ea7n Ram v\u00e0 CPU. Gi\u1ea3 s\u1eed t\u1ea1i m\u1ed9t th\u1eddi \u0111i\u1ec3m n\u00e0o \u0111\u00f3 n\u00f3 th\u1ef1c hi\u1ec7n r\u1ea5t nhi\u1ec1u c\u00f4ng vi\u1ec7c v\u00e0 ng\u1ed1n h\u1ebft Ram c\u1ee7a VPS v\u00e0 n\u1ebfu t\u00ecnh tr\u1ea1ng n\u00e0y k\u00e9o d\u00e0i th\u00ec Services (D\u1ecbch v\u1ee5) c\u1ee7a b\u1ea1n s\u1ebd b\u1ecb crash (B\u1ecb l\u1ed7i v\u00e0 kh\u00f4ng ho\u1ea1t \u0111\u1ed9ng n\u1eefa) th\u1eadm ch\u00ed c\u00f3 th\u1ec3 treo VPS, Server c\u1ee7a b\u1ea1n.<\/p>\n\n\n\n<p>Do \u0111\u00f3 l\u1eddi khuy\u00ean c\u1ee7a m\u00ecnh l\u00e0 c\u00e1c b\u1ea1n n\u00ean t\u1ea1o Ram \u1ea3o \u0111\u1ec3 khi Ram th\u1eadt c\u1ee7a VPS, Server m\u00ecnh b\u1ecb h\u1ebft, th\u00ec h\u1ec7 \u0111i\u1ec1u h\u00e0nh s\u1ebd d\u00f9ng Ram \u1ea3o n\u00e0y \u0111\u1ec3 s\u1eed d\u1ee5ng ti\u1ebfp.<\/p>\n\n\n\n<p>C\u00e2u h\u1ecfi \u0111\u1eb7t ra l\u00fac n\u00e0y l\u00e0 : T\u1ea1o nh\u01b0 th\u1ebf n\u00e0o v\u00e0 bao nhi\u00eau l\u00e0 \u0111\u1ee7 l\u00e0 ph\u00f9 h\u1ee3p ?<\/p>\n\n\n\n<p>T\u1ed1c \u0111\u1ed9 truy xu\u1ea5t c\u1ee7a Ram nhanh h\u01a1n c\u1ee7a Disk r\u1ea5t l\u00e0 nhi\u1ec1u, cho n\u00ean c\u00e1c b\u1ea1n \u0111\u1eebng qu\u00e1 l\u1ea1m d\u1ee5ng khi t\u1ea1o nhi\u1ec1u dung l\u01b0\u1ee3ng cho Virtual Memory, n\u1ebfu c\u00e1c b\u1ea1n t\u1ea1o qu\u00e1 nhi\u1ec1u th\u00ec khi VPS s\u1eed d\u1ee5ng nhi\u1ec1u Ram \u1ea3o s\u1ebd l\u00e0m cho VPS m\u00ecnh ch\u1eadm \u0111i.<\/p>\n\n\n\n<p>Theo kinh nghi\u1ec7m c\u1ee7a m\u00ecnh th\u00ec Ram 512MB th\u00ec t\u1ea1o t\u1eeb 512-1024MB, 1GB tr\u1edf l\u00ean th\u00ec c\u00e1c b\u1ea1n t\u1ea1o Ram \u1ea3o b\u1eb1ng dung l\u01b0\u1ee3ng Ram th\u1eadt l\u00e0 \u0111\u01b0\u1ee3c.<\/p>\n\n\n\n<p>B\u00e2y gi\u1edd m\u00ecnh s\u1ebd ch\u1ec9 c\u00e1c b\u1ea1n t\u1ea1o Ram \u1ea3o.<\/p>\n\n\n\n<p>==&gt; \u0110\u1ea7u ti\u00ean b\u1ea1n \u0111\u0103ng nh\u1eadp SSH v\u00e0o VPS b\u1eb1ng t\u00e0i kho\u1ea3n root.<\/p>\n\n\n\n<p>N\u1ebfu s\u1eed d\u1ee5ng Windows th\u00ec c\u00e1c b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng ph\u1ea7n m\u1ec1m <a href=\"http:\/\/www.putty.org\/\" target=\"_blank\" rel=\"noopener\">Putty<\/a>.<\/p>\n\n\n\n<p>N\u1ebfu s\u1eed d\u1ee5ng Mac th\u00ec v\u00e0o Terminal: <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nssh -p port root@ip\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Create Storage File<\/h2>\n\n\n\n<p>Nh\u1eadp \u0111o\u1ea1n l\u1ec7nh b\u00ean d\u01b0\u1edbi v\u00e0o Command Line b\u00ean d\u01b0\u1edbi \u0111\u1ec3 t\u1ea1o 512MB Swap file (1024 * 512MB = 524288 block size, N\u1ebfu c\u00e1c b\u1ea1n mu\u1ed1n t\u1ea1o v\u1edbi dung l\u01b0\u1ee3ng kh\u00e1c th\u00ec c\u1ee9 d\u00f9ng c\u00f4ng th\u1ee9c n\u00e0y, r\u1ed3i l\u1ea5y k\u1ebft qu\u1ea3 thay th\u1ebf v\u00e0o bi\u1ebfn count)<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ndd if=\/dev\/zero of=\/swapfile bs=1024 count=524288\n<\/pre><\/div>\n\n\n<p>Command tr\u00ean s\u1ebd set up a Linux swap area in a file.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nmkswap \/swapfile\n<\/pre><\/div>\n\n\n<p>V\u00ec l\u00fd do b\u1ea3o m\u1eadt ta ph\u1ea3i config \u0111\u00fang quy\u1ec1n \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o ch\u1ec9 c\u00f3 User root \u0111\u01b0\u1ee3c ph\u00e9p \u0111\u1ecdc file n\u00e0y.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nchown root:root \/swapfile\nchmod 0600 \/swapfile\n<\/pre><\/div>\n\n\n<p>Cu\u1ed1i c\u00f9ng activate n\u00f3.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nswapon \/swapfile\n<\/pre><\/div>\n\n\n<p>\u0110\u1ec3 file swap \u0111\u01b0\u1ee3c t\u1ea1o l\u1ea1i sau khi reboot VPS, Server th\u00ec ta ph\u1ea3i l\u00e0m nh\u01b0 sau.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nvi \/etc\/fstab\n<\/pre><\/div>\n\n\n<p>th\u00eam v\u00e0o cu\u1ed1i file<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\/swapfile swap swap defaults 0 0\n<\/pre><\/div>\n\n\n<p>Ch\u00fac c\u00e1c b\u1ea1n th\u1ef1c hi\u1ec7n th\u00e0nh c\u00f4ng!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Th\u00f4ng th\u01b0\u1eddng khi mua VPS \u1edf n\u01b0\u1edbc ngo\u00e0i th\u00ec VPS s\u1ebd kh\u00f4ng setup s\u1eb5n Ram \u1ea3o (Virtual memory) cho m\u00ecnh. [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":7823,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[174],"tags":[],"class_list":["post-4057","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps-huong-dan"],"views":575,"_links":{"self":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/4057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/comments?post=4057"}],"version-history":[{"count":13,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/4057\/revisions"}],"predecessor-version":[{"id":7824,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/4057\/revisions\/7824"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/media\/7823"}],"wp:attachment":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/media?parent=4057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/categories?post=4057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/tags?post=4057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}