Wednesday, October 15, 2014

Notes on setting up Ubuntu 14.04 Django server

Ubuntu 14.04 / python / Django / uWsgi / Nginix / postgres / postgis / upstart

# Notes and reference on building Ubuntu 14.04 server

adduser skywalker
echo "skywalker    ALL=(ALL:ALL) ALL" >> visudo

nano /etc/ssh/sshd_config
Port 10022
PermitRootLogin no
AllowUsers skywalker
service ssh restart


sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-virtualenv
sudo pip install virtualenvwrapper

sudo apt-get install mercurial
https://confluence.atlassian.com/pages/viewpage.action?pageId=270827678#SetupSSHforGitandMercurialonMacOSX/Linux-startagent

clone the repo

sudo apt-get install python-dev libffi-dev

maakevirtualenv starwars
workon starwars
pip install -r requirements.txt
deactivate

sudo apt-get install libpq-dev
sudo apt-get install postgresql postgresql-contrib
http://www.peterstratton.com/2014/04/how-to-install-postgis-2-dot-1-and-postgresql-9-dot-3-on-ubuntu-servers/

sudo adduser yoda
sudo -u postgres createuser -D -A -P --superuser yoda
sudo -u postgres createdb -O yoda starwars

workon starwars
python manage.py migrate
python manage.py runserver
deactivate

sudo apt-get install nginx
sudo cp code/starwars/conf/djago /etc/nginx/sites-available
ln -s /etc/nginx/sites-available /etc/nginx/sites-enbled
sudo service nginx restart

mkdir /home/skywalker/code/starwars/log
sudo chmod -R 777 /home/skywalker/code/starwars/log

sudo mkdir /opt/django-nginx-uwsgi/
sudo chmod -R 777 /opt/django-nginx-uwsgi/
sudo chown skywalker:www-data /opt/django-nginx-uwsgi/

sudo usermod -g www-data skywalker
id

sudo cp /code/starwars/conf/upstart.conf /etc/init/uwsgi.conf

sudo reboot


## important

iptables -L
cat /etc/host.conf 
cat /etc/hosts.allow 
cat /etc/hosts.deny 
netstat -tulpn | grep ssh

## setting up SSL - Reference

https://www.digitalocean.com/community/tutorials/how-to-create-an-ssl-certificate-on-nginx-for-ubuntu-14-04

## Hardening SSL

https://aralbalkan.com/scribbles/setting-up-ssl-with-nginx-using-a-namecheap-essentialssl-wildcard-certificate-on-digitalocean/
https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/

Sunday, August 24, 2014

Forward Naked domains to Openshift for FREE

How to attach a domain name to OpenShift or any PaaS account ?

1. Create a new app ex in OpenShift - app_name-domain_name.rhcloud.com
2. Get a domain from Godaddy.
3. Signup for a free account for CloudFlare


CloudFlare

1. Add a website, by specifying the domain name - example.com

2. In the DNS settings, check if these two entries are there - if not create them manually
  • www points to example.com - type CNAME
  • example.com points to app_name-domain_name.rhcloud.com - type CNAME
3. Delete A level record from the list

4. CloudFlare now shows you two name servers.


GoDaddy

1. Delete the existing nameservers provided by Godaddy in Godaddy's control panel, in the domain settings for example.com

2. Add the two nameservers provided by CloudFlare to domain settings of example.com in GoDaddy

3. Check if domain forwarding is disabled or off. It should be disable or off by default


OpenShift Client Tools - Locally


1. Install the rhc client tools for openshift, if you haven't and set it up, by following the instructions here

2. After Installation execute these commands
  • rhc alias add app_name example.com
  • rhc alias add app_name www.example.com

Friday, April 25, 2014

Running Ubuntu on 24GB SSD (Dual boot windows 8.1) - Managing Vagrant and VM files

I use an ASUS S56C ultrabook, it has a hybrid drive ( 24G SSD + 750G HDD ) with Windows 8 as the primary OS.

I primarily use Ubuntu, and wanted to keep windows too ( i paid 3K extra for that! ) so dual booting was my only option. Installing Ubuntu on the HDD was not an option because it was already divided into 5 partitions ( Recovery , OS , 350G, EFI , 128MB) etc and i wanted to avoid the mess dealing with Windows. And Ubuntu didn't support SSD cache out of the box.

Setting up Ubuntu 14.04 on SSD


So I decided to install Ubuntu on the SSD. On further inspecting the SSD , the SSD is divided into 2 partitions .One for the OEM ( windows copy 4G ) and another 18G free partition( used as cache by Windows ).

I installed Ubuntu on the 18G partition. Ubuntu + installation of essential packages ( VLC , git mercurial , gparted , gstream , etc ) takes around 8G , leaving me with only 10G free space.

10G is not enough for me to setup vagrant and save the VM's. Each vagrant image I had was around 10G. So I decided to move the VM's to another ntfs drive. But i didn't have write permission on NTFS drive. This was because Windows 8 has an "Fast Boot" option which prevents me to write to NTFS drives from another OS. you can disable that option by going to power options in Win8. But then later found out that NTFS drives don't support unix style permissions. :|

After all the frustration dealing with Win8 i decided to shrink the D drive ( 350G) to give me a nice 50G partition. I formatted it to EXT4 and mounted it to /media/new_drive/.

Changing the default path for vagrant and virtualbox

By default vagrant saves all the data in ~/.vagrant.d/ directory. To change the all we have to do is set the environment variable VAGRANT_HOME to a new location. You can do that by 

1) create a new file in /etc/profile.d/ called vagrant.sh . This file will be loaded during boot to setup the environment variable.

sudo nano /etc/profile.d/vagrant.sh

in the file type:

export VAGRANT_HOME = /media/new_drive/vagrant/

where /media/new_drive is where the EXT4 partition is mounted.

2) VirtualBox also saves the copy of the image in the users home directory. By default virtual box saves the copy of the image to ~/.virtualbox/ directory. To change the default location:

open virtualbox -> file -> preference 

Here change the default image save path to /media/new_drive/virtualbox .


Now you can run vagrant as usual and all the configuration and image files will be saved on the new drive.

Note: 
1) SSD cache is manged by Diskeeper express cache in windows on my machine. In some hybrid computers, its managed by Intel SRT or RST (depends ) . Disabling that is advised before installing another OS (do a research before you proceed)
2) Windows 8.1 works perfectly with fast boot disabled and without SSD cache. Its slow now.
3) Ubuntu is super fast now.
4) There are several posts online on how to use SSD as a cache on Ubuntu.
5) Asus S56C - Windows 8.1 + ubuntu 14.04 + vagrant