本教程实验环境为阿里云服务器centos6.8 64位
1.首先更新python版本
centos6.8的默认python版本为2.6,如果用默认版本安装的话会走不少弯路。
1.1安装前准备
查看当前系统中的 Python 版本,可以看到实验室的这台服务器已经安装了 Python 2.6.6
1
|
python
--
version
|
检查 CentOS 版本,我们可以看到这台服务器的 CentOS的版本是 CentOS release 6.8
1
|
cat
/
etc
/
redhat
-
release
|
为了避免后续安装出错,我们先来安装开发工具包
先安装 Development Tools
1
|
yum
groupinstall
-
y
"Development tools"
|
然后安装其它的工具包
1
|
yum
install
-
y
zlib
-
devel
bzip2
-
devel
openssl
-
devel
ncurses
-
devel
sqlite
-
devel
|
1.2安装python
下载、编译和安装 Python 2.7.13
yum 源中没有新版 Python ,我们到官网中下载 Python 2.7.13
1
|
wget
<
a
href
=
"https://mc.qcloudimg.com/static/archive/b577469e4ed03782eb1f62e8fd6125a5/Python-2.7.13.tar.gz"
>
https
:
//mc.qcloudimg.com/static/archive/b577469e4ed03782eb1f62e8fd6125a5/Python-2.7.13.tar.gz</a>
|
下载完成后,解压这个安装包
1
|
tar
zxvf
Python
-
2.7.13.tar.gz
|
进入文件夹 Python-2.7.13
1
|
cd
Python
-
2.7.13
|
执行 configure 文件预编译
1
|
.
/
configure
|
编译和安装
1
|
make
&
amp
;
&
amp
;
make
install
|
1.3配置python
更新系统默认 Python 版本
先把系统默认的旧版 Python 重命名
1
|
mv
/
usr
/
bin
/
python
/
usr
/
bin
/
python
.
old
|
再删除系统默认的 python-config 软链接
1
|
rm
-
f
/
usr
/
bin
/
python
-
config
|
最后创建新版本的 Python 软链接
1
2
3
|
ln
-
s
/
usr
/
local
/
bin
/
python
/
usr
/
bin
/
python
ln
-
s
/
usr
/
local
/
bin
/
python
-
config
/
usr
/
bin
/
python
-
config
ln
-
s
/
usr
/
local
/
include
/
python2
.
7
/
/
usr
/
include
/
python2
.
7
|
编辑 /usr/bin/yum 文件,把代码第一行的 python 改为指向老的 python2.6 版本,修改内容参考以下:
1
|
#!/usr/bin/python2.6
|
再查看 Python 版本,现在我们看到的已经是最新版了
1
|
python
--
version
|
1.4为新版 Python 安装一些工具
为新版 Python 安装 pip
1
2
|
curl
https
:
//bootstrap.pypa.io/get-pip.py | python
|
使用 pip 安装第三方库 requests
1
|
pip
install
requests
|
2.安装mezzanine
# 使用pip安装mezzanine
1
|
$
pip
install
mezzanine
|
# 创建项目
1
2
|
$
mezzanine
-
project
myproject
$
cd
myproject
|
# 创建数据库
1
|
$
python
manage
.
py
createdb
|
# 运行mezzanine
1
|
$
python
manage
.
py
runserver
|
以上是官网给出的安装办法,
如果需要使用mysql数据库 需要修改下一层目录中的local_settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
DATABASES
=
{
"default"
:
{
# Ends with "postgresql_psycopg2", "mysql", "sqlite3" or "oracle".
"ENGINE"
:
"django.db.backends.mysql"
,
//这块在点后面改成mysql
# DB name or path to database file if using sqlite3.
"NAME"
:
"db"
,
//数据库名称
# Not used with sqlite3.
"USER"
:
"user"
,
//用户名
# Not used with sqlite3.
"PASSWORD"
:
"password"
,
//密码
# Set to empty string for localhost. Not used with sqlite3.
"HOST"
:
"address"
,
//数据库地址
# Set to empty string for default. Not used with sqlite3.
"PORT"
:
"3306"
,
}
}
|
ps:使用mysql 需要在服务器上安装mysql 及mysql-python
1
|
yum
install
-
y
mysql
-
server
mysql
mysql
-
deve
|
安装mysql-python
1
|
pip
install
mysql
-
python
|
现在mezzanine就安装成功了,访问127.0.0.1:8000 就可以访问了
但是启动和访问网站好像还有点不方便,就需要安装nginx和supervisor了
3.安装supervisor
使用pip安装supervisor
1
|
pip
install
suerpvisor
|
创建supervisor配置文件 supervisord.conf
1
2
3
4
5
6
7
|
[
program
:
project
]
command
=
python
/
data
/
project
/
manage
.
py
runserver
autostart
=
true
autorestart
=
true
stdout_logfile
=
/
data
/
project
/
log
/
log
.
log
stderr_logfile
=
/
data
/
project
/
log
/
err
.
log
[
supervisord
]
|
让supervisor指定配置文件运行
1
|
supervisord
-
c
/
etc
/
supervisord
.
conf
|
运行了这条命令之后,进程会自动运行
停止进程
1
|
supervisorctl
start
project
|
重启进程
1
|
supervisorctl
restart
project
|
开启进程
1
|
supervisorctl
start
project
|
4.安装nginx
4.1安装nginx
1
|
yum
install
nginx
-
y
|
4.2配置反向代理
打开配置文件/etc/nginx/conf.d/default.conf
1
2
3
4
|
location
/
{
proxy_pass
http
:
//127.0.0.1:8000;
proxy_redirect
default
;
}
|
4.3开启nginx服务
1
|
nginx
|
好了 现在就可以通过域名访问你的网站了,mezzanine安装完毕。