Set up a virtual machine on neCTAR

marrabld edited this page Aug 13, 2012 · 6 revisions

Setting up a Virtual Machine on neCTAR

Firstly you need to download an ssh keypair. This will allow you to log in via ssh with sudo privileges.

  • Choose Access & Security → Create Keypairs
  • Give the key pair a name
  • Download the key and save it. This is your public key.
  • For security reason, change the permission on the key chmod 600
  • Choose Instances → Launch instances
  • Choose the OS you would like to create. From here it is assumed you have chosen Ubuntu 12.04 LTS (Precise) amd64 UEC and choose launch on the right hand side.
  • Give the server a useful name and choose the resources you require in ‘Flavor’ dropdown box
  • From keypair dropdown, choose the keypair you setup earlier
  • IMPORTANT make sure you tick all of the security groups - especially ssh if you would like to access the vm via ssh.
  • Choose launch instance.

Setting up additional VM users with ssh capability

  • ssh in to the VM. You can find the ip address in the nectar dashboard.

      ssh -i <Your keypair from previous step> ubuntu@<ip address>     
      useradd -m <username>
  • Log back out and copy over the user’s ssh public key using.

      scp <user’s public key> -i <your keypair> ubuntu@<ip address>
  • Log in to the VM and copy the user’s public key text to their authorized list

      sudo cat <user’s public key> >> /home/<username>/.ssh/authorized_keys

Create a common user group

  • Create a new group and add the users

      sudo groupadd <groupname>
      sudo usermod -a -G <groupname> <user>
  • Add group to a folder

      sudo chgrp -R <group> /path/to/folder
      sudo chmod -R 770 /path/to/folder

Setting up Django on an Ubuntu server

  • Install Django and dependencies

      sudo apt-get install python-django sqlite3
  • Set up a site

      django-admin startproject <site>
      cd <site>
  • Change the following : # examples are in Bold

      DATABASES = {
          'default': {
          'ENGINE': 'django.db.backends.**sqlite3**', # Add 'postgresql_psycopg2', 'postgresql', 'mysql',         'sqlite3' or 'oracle'.
          'NAME': **'/home/marrabld/Programming/Python/catami_sandbox/Poll'**,                  	# Or path to database file if using sqlite3.
          'USER': '',                  	# Not used with sqlite3.
          'PASSWORD': '',              	# Not used with sqlite3.
          'HOST': '',                  	# Set to empty string for localhost. Not used with sqlite3.
          'PORT': '',                  	# Set to empty string for default. Not used with sqlite3.
  • Apply the settings

      python syncdb
  • Create an app - known as a ‘model’

      python startapp <appname>
      cd <appname>
  • Add app code to / # example

      from django.db import models
      # Create your models here.
      class Poll(models.Model):
          def __unicode__(self):
              return self.question
          question = models.CharField(max_length=200)
          pub_date = models.DateTimeField('date published')
      class Choice(models.Model):
          def __unicode__(self):
              return self.choice
          poll = models.ForeignKey(Poll)
          choice = models.CharField(max_length=200)
          votes = models.IntegerField()
  • Add app name to under ‘INSTALLED APPS’ # example

          INSTALLED_APPS = (
          # Uncomment the next line to enable the admin:
          # Uncomment the next line to enable admin documentation:
          # 'django.contrib.admindocs',
  • Build the sql database

      python sql <appname>
      python syncdb
  • Launch the site

      python runserver

Make Django visible to the outside world

Method 1

  • To make Django visible to the outside world you need to use apache and mod_python

      sudo apt-get install libapache2-mod-python
  • Setup apache to use Django. Add the following

      emacs /etc/apache2/httpd.conf
      LoadModule python_module /usr/lib/apache2/modules/
      MaxRequestsPerChild 1
          SetHandler python-program
          PythonHandler django.core.handlers.modpython
          SetEnv DJANGO_SETTINGS_MODULE <site>.settings
          PythonPath “[‘/home/<username>/<appname>’] + sys.path”
          SetHandler None
  • Restart apache2 and run the django server

      sudo /etc/init.d/apache2 restart
      python runserver
  • Setup a script to run django on boot

      python runserver C-x C-s C-x C-c
      sudo mv /etc/init.d
      sudo chmod +x /etc/init.d/
      sudo update-rc.d defaults

##Method 2

  • Use fastcgi
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.