Monday, April 5, 2010

Playing around with low end VPS box

Last week I just bought a VPS account for playing around with. It feels so great having our own shell account with root login so that we can do anything inside. I bought it from here. First of all, I bought the minimalist one, with 64mb memory, with no burstable ram :D, using Centos. I simply cant do anything, their Centos installation itself took around 20-30mb ram. I also not well enough playing with Yum. This is not great, so I upgraded the account to 128mb ram. At the same time I noticed that besides Centos, the hosting provider also provide Debian Lenny as the OS....why dont you said that from the beginning ??? :D Now, I'm running Lenny with 128mb ram. The VM specs itself it's not that bad, considering it's powered with 2 cpu @3Ghz, 128mb ram with no swap ( this guy here shares a great script to create a fake swap, but I dont need it any longer ;) read the rest of the entry to know why... ), and with 10Gb disk, more than enough storage for minimalist like me :)

So, first thing first, chop all the unnecessary program, replace it with the program with smaller 'cost'. Just do ps -ef and there I found apache2 and Sendmail sitting around and eating my memory. Just do :
# apt-get remove --purge sendmail apache2
And dont forget to kill them, and remove them from startup script.
# kill -9 pid
# update-rc.d -f remove apache2
# update-rc.d -f remove sendmail
Ok, that left me around 5 mb used memory. Not bad :)
Next thing is to replace the default shell, since bash shell become greedy enough to eat my memory. I replaced it with pdksh since after googling around, this pdksh shell saves ~1mb for every shell session...good enough. So I install it :
# apt-get install pdksh
Dont remove the bash shell yet, since it has a lot of dependencies. Leave it there, but dont use it :) How do we do that ? Just edit your own default shell to become pdksh in /etc/passwd :
# vi /etc/passwd
Change the line using /bin/bash, into /bin/pdksh, and voillaa, next login session will be using pdksh.
Not enought with just # prompt ? It's time to decorate your shell with some fancy prompts, just edit the .profile located inside the user's home directory ( just do ls -la to see it, since it's a hidden file ). Add the following line :
HOSTNAME=`hostname`
PS1=`print "\027\033[1;32m$USER@$HOSTNAME $PWD > \027\033[0m"`
And then do logout and login again, now you have a green fancy prompt sitting around in your shell prompts.

Next thing we can chop with, is the rsyslogd daemon and the sshd daemon. I got a great reference here. We will replace the rsyslogd daemon with syslog-ng, and replace the open-ssh server with dropbear.
# apt-get install syslog-ng && dpkg --purge rsyslog
And then the dropbear.
# touch /etc/ssh/sshd_not_to_be_run
# apt-get install dropbear
And edit the /etc/default/dropbear to set NO_START=0. To make sure of what we have change, just reboot the server.
And after fresh reboot, here's what I have in my VPS :

root@ath.cx /root > ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Apr05 ? 00:00:00 init [2]
root 340 1 0 Apr05 ? 00:00:00 /usr/sbin/syslog-ng -p /var/run/
root 348 1 0 Apr05 ? 00:00:00 /usr/sbin/dropbear -d /etc/dropb
root 367 1 0 Apr05 ? 00:00:00 /usr/sbin/xinetd -pidfile /var/r
root 382 1 0 Apr05 ? 00:00:00 /usr/sbin/cron
root 8864 348 0 02:24 ? 00:00:00 /usr/sbin/dropbear -d /etc/dropb
onty 8865 8864 0 02:24 pts/1 00:00:00 -pdksh
root 9192 8865 0 02:51 pts/1 00:00:00 -pdksh
root 9226 1 0 03:01 ? 00:00:00 nginx: master process /usr/sbin/
www-data 9227 9226 0 03:01 ? 00:00:00 nginx: worker process
root 9229 9192 0 03:01 pts/1 00:00:00 ps -ef

root@ath.cx /root > free -m
total used free shared buffers cached
Mem: 128 6 121 0 0 0
-/+ buffers/cache: 6 121
Swap: 0 0 0


Yep, I end up with just 6 mb ram for OS, dropbear, and nginx, and 121 ram free for my other apps.