How to survive with AWS EC2 T1.Micro instance

With my t1.micro, i can host my personal redmine, git and blog. But i couldn’t do that with default settings.

200px-AWS_Simple_Icons_Compute_Amazon_EC2_Instances.svg

Press continue reading for more!

1. Swap

My first need was to create a swap on file, for that i made this:
$ sudo dd if=/dev/zero of=/mnt/swap bs=16384 count=131072
$ sudo mkswap /mnt/swap
$ sudo chown root:root /mnt/swap
$ sudo chmod 0600 /mnt/swap
$ sudo swapon /mnt/swap
then
$ sudo vim /etc/fstab and add at the end of the file:
/mnt/swap swap swap defaults 0 0

2. Sysctl.conf

Another change was in:
$ sudo vim /etc/sysctl.conf
#disable ipv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

vm.swappiness = 100
kernel.panic_on_oops = 1
kernel.panic = 1
kernel.shmmax = 268435456

save file and type $ sudo sysctl -p

3. Clearcache script

And this one to free memory:

make one script in /root
clearcache.sh

#!/bin/bash

sync; echo 3 > /proc/sys/vm/drop_caches

and put in crontab

0 * * * * /root/clearcache.sh

4. PHP-APC

Not needed in php5.5 or newer, type php5 --version to check.

$ sudo apt-get install php-apc

5. Varnish proxy in front of Apache.

$ sudo apt-get install varnish

Change Apache ports to 8080 and varnish to 80.

$ sudo vim /etc/default/varnish

DAEMON_OPTS=”-a :80
-T localhost:6082
-f /etc/varnish/default.vcl
-S /etc/varnish/secret
-s malloc,64m”

$ sudo vim /etc/apache2/ports.conf
NameVirtualHost *:8080
Listen 8080

$ sudo vim /etc/apache2/sites-available/default
(and all others vhost that you have created)

<VirtualHost *:8080>
$ sudo service apache2 restart
$ sudo service varnish restart

To show users IP in logs you need to install mod-rpaf

$ sudo apt-get install libapache2-mod-rpaf

6. Prelink

$ sudo apt-get install prelink
$ sudo prelink -amR
$ sudo vim /etc/default/prelink
change from unknown to yes
$ sudo /etc/cron.daily/prelink
$ sudo vim /etc/apt/apt.conf
type this inside the new file:
DPkg::Post-Invoke {“echo Running prelink, please wait…; /etc/cron.daily/prelink”;}
if your apt-get install get problems, check the quotation marks.

7. Preload

$ sudo apt-get install preload

8. WarmUP EBS

Make a script for filling the entire ebs and then just remove the file, adjust the count number to fill your entire EBS.

$ sudo dd if=/dev/zero of=/mnt/warm1 bs=16384 count=524288
$ sudo rm /mnt/warm1

9. AWS RDS – Scale out the database.

AWS Free Tier gives an free rds, use it.

10. AWS ElastiCache

AWS Free Tier gives an free memcached (or redis) use it.

WordPress, install W3 Total Cache and use memcached in all options. :)

Redmine:

config/additional_environment.rb -> add at the end of the file: config.cache_store = :mem_cache_store, “yourserver:11211”

Gemfile -> above the source line, add gem “memcache-client”

Gitlab: i dont know how to do.

Comments

comments

Comments are Disabled