目錄css
項目部署,環境準備html
1.python3虛擬環境準備前端
mkvirtualenv -p python3 my_django
2.安裝uwsgivue
pip3 install uwsgi
安裝 djangonode
pip3 install django==1.11.18 pip3 install -i https://pypi.douban.com/simple pymysql pip3 install -i https://pypi.douban.com/simple django-multiselectfield
3.經過uwsgi啓動django項目python
1.進入項目的第一層 cd Ace_crm 2.執行命令啓動django uwsgi --http :8000 --module Ace_crm.wsgi
4.熱加載uwsgi 命令以下mysql
uwsgi --http :8088 --module mysite.wsgi --py-autoreload=1
5.經過配置文件,啓動uwsgi
這個文件叫作 uwsgi.inilinux
#手動建立這個配置文件,寫入以下信息 [uwsgi] # Django-related settings # the base directory (full path) #這裏寫入項目的絕對路徑 chdir = /opt/crm/Ace_crm # Django's wsgi file #寫入django的第二層文件夾,和wsgi.py文件 module = Ace_crm.wsgi # the virtualenv (full path) #虛擬環境的絕對路徑 home = /root/Envs/my_django # process-related settings # master master = true # maximum number of worker processes processes = 5 #若是你沒用nginx,想直接訪問django後臺,能夠使用http協議 #http = 0.0.0.0:8000 #若是你用了nginx進行反向代理,請使用socket協議,註釋掉http協議 #若是你用了nginx進行反向代理,請使用socket協議,註釋掉http協議 #若是你用了nginx進行反向代理,請使用socket協議,註釋掉http協議 socket = 0.0.0.0:8000 # ... with appropriate permissions - may be needed # chmod-socket = 664 # clear environment on exit vacuum = true 啓動 uwsgi --ini uwsgi.ini
6.nginx結合uwsgi 啓動nginx
1.修改nginx配置 nginx.conf以下 #是nginx進行反向代理 location / { include uwsgi_params; uwsgi_pass 0.0.0.0:8000; } #http://192.168.11.250/static/admin/css/base.css #當請求url,從static路徑開始時,咱們就讓他去找某一個文件夾 #解決靜態文件的配置方式 location /static { alias /opt/aceCrmStatic; } 2.修改django的settings.py,收集靜態資源 1.修改settings.py以下 STATIC_ROOT="/opt/aceCrmStatic" STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static') ] 3.使用命令收集django的靜態文件 python3 manage.py collectstatic 4.此時靜態頁面配置完畢
1.安裝supervisorweb
yum install python-setuptools easy_install supervisor
2。安裝完畢後,生成配置文件
echo_supervisord_conf > /etc/supervisord.conf
3.在配置文件中,添加任務,管理uwsgi
vim /etc/supervisord.conf #在最底行,寫入配置以下 [program:s17uwsgi] command=/root/Envs/my_django/bin/uwsgi --ini /opt/crm/Ace_crm/uwsgi.ini stopasgroup=true killasgroup=true [program:s17nginx] command=/opt/tnginx220/sbin/nginx stopasgroup=true killasgroup=true
4.啓動supervisor服務
supervisord -c /etc/supervisord.conf
5.經過命令管理任務,管理uwsgui
supervisorctl -c /etc/supervisord.co
6。學習管理supervisor的命令
start 任務名 stop 任務名 stop all start all status 任務名
nginx + uwsgi + crm + mariadb +supervisor
一.準備代碼
二. 從後端搞起
解決環境依賴
把能夠正常運行路飛哪一個機器地下的python包,所有導出來,就能夠
pip3 freeze > requirements.txt
把這個文件,傳輸給linux系統 linux再經過命令安裝 pip3 install -r requirements.txt 經過模塊依賴文件,直接安裝,着是從講師機器上下載的 手動建立依賴文件,而後寫入
(s17luffy) [root@master luffy_boy]# cat requirements.txt
certifi==2018.11.29
chardet==3.0.4
crypto==1.4.1
Django==2.1.4
django-redis==4.10.0
django-rest-framework==0.1.0
djangorestframework==3.9.0
idna==2.8
Naked==0.1.31
pycrypto==2.6.1
pytz==2018.7
PyYAML==3.13
redis==3.0.1
requests==2.21.0
shellescape==3.4.1
urllib3==1.24.1
uWSGI==2.0.17.1
安裝uwsgi啓動後端
pip3 install uwsgi
啓動方式1,用參數啓動uwsgi --socket :8000 --module luffy_boy.wsgi 啓動方式2:用配置文件啓動 touch uwsgi.ini 寫入配置: [uwsgi] # Django-related settings # the base directory (full path) chdir = /opt/luffy_boy # Django's wsgi file module = luffy_boy.wsgi # the virtualenv (full path) home = /root/Envs/vue # process-related settings # master master = true # maximum number of worker processes processes = 1 # the socket (use the full path to be safe socket = 0.0.0.0:6666 # ... with appropriate permissions - may be needed # chmod-socket = 664 # clear environment on exit vacuum = true
二. 開始搞前段(vue)
1. 準備node環境 ,下載node環境包 wget https://nodejs.org/download/release/v8.6.0/node-v8.6.0-linux-x64.tar.gz 2. 解壓縮node包 tar -zxvf node-v8.6.0-linux-x64.tar.gz 3. 添加node到環境變量 PAHT="node環境" vim /etc/pro.. source /etc/pro.. 4. 開始編譯打包前端vue文件 1.修改vue提交的請求地址,修改文件是 /opt/s17luffy/07-luffy_project_01/src/restful/api.js 2.更改接口內的地址 本來是 127.0.0.1:8000/ 改爲服務器的ip地址+端口 sed -i "s/127.0.0.1/192.168.11.175/g" /opt/07-luffy_project_01/src/restful/api.js 此時進入vue代碼的第一層文件夾 cd /opt/s17luffy/07-luffy_project_01 3.安裝node模塊,這是找到package.json,安裝它的內容 npm install 4.編譯打包vue代碼,這一步會生成dist靜態文件夾,用於nginx展現,路飛的頁面都在這了 npm run build 5. 配置nginx去找到這個路飛學城頁面 修改nginx.conf(也能夠利用include /opt/tnginx220/conf/conf.d/*.conf; 去conf.d配置) 參數以下 虛擬主機1,用於找到vue頁面 server { listen 80; server_name s17dnf.com; location / { root /opt/07-luffy_project_01/dist; index index.html; } } 虛擬主機2,用於反向代理,找到django server{ listen 8000; server_name 192.168.11.250; location / { include uwsgi_params; uwsgi_pass 0.0.0.0:6666; } } 6. 重啓 nginx 7. 啓動redis數據庫,支撐購物車數據 redis-server redis.conf
三. 確保前端vue正常,後端django正常,nginx啓動正常,redis啓動正常,在windows中訪問頁面