添加阿里云服务器的swap分区
Posted
阿里云默认没有开启swap分区!小内存测试服务器常爆机!
Cannot allocate memory - identify
Cannot allocate memory - convert -size 240x240 xc:'rgb(142,125,214)' -pointsize 140 -font
查看 swap 空间大小
$ sudo swapon -s
Filename Type Size Used Priority
首先先登录root
sudo su -
1、创建用于交换分区的文件:
# dd if=/dev/zero of=/mnt/swapfile bs=1k count=1024000
1024000+0 records in
1024000+0 records out
1048576000 bytes (1.0 GB) copied, 17.7815 s, 59.0 MB/s
2、设置交换分区文件:
# mkswap /mnt/swapfile
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=c09e7797-1481-4d87-a620-29aa24ede564
3、立即启用交换分区文件
swapon /mnt/swapfile
# free -m
total used free shared buffers cached
Mem: 992 914 77 0 5 70
-/+ buffers/cache: 839 153
Swap: 999 0 999
注:如果在 /etc/rc.local 中有 swapoff -a 需要修改为 swapon -a
4、设置开机时自启用 SWAP 分区:
需要修改文件 /etc/fstab 中的 SWAP 行,添加
# echo "/mnt/swapfile swap swap defaults 0 0" >>/etc/fstab
注:/mnt/swapfile 路径可以修改,可以根据创建的 SWAP 文件具体路径来配置。
5、修改 swpapiness 参数
# echo 30 >/proc/sys/vm/swappiness
可以使用下述方法临时修改此参数,假设我们配置为空闲内存少于 30% 时才使用 SWAP 分区:
# vim /etc/sysctl.conf
vm.swappiness=30
# sysctl -p
ref:
http://coderschool.cn/1486.html
http://stackoverflow.com/questions/11013755/rails-assets-pipeline-cannot-allocate-memory-nodejs
此文章 短链接: http://dlj.bz/XxNvnS
Tag Cloud
AFNetworking(1)
AngularJS(2)
Devise(1)
Devops(1)
Homebrew(1)
MacOSX(11)
Rails4(2)
TTS(1)
Unauthorized(1)
analysis(1)
android(1)
apache(2)
api(1)
assets(5)
backup(3)
blog(1)
bower(1)
bundle(2)
cache(1)
capistrano(2)
capistrano3(2)
centos(4)
chrome-extension(1)
crontab(1)
css(1)
curl(1)
data(2)
deploy(2)
dlj(1)
dropbox(3)
elasticsearch(1)
fqa(1)
gem(7)
geobean(1)
gfw(1)
gis(1)
git(4)
github(2)
gitlib(1)
google(1)
httpd(1)
iOS(2)
java(1)
javascript(2)
jekyll(1)
js(2)
letsencrypt(1)
linode(2)
linux(16)
memcached(1)
mongodb(5)
mongoid(2)
mongomapper(1)
mtr(1)
mysql(2)
newrelic(1)
nginx(7)
nodejs(1)
notejs(1)
observer(1)
octopress(1)
omniauth-oauth(1)
openlayers(1)
paginate(2)
passenger(2)
pipeline(1)
plugin(2)
production(1)
proxy(3)
rails(23)
rails3(4)
rake(1)
restful_authentication(1)
ruby(28)
rvm(6)
search(1)
siege(1)
sinatra(2)
skill(7)
socks(1)
solr(1)
sql(2)
sqlserver(1)
ssh(6)
ssl(1)
story(4)
sublime-text(3)
sunspot(1)
sweeper(1)
theme(1)
tile(1)
tools(1)
ubuntu(19)
vagrantbox(2)
vps(2)
web(1)
webkit(1)
webpack(1)
win(3)
xcode(2)
yarn(1)
yum(1)
佛(3)
创业(1)
压力测试(2)
正则(1)
转载(7)