-
通过git的方式
-
通过Blog_mini项目主页下载
-
首先确保你的系统已经安装了git版本控制系统:
1
2
3
|
xpleaf@leaf:~$ git version
程序“git”尚未安装。 您可以使用以下命令安装:
sudo
apt-get
install
git
|
-
如果还没有安装,请通过apt-get方式安装:
1
2
|
xpleaf@leaf:~$
sudo
apt-get
install
git
[
sudo
] xpleaf 的密码:
|
-
安装完成后,在用户目录中创建一个project的目录:
1
2
3
|
xpleaf@leaf:~$
mkdir
project
xpleaf@leaf:~$
cd
project/
xpleaf@leaf:~
/project
$
|
-
从Blog_mini项目地址中克隆源代码:
1
|
xpleaf@leaf:~
/project
$ git clone https:
//github
.com
/xpleaf/Blog_mini
|
-
查看Blog_mini的源代码目录结构:
1
2
3
|
xpleaf@leaf:~
/project/Blog_mini
$
ls
app LICENSE migrations README.md requirements.txt
config.py manage.py Procfile requirements
|
-
进入项目主页:
-
点击Download ZIP按钮
-
下载后的文件名应该是:Blog_mini-master.zip
-
执行下面的命令安装即可:
1
|
xpleaf@leaf:~
/project/Blog_mini
$
sudo
apt-get
install
python-pip
|
-
执行下面的命令安装即可:
1
|
xpleaf@leaf:~
/project/Blog_mini
$
sudo
apt-get
install
virtualenv
|
1
|
xpleaf@leaf:~
/project/Blog_mini
$
sudo
apt-get
install
python-virtualenv
|
-
在Blog_mini目录下执行下面的命令:
1
2
3
4
5
|
xpleaf@leaf:~
/project/Blog_mini
$ virtualenv venv
Running virtualenv with interpreter
/usr/bin/python2
New python executable
in
venv
/bin/python2
Also creating executable
in
venv
/bin/python
Installing setuptools, pip...
done
.
|
-
可以在Blog_mini下看到生成了一个venv目录:
1
2
3
|
xpleaf@leaf:~
/project/Blog_mini
$
ls
app LICENSE migrations README.md requirements.txt
config.py manage.py Procfile requirements venv
|
-
在Blog_mini目录下:
1
2
|
xpleaf@leaf:~
/project/Blog_mini
$
source
venv
/bin/activate
(venv)xpleaf@leaf:~
/project/Blog_mini
$
|
-
执行如下命令:
1
|
(venv)xpleaf@leaf:~
/project/Blog_mini
$ pip
install
-r requirements
/common
.txt
|
-
使用sqlite作为默认数据库来运行Blog_mini
-
使用MySQL作为默认数据库来运行Blog_mini
-
生成Blog_mini所需要的系统默认数据,请在Blog_mini目录下执行下面的命令:
1
2
3
4
|
(venv)xpleaf@leaf:~
/project/Blog_mini
$ python manage.py deploy product
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running upgrade -> 051691f120e6, fit to MySQL
|
-
查看生成的sqlite数据库:
1
2
3
|
(venv)xpleaf@leaf:~
/project/Blog_mini
$
ls
app config.pyc LICENSE migrations README.md requirements.txt
config.py data.sqlite manage.py Procfile requirements venv
|
-
运行Blog_mini:
1
2
3
4
5
|
(venv)xpleaf@leaf:~
/project/Blog_mini
$ gunicorn manage:app
[2016-03-08 11:49:11 +0000] [7189] [INFO] Starting gunicorn 19.4.5
[2016-03-08 11:49:11 +0000] [7189] [INFO] Listening at: http:
//127
.0.0.1:8000 (7189)
[2016-03-08 11:49:11 +0000] [7189] [INFO] Using worker:
sync
[2016-03-08 11:49:11 +0000] [7194] [INFO] Booting worker with pid: 7194
|
-
以80端口运行Blog_mini:
1
2
3
4
5
|
(venv)xpleaf@leaf:~
/project/Blog_mini
$ gunicorn -b 0.0.0.0:80 manage:app
[2016-03-08 11:50:43 +0000] [7202] [INFO] Starting gunicorn 19.4.5
[2016-03-08 11:50:43 +0000] [7202] [INFO] Listening at: http:
//0
.0.0.0:80 (7202)
[2016-03-08 11:50:43 +0000] [7202] [INFO] Using worker:
sync
[2016-03-08 11:50:43 +0000] [7207] [INFO] Booting worker with pid: 7207
|
-
如果你是在有公网IP地址的服务器部署Blog_mini的,只需要在互联网上任何一台主机的浏览器上输入你的公网IP地址,就可以访问Blog_mini了。
-
如果你只是在局域网上部署Blog_mini的,那么在局域网上的任何一台主机的浏览器上输入你这台主机的IP地址也是可以访问的了。
1
2
|
xpleaf@leaf:~$
sudo
ufw disable
[
sudo
] xpleaf 的密码:
|
-
账号:blog_mini@163.com
-
密码:blog_mini
1
|
(venv)xpleaf@leaf:~
/project/Blog_mini
$ python manage.py deploy test_data
|
-
通过apt-get方式安装MySQL
-
通过源码的方式安装MySQL
-
安装python必要的函数库:
1
|
(venv)xpleaf@leaf:~
/project/Blog_mini
$
sudo
apt-get
install
python-dev libmysqlclient-dev
|
-
安装MySQL-python:
1
2
3
4
|
(venv)xpleaf@leaf:~
/project/Blog_mini
$ pip
install
MySQL-python
……
Successfully installed MySQL-python
Cleaning up...
|
-
退出虚拟环境,回到用户主目录中:
1
2
3
|
(venv)xpleaf@leaf:~
/project/Blog_mini
$ deactivate
xpleaf@leaf:~
/project/Blog_mini
$
cd
xpleaf@leaf:~$
|
-
登陆到MySQL数据库中(请先确保MySQL服务已经开启):
1
2
3
4
|
[root@leaf ~]
# mysql -u root -p
Enter password:
mysql>
|
-
为Blog_mini创建数据库:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
mysql> create database blog_mini default character
set
utf8 collate utf8_general_ci;
Query OK, 1 row affected (0.04 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| blog_mini |
| mysql |
| performance_schema |
+--------------------+
4 rows
in
set
(0.04 sec)
|
-
设定系统环境变量:
1
|
xpleaf@leaf:~$
export
DATABASE_URL=mysql:
//root
:123456@127.0.0.1
/blog_mini
|
-
验证系统环境变量:
1
2
|
xpleaf@leaf:~$
echo
$DATABASE_URL
mysql:
//root
:123456@127.0.0.1
/blog_mini
|
-
进入project/Blog_mini目录,初始化虚拟环境:
1
2
3
|
xpleaf@leaf:~$
cd
project
/Blog_mini/
xpleaf@leaf:~
/project/Blog_mini
$
source
venv
/bin/activate
(venv)xpleaf@leaf:~
/project/Blog_mini
$
|
-
初始化Blog_mini系统默认数据:
1
2
3
4
|
(venv)xpleaf@leaf:~
/project/Blog_mini
$ python manage.py deploy product
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running upgrade -> 051691f120e6, fit to MySQL
|
-
运行Blog_mini:
1
2
3
4
5
|
(venv)xpleaf@leaf:~
/project/Blog_mini
$ gunicorn manage:app
[2016-03-08 11:49:11 +0000] [7189] [INFO] Starting gunicorn 19.4.5
[2016-03-08 11:49:11 +0000] [7189] [INFO] Listening at: http:
//127
.0.0.1:8000 (7189)
[2016-03-08 11:49:11 +0000] [7189] [INFO] Using worker:
sync
[2016-03-08 11:49:11 +0000] [7194] [INFO] Booting worker with pid: 7194
|
-
以80端口运行Blog_mini:
1
2
3
4
5
|
(venv)xpleaf@leaf:~
/project/Blog_mini
$ gunicorn -b 0.0.0.0:80 manage:app
[2016-03-08 11:50:43 +0000] [7202] [INFO] Starting gunicorn 19.4.5
[2016-03-08 11:50:43 +0000] [7202] [INFO] Listening at: http:
//0
.0.0.0:80 (7202)
[2016-03-08 11:50:43 +0000] [7202] [INFO] Using worker:
sync
[2016-03-08 11:50:43 +0000] [7207] [INFO] Booting worker with pid: 7207
|
-
如果你是在有公网IP地址的服务器部署Blog_mini的,只需要在互联网上任何一台主机的浏览器上输入你的公网IP地址,就可以访问Blog_mini了。
-
如果你只是在局域网上部署Blog_mini的,那么在局域网上的任何一台主机的浏览器上输入你这台主机的IP地址也是可以访问的了。
1
2
|
xpleaf@leaf:~$
sudo
ufw disable
[
sudo
] xpleaf 的密码:
|
-
账号:blog_mini@163.com
-
密码:blog_mini
1
|
(venv) [root@leaf Blog_mini]
# python manage.py deploy test_data
|