Total Pageviews

Thursday 25 July 2019

给openvz vps增加swap分区的办法

#!/bin/bash
#Addition SWAP For OpenVZ
echo 'Start adding SWAP space ......';
SWAP="${1:-512}";
NEW="$[SWAP*1024]";
TEMP="${NEW//?/ }";
OLD="${TEMP:1}0";
umount /proc/meminfo 2> /dev/null
sed "/^Swap\(Total\|Free\):/s,$OLD,$NEW," /proc/meminfo > /etc/fake_meminfo
mount --bind /etc/fake_meminfo /proc/meminfo
echo 'Add the ready!'; 以上代码来自https://github.com/TestSmirk/ovz-swap/raw/master/swap4ovz.sh 在linux vps上, wget https://github.com/TestSmirk/ovz-swap/raw/master/swap4ovz.sh chmod 755 swap4ovz.sh
./swap4ovz.sh

然后运行free -m 一看,果然增加了512mb虚拟内存。
不过重启vps后,会失效 需要加入开机启动。

from  https://github.com/TestSmirk/ovz-swap

No comments:

Post a Comment