1. 程式人生 > >django - 部署

django - 部署

one osi setting 配置服務器 配置服務 text workspace epo 虛擬

django項目部署

步驟

1.github建立新倉庫

[email protected]: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 [email protected]:yc913344706/learning_log.git

8. push代碼

如果在github的代碼倉裏原本有文件,則需要先pull

但是由於本地倉庫和遠程倉庫有不同祖先,所以需要“合並不同版本的歷史”

然後再次push即可

9. 服務器獲取代碼

9.1 服務器安裝git

9.2 服務器生成公私鑰

[yc@yc ~]$ ssh-keygen -t rsa -C "[email protected]"

9.3添加公鑰到github

9.4 驗證服務器git是否OK

[yc@yc .ssh]$ ssh -T [email protected]

9.5 配置服務器的git全局信息

[yc@yc .ssh]$ git config --global user.name "rhel_7"

[yc@yc .ssh]$ git config --global user.email "[email protected]"

9.6 拉取代碼

[yc@yc py_web_project]$ pwd

/data01/py_web_project

[yc@yc py_web_project]$ git clone [email protected]: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>YCs 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>YCs Learning Logs</p>
xshell中新開虛擬終端進行調試

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 - 部署