Ubuntu10.10 Server+Nginx+Django+Postgresql安装步骤

1,安装Ubuntu 10.10

1.1 使用默认安装,在更新apt的时候选择跳过

1.2 设置管理员的用户名和密码

1.3 安装openssh-server启动ssh服务,方便使用Bitvise Tunnelier,putty工具进行管理

sudo apt-get install openssh-server

2, 更新源

2.1 sudo vi /etc/apt/sources.list 编辑源列表

#163的,速度很不错的
deb http://mirrors.163.com/Ubuntu/ maverick main restricted universe multiverse
deb http://mirrors.163.com/Ubuntu/ maverick-security main restricted universe multiverse
deb http://mirrors.163.com/Ubuntu/ maverick-updates main restricted universe multiverse
deb http://mirrors.163.com/Ubuntu/ maverick-proposed main restricted universe multiverse
deb http://mirrors.163.com/Ubuntu/ maverick-backports main restricted universe multiverse
deb-src http://mirrors.163.com/Ubuntu/ maverick main restricted universe multiverse
deb-src http://mirrors.163.com/Ubuntu/ maverick-security main restricted universe multiverse
deb-src http://mirrors.163.com/Ubuntu/ maverick-updates main restricted universe multiverse
deb-src http://mirrors.163.com/Ubuntu/ maverick-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/Ubuntu/ maverick-backports main restricted universe multiverse
deb http://archive.Ubuntu.com/ubuntu/ maverick main restricted universe multiverse
deb http://archive.Ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse
deb http://archive.Ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse
deb http://archive.Ubuntu.com/ubuntu/ maverick-proposed main restricted universe multiverse
deb http://archive.Ubuntu.com/ubuntu/ maverick-backports main restricted universe multiverse
deb-src http://archive.Ubuntu.com/ubuntu/ maverick main restricted universe multiverse
deb-src http://archive.Ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse
deb-src http://archive.Ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse
deb-src http://archive.Ubuntu.com/ubuntu/ maverick-proposed main restricted universe multiverse
deb-src http://archive.Ubuntu.com/ubuntu/ maverick-backports main restricted universe multiverseo

#LUPA的源,速度也很好的(开源社区)
deb http://mirror.lupaworld.com/Ubuntu maverick main restricted universe multiverse
deb http://mirror.lupaworld.com/Ubuntu maverick-security main restricted universe multiverse
deb http://mirror.lupaworld.com/Ubuntu maverick-updates main restricted universe multiverse
deb http://mirror.lupaworld.com/Ubuntu maverick-backports main restricted universe multiverse
deb http://mirror.lupaworld.com/Ubuntu maverick-proposed main restricted universe multiverse
deb-src http://mirror.lupaworld.com/Ubuntu maverick main restricted universe multiverse
deb-src http://mirror.lupaworld.com/Ubuntu maverick-security main restricted universe multiverse
deb-src http://mirror.lupaworld.com/Ubuntu maverick-updates main restricted universe multiverse
deb-src http://mirror.lupaworld.com/Ubuntu maverick-backports main restricted universe multiverse
deb-src http://mirror.lupaworld.com/Ubuntu maverick-proposed main restricted universe multiverse

#sohu的源
deb http://mirrors.sohu.com/Ubuntu/ maverick main restricted
deb-src http://mirrors.sohu.com/Ubuntu/ maverick main restricted
deb http://mirrors.sohu.com/Ubuntu/ maverick-updates main restricted
deb-src http://mirrors.sohu.com/Ubuntu/ maverick-updates main restricted
deb http://mirrors.sohu.com/Ubuntu/ maverick universe
deb-src http://mirrors.sohu.com/Ubuntu/ maverick universe
deb http://mirrors.sohu.com/Ubuntu/ maverick-updates universe
deb-src http://mirrors.sohu.com/Ubuntu/ maverick-updates universe
deb http://mirrors.sohu.com/Ubuntu/ maverick multiverse
deb-src http://mirrors.sohu.com/Ubuntu/ maverick multiverse
deb http://mirrors.sohu.com/Ubuntu/ maverick-updates multiverse
deb-src http://mirrors.sohu.com/Ubuntu/ maverick-updates multiverse

#官方的Ubuntu 10.10要保留几个用于紧急www.linuxidc.com更新
deb http://security.Ubuntu.com/ubuntu maverick-security main restricted
deb-src http://security.Ubuntu.com/ubuntu maverick-security main restricted
deb http://security.Ubuntu.com/ubuntu maverick-security universe
deb-src http://security.Ubuntu.com/ubuntu maverick-security universe
deb http://security.Ubuntu.com/ubuntu maverick-security multiverse
deb-src http://security.Ubuntu.com/ubuntu maverick-security multiverse

注意vi命令: i写入模式 ESC退出写入模式,进入命令模式 wq保存退出命令
dd 删除正行 x删除单个字符

3,更新apt-get并安装基本编译环境

sudo apt-get update
sudo apt-get install build-essential

 

4,安装Django

wget http://media.djangoproject.com/releases/1.2/Django-1.2.3.tar.gz

 

tar zxvf Django-1.2.3.tar.gz
cd Django-1.2.3.tar.gz
sudo python setup.py install

 

5,部署项目

将项目拷贝到/build/script-2.6/里

6,安装Postgresql

6.1 安装数据库

sudo apt-get install postgresql

6.2 修改Linux用户postgres的密码

sudo passwd postgres

6.3 修改数据库超级用户postgres的密码

6.3.1 切换到Linux下postgres用户

sudo su postgres

6.3.2 登录postgres数据库

psql postgres

6.3.3 修改密码

ALTER USER postgres with PASSWORD '新密码';

6.4 添加自定义的用户和数据库

6.4.1 添加用户并修改密码

create user 用户名;

ALTER USER 用户名 with PASSWORD '新密码';

6.4.2 创建个属于自定义用户的数据库

create database 数据库名 owner 用户名

6.4.3 查询数据库和表以及用户

select * from pg_database;
select * from pg_user;
select * from pg_tables;
\q退出
退出postgres用户模式 exit

6.5 修改/etc/postgresql/8.4/main/pg_hba.conf 配置文件将md5为trust

sudo vi /etc/postgresql/8.4/main/pg_hba.conf
local trust
hosts trust

6.6 重启postgres

sudo /etc/init.d/postgresql-8.4 restart

 

7,修改项目相应的settings.py文件

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '数据库名', # 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.

}

}

8, 安装Psycopg2驱动程序

8.1 安装相关包

sudo apt-get install python-dev

sudo apt-get install libpq-dev

 

8.2 下载并安装Psycopg2

wget http://initd.org/psycopg/tarballs/psycopg2-2.2.2.tar.gz
tar zxvf psycopg2-2.2.2.tar.gz
cd psycopg2-2.2.2
sudo python setup.py install

 

9,安装nginx并配置

9.1安装最新的nginx版本

sudo su -
echo "deb http://ppa.launchpad.net/nginx/stable/Ubuntu lucid main" >> /etc/apt/sources.list
apt-key adv --keyserver keyserver.Ubuntu.com --recv-keys C300EE8C
apt-get update
apt-get install nginx
sudo apt-get install python-flup

9.2 配置nginx的配置文件

sudo vi /etc/nginx/nginx.conf

 

在http节中加入

server {

listen 80;
server_name ourscopee.com www.ourscopee.com;
location / {
fastcgi_pass 127.0.0.1:8080; #转发8080端口的信息
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

}

location ^~ /media/ {

alias /home/lynne/Django-1.2.3/django/contrib/admin/media/; #lynne注意Django静态文件的路径
}

 

9.3 重启nginx

sudo ./etc/init.d/postgresql restart

 

10,测试

1,测试Django与数据库

python manage.py syncdb

2,测试Django本身WebServer

python manage.py runserver 绑定ip地址:绑定的端口号

3,测试Django与nginx的fastcgi模式配合

开启nginx服务
sudo /etc/init.d/nginx start
开启django的fastcgi模式到8080端口

 

11,测试 http://服务器的ip/

TODO:
1)Memcache未加入和配置
2)未进行高并发测试
3)配置未完全掌握并优化尤其是fastcgi的配置

相关推荐

3 thoughts on “Ubuntu10.10 Server+Nginx+Django+Postgresql安装步骤”

Leave a Comment