2012年6月26日 星期二

[Django] Installing Django with Apache & mod_wsgi

Django 安裝及簡介 文章中曾介紹如何安裝 Django。

不過,若要將開發的網頁透過 domain 分享給世界各地的人欣賞,

則需要設定 apache 以達到這個目的。

下面將一步一步介紹如何在 apache 上安裝 Django:

PART 1 - Server 的部署

安裝 Apache 及 mod_wsgi
> sudo apt-get install apache2 libapache2-mod-wsgi

安裝 Django 請參考這裡

建立一資料夾儲存網站資料〈此為筆者存放位置,讀者可自行決定〉
> sudo mkdir /opt/www

PART 2 - 設定 domain name

> sudo vi /etc/hosts

並加入下列內容:

192.168.1.1 domainname 〈此為筆者之假設,請讀者自行決定〉

PART 3 - Django 測試

建立 Django 專案
> cd /opt/www
> sudo django-admin.py startproject helloworld

產生一個 wsgi 的檔案
> sudo mkdir /opt/www/helloworld/apache
> sudo vi /opt/www/helloworld/apache/django.wsgi

在 django.wsgi 檔案中編輯下列內容:

import os
import sys

path = '/opt/www'
if path not in sys.path:
    sys.path.insert(0, '/opt/www')

os.environ['DJANGO_SETTING_MODULE'] = 'helloworld.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler( )


修改 apache 設定
> sudo vi /etc/apache2/sites-available/default

於 default 檔案中‧‧‧

修改下列內容:

DocumentRoot /var/www -> /opt/www/helloworld

<Directory /var/www> -> <Directory /opt/www/helloworld>


增加下列內容:

WSGIScriptAlias / /opt/www/helloworld/apache/django.wsgi

啟動 site
> sudo a2ensite default
> sudo service apache2 reload


最後,打開網址,並輸入 http://domainname 就會看到 Django 安裝完成的畫面囉!

2012年6月14日 星期四

[OpenStack] 如何透過 dashboard import keypair?

在 OpenStack dashboard 中存在一項功能 ── import keypair。

But, how to import a keypiar via dashboard 一直困擾著我!囧

經由上網發問,總算得知正確的使用方式。

因此,藉由這裡記錄在 OpenStack dashboard import keypair 的方法。

首先,什麼是 keypair?下面是 OpenStack 初學者手冊中的定義。

You will also need to generate a keypair consisting of private key/public key to be able to launch instances on OpenStack. These keys are injected into the instances to make password-less SSH access to the instance. This depends on the way the necessary tools are bundled into the images.

接下來,將說明如何操作 import keypair。

STEP 1. 在主機上建立公鑰 (public key)
# ssh-keygen

建立過程中詢問之事項皆 Enter 帶過。

STEP 2. 進入 .ssh 資料夾
# cd .ssh

將會發現資料夾中存在 id_rsa 以及 id_rsa.pub 檔案。

STEP 3. 開啟公鑰
# cat ~/.ssh/id_rsa.pub

STEP 4. 複製工要內容,並貼入 dashboard 中 public key 欄位

恭喜你,順利完成 import keypair 的艱難任務! :D

參考資料:
1. OpenStack Compute Starter Guide -Essex

2012年6月2日 星期六

[Ubuntu] 在 Ubuntu 上安裝 Samba 分享檔案

用習慣圖形介面管理檔案的我,

一開始接觸 Ubuntu 相當不習慣!( Crtl+C Crtl+V 不是很好用嗎?! )

幸好公司的前輩為我開啟 Samba 這套分享檔案套件,

使我順利在 Windows 上管理 Ubuntu 的檔案。

話不多說,下面咱們就來看看如何在 Ubuntu 上安裝這套好用的套件。:D

STEP 1 安裝 Samba
sudo apt-get install samba

STEP 2 設定 Samba 設定檔
sudo vi /etc/samba/smb.conf

STEP 3 增加「分享資料夾」
在 smb.conf 尾端加上

[Sharename]
    path = /
    browseable = yes
    read only = no
    create mask = 0644
    directory mask = 0755

STEP 4 重新啟動 Samba 服務
sudo /etc/init.d/smbd restart

STEP 5 建立 Samba 帳號密碼
sudo smbpasswd -a username