django - 部署
Posted yc紫日
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了django - 部署相关的知识,希望对你有一定的参考价值。
django项目部署
步骤
1.github建立新仓库
git@github.com:yc913344706/learning_log.git
2.本地安装git
Administrator@yc MINGW64 /e/yc_study/python/django/sys/workspace/learning_log
$ git --version
git version 2.16.0.windows.2
3. 创建.gitignore并编辑
Administrator@yc MINGW64 /e/yc_study/python/django/sys/workspace/learning_log (master)
$ touch .gitignore
Administrator@yc MINGW64 /e/yc_study/python/django/sys/workspace/learning_log (master)
$ cat .gitignore
ll_env/
__pycache__/
*.pyc
*.sqlite3
4. 建立本地仓库
Administrator@yc MINGW64 /e/yc_study/python/django/sys/workspace/learning_log (master)
$ git init
Initialized empty Git repository in E:/yc_study/python/django/sys/workspace/learning_log/.git/
5. 添加文件
Administrator@yc MINGW64 /e/yc_study/python/django/sys/workspace/learning_log (master)
$ git add .
6. 提交到本地仓库
Administrator@yc MINGW64 /e/yc_study/python/django/sys/workspace/learning_log/ll_env (master)
$ git commit -am "Initialize the project"
-- snip --
7. 关联github远程仓库
Administrator@yc MINGW64 /e/yc_study/python/django/sys/workspace/learning_log/ll_env (master)
$ git remote add origin git@github.com:yc913344706/learning_log.git
8. push代码
如果在github的代码仓里原本有文件,则需要先pull
但是由于本地仓库和远程仓库有不同祖先,所以需要“合并不同版本的历史”
然后再次push即可
9. 服务器获取代码
9.1 服务器安装git
9.2 服务器生成公私钥
[yc@yc ~]$ ssh-keygen -t rsa -C "13186087857@163.com"
9.3添加公钥到github
9.4 验证服务器git是否OK
[yc@yc .ssh]$ ssh -T git@github.com
9.5 配置服务器的git全局信息
[yc@yc .ssh]$ git config --global user.name "rhel_7"
[yc@yc .ssh]$ git config --global user.email "13186087857@163.com"
9.6 拉取代码
[yc@yc py_web_project]$ pwd
/data01/py_web_project
[yc@yc py_web_project]$ git clone git@github.com:yc913344706/learning_log.git
10 开发服务器测试代码是否可用
10.1安装python
[yc@yc tools]$ wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
[yc@yc tools]$ tar -xf Python-3.6.3.tgz
[yc@yc tools]$ cd Python-3.6.3/
[yc@yc Python-3.6.3]$ sudo yum -y install xz wget gcc make gdbm-devel openssl-devel sqlite-devel zlib-devel bzip2-devel python-devel libyaml unzip libffi-devel
[yc@yc Python-3.6.3]$ sudo ./configure --prefix=/usr/local
[yc@yc Python-3.6.3]$ sudo make -j
[yc@yc Python-3.6.3]$ sudo make install
[yc@yc Python-3.6.3]$ sudo mv /usr/bin/python /usr/bin/python_2_7_old
[yc@yc Python-3.6.3]$ sudo ln -s /usr/local/bin/python3.6 /usr/bin/python
[yc@yc Python-3.6.3]$ python --version
Python 3.6.3
10.2 安装pip
[yc@yc tools ]$ wget https://bootstrap.pypa.io/get-pip.py
[yc@yc tools]$ sudo python get-pip.py
[yc@yc tools]$ pip --version
pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
10.3 安装virtualenv
[yc@yc tools]$ pip install --user virtualenv
10.4 创建虚拟环境
[yc@yc tools]$ cd /data01/py_web_project/learning_log
[yc@yc learning_log]$ virtualenv ll_env
[yc@yc learning_log]$ ls
learning_log learning_logs ll_env manage.py README.md
10.5 激活虚拟环境
[yc@yc learning_log]$ source ll_env/bin/activate
(ll_env) [yc@yc learning_log]$
10.6 虚拟环境中安装依赖环境
(ll_env) [yc@yc learning_log]$ pip install -r requirements.txt
10.7 迁移数据库
(ll_env) [yc@yc learning_log]$ python manage.py migrate
10.8 创建超级管理员
(ll_env) [yc@yc learning_log]$ python manage.py createsuperuser
10.9 开发服务器启动服务器并测试
(ll_env) [yc@yc learning_log]$ python manage.py runserver 0.0.0.08080
[yc@yc ~]$ curl 127.0.0.1:8080 <p> <a href="/">Learning Logs</a> - <a href="/topics/">Topics</a> </p> <p>YC\'s Learning Logs</p> [yc@yc ~]$ curl 192.168.0.101:8080 curl: (7) Failed connect to 192.168.0.101:8080; Connection refused [yc@yc ~]$ sudo firewall-cmd --state running [yc@yc ~]$ sudo firewall-cmd --get-active-zones public interfaces: ens33 [yc@yc ~]$ sudo firewall-cmd --permanent --zone=home --change-interface=ens33 The interface is under control of NetworkManager, setting zone to \'home\'. success [yc@yc ~]$ sudo firewall-cmd --get-active-zones home interfaces: ens33 [yc@yc ~]$ sudo firewall-cmd --permanent --zone=home --add-port=8080/tcp success [yc@yc ~]$ sudo firewall-cmd --reload success [yc@yc ~]$ sudo firewall-cmd --zone=home --list-all home (active) target: default icmp-block-inversion: no interfaces: ens33 sources: services: ssh mdns samba-client dhcpv6-client ports: 8080/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: [yc@yc ~]$ curl yc.test.com:8080 <p> <a href="/">Learning Logs</a> - <a href="/topics/">Topics</a> </p> <p>YC\'s Learning Logs</p>
11 nginx+wsgi
TODO:待添加操作步骤
参考资料
tortoisegit管理密钥问题
https://www.cnblogs.com/cglNet/p/3706860.html
git无法pull仓库refusing to merge unrelated histories
https://blog.csdn.net/lindexi_gd/article/details/52554159
Django 部署(Nginx)
https://code.ziqiangxuetang.com/django/django-nginx-deploy.html
以上是关于django - 部署的主要内容,如果未能解决你的问题,请参考以下文章
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段