TUTORIAL Use Swap File at Digital Ocean

jrglass

Guru
Joined
Oct 18, 2007
Messages
302
Reaction score
20
I have a small server at DO. It was losing its registration with all for providers. After a reboot they work DO suggested adding a swap drive. will this effect the PBXIAF? Should the swap size be 2x 512 =1G and swappiness be set at 10?

Thanks,

Jeff


root@U140464:~# free -m
total used free shared buffers cached
Mem: 490 402 87 5 14 226
-/+ buffers/cache: 160 329
Swap: 0 0 0
root@U140464:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda 20G 3.0G 16G 17% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 235M 4.0K 235M 1% /dev
tmpfs 50M 336K 49M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 246M 0 246M 0% /run/shm
none 100M 0 100M 0% /run/user
 

Huckda

Guru
Joined
May 28, 2013
Messages
143
Reaction score
27
wow havent heard of a modern linux system need'n swap drive in a long while
 

Jay Deal

Phhhhhhhhttttttt :)
Joined
Dec 26, 2013
Messages
267
Reaction score
85
wow havent heard of a modern linux system need'n swap drive in a long while


I read somewhere recently that swap drives put excessive wear on SSD's and should not be used on systems that contain them as boot drives. While I am no Linux expert, I can speak to something similar to this claim as I just had a year old Plextor SSD fail from what I think was my constant hybernations. Hybernating is supposedly like a swap file in that it copies the contents of dynamic memory to the drive and I guess my regular hybernations instead of sleeping or shutting down put excessive wear on the static memory components typical of SSDs.

It just goes to show everytime there is a supposed new bullet proof storage technology that comes out, it in the end will have some major issue and while it will be faster than what it replaced, it still won't be reliable enough to last more than 5 years if it makes it half that long.
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,168
Reaction score
5,199
The context here is a cloud-based, virtual machine with 512MB RAM. If it runs out of RAM, something has to happen. Either running apps get killed off by the Linux kernel, or you need a swap file. PIAF and Raspberry Pi builds have ALWAYS had either a swap file or swap partition. With Incredible PBX, you're designing and deploying your own operating system. Inclusion of a swap file or swap partition is and always has been the standard way of building Linux file systems. Digital Ocean builds the VM platform for you and apparently does not include a swap file by default. Who knows why?? It may very well be because of the wear and tear on their SSDs. Or maybe they want to encourage use of a more expensive platform with more RAM. :Angel anim:

Whether the lack of a swap file causes a problem depends upon the processing load on your virtual machine. But running a 512MB appliance with Asterisk, Apache (multiple instances), PHP, FreePBX, MySQL, SendMail, etc. with no swap file is a risky business IMHO. We use Digital Ocean as a sandbox so it doesn't much matter. For production use with RentPBX or a dedicated server, there should always be a swap file or swap partition IMHO.

Here's the Ubuntu method on DO. It will activate the swap file when you reach 90% RAM usage.
Code:
dd if=/dev/zero of=/swapfile bs=1024 count=1024k
chown root:root /swapfile
chmod 0600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile      none    swap    sw      0      0" >> /etc/fstab
echo 10 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf
free -h

Here's the CentOS method on DO. It will activate the swap file when you reach 90% RAM usage.
Code:
dd if=/dev/zero of=/swapfile bs=1024 count=1024k
chown root:root /swapfile
chmod 0600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile          swap            swap    defaults        0 0" >> /etc/fstab
sysctl vm.swappiness=10
echo vm.swappiness=10 >> /etc/sysctl.conf
free -h
cat /proc/sys/vm/swappiness
 

Huckda

Guru
Joined
May 28, 2013
Messages
143
Reaction score
27
I always include one.. but haven't seen it USED but my servers are more fileservers for small businesses and schools... they rarely touch 1/2 the RAM in the box :)
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,168
Reaction score
5,199
Actually, the installer for CentOS got an out-of-memory error and the kernel force-closed another app to let the install proceed. Didn't see that on the Ubuntu build, but adding the swap file improved performance during the install dramatically. Complete install now takes 15 minutes! Running free -h after the Ubuntu install completed showed that 25% of the swap file had been used.
 

Adam Kayden

Member
Joined
Dec 28, 2013
Messages
53
Reaction score
3
i have the same error installing on Amazon and DO. I'm able to install (removing # to create swapfile) with this - http://nerdvittles.com/?p=10079


Code:
cd /root
wget http://incrediblepbx.com/incrediblepbx11.4.centos.tar.gz
tar zxvf incrediblepbx*
./create-swapfile-DO
./IncrediblePBX*
 

Twilight Sparkle

https://voip.ms/en/invite/MjM2MjQ4
Joined
Jul 21, 2013
Messages
448
Reaction score
57
The context here is a cloud-based, virtual machine with 512MB RAM. If it runs out of RAM, something has to happen. Either running apps get killed off by the Linux kernel, or you need a swap file. PIAF and Raspberry Pi builds have ALWAYS had either a swap file or swap partition. With Incredible PBX, you're designing and deploying your own operating system. Inclusion of a swap file or swap partition is and always has been the standard way of building Linux file systems. Digital Ocean builds the VM platform for you and apparently does not include a swap file by default. Who knows why?? It may very well be because of the wear and tear on their SSDs. Or maybe they want to encourage use of a more expensive platform with more RAM. :Angel anim:
Whether the lack of a swap file causes a problem depends upon the processing load on your virtual machine. But running a 512MB appliance with Asterisk, Apache (multiple instances), PHP, FreePBX, MySQL, SendMail, etc. with no swap file is a risky business IMHO. We use Digital Ocean as a sandbox so it doesn't much matter. For production use with RentPBX or a dedicated server, there should always be a swap file or swap partition IMHO.


im using that IncrediblePBX12-Ubuntu14.04 from http://sourceforge.net/projects/pbxinaflash/files/IncrediblePBX12-Ubuntu14.04/
so do i need to use the command above or does it do it for me automatic during the install. im using Digital Ocean $20 plan. & used your Promo code & got $10 free.


by the way i saw a new file uploaded in this folder called: installmp3stt.tar.gz, so i has to install this? or no?



UPDATE: i posted a photo below of what my Memory looks like after i did the command.... its kinda scaring me.
tar zxvf incrediblepbx12*
./create-swapfile-DO
./IncrediblePBX12*
 

Twilight Sparkle

https://voip.ms/en/invite/MjM2MjQ4
Joined
Jul 21, 2013
Messages
448
Reaction score
57
Your image (which I've deleted) showed a swap file had been activated so you're good to go.


do you Recommend 2GB or 1GB Memory on Digital Ocean? to use the swap file.

using Ubuntu 14.04 for IncrediblePBX12-Ubuntu14.04
 

Twilight Sparkle

https://voip.ms/en/invite/MjM2MjQ4
Joined
Jul 21, 2013
Messages
448
Reaction score
57
512MB RAM with 1GB swap

i dont see any options to allow 1GB + 512MB ram, Digital Ocean only has plans for $5 512MB, $10 1GB, $20 2GB
so do i need to stay with 2GB and let the swap do its thing like i had it setup in the photo u said u removed

i did another server with 1GB not 2GB photo below of what i has now + i still hear choppy incoming calls

right now the Digital Ocean Droplet is on the 1GB $10 Plan

*if u do tell me i need the $20 2GB Plan
can i power off server and ReSize Memory or do i need to Buy new server and re-install pbx
 

Attachments

  • Memory.png
    Memory.png
    51.8 KB · Views: 7

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,168
Reaction score
5,199
512MB RAM is a Digital Ocean choice. Then you run the create swap file script that is included in the Incredible PBX tarball.
 

Twilight Sparkle

https://voip.ms/en/invite/MjM2MjQ4
Joined
Jul 21, 2013
Messages
448
Reaction score
57
Read the tutorial!!

i think i got it! n_n

WARNING: If you’re using a 512MB droplet at Digital Ocean, be advised that their Ubuntu setup does NOT include a swap file. This may cause serious problems when you run out of RAM. Uncomment ./create-swapfile-DO line below to create a 1GB swap file which will be activated whenever you exceed 90% RAM usage on Digital Ocean.
 

Members online

No members online now.

Forum statistics

Threads
25,782
Messages
167,509
Members
19,202
Latest member
pbxnewguy
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Top