django - 部署

django項目部署

步驟

1.github創建新倉庫

git@github.com:yc913344706/learning_log.githtml

2.本地安裝git

Administrator@yc MINGW64 /e/yc_study/python/django/sys/workspace/learning_logpython

$ git --versionnginx

git version 2.16.0.windows.2git

3. 建立.gitignore並編輯

Administrator@yc MINGW64 /e/yc_study/python/django/sys/workspace/learning_log (master)github

$ touch .gitignoreweb

Administrator@yc MINGW64 /e/yc_study/python/django/sys/workspace/learning_log (master)sql

$ cat .gitignoreshell

ll_env/數據庫

__pycache__/django

*.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>
xshell中新開虛擬終端進行調試

11 nginx+wsgi

TODO:待添加操做步驟

參考資料

tortoisegit管理密鑰問題

       http://www.javashuo.com/article/p-xetjnpcx-gg.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

相關文章
相關標籤/搜索