部署圖書管理項目須要如下軟件html
上傳圖書管理系統項目到linux服務器上python
在/opt/目錄下傳輸項目文件,數據庫文件一樣存放在這個文件夾下mysql
經過virtualenvwrapper工具的配置,解決虛擬環境問題linux
建立虛擬環境mkvirtualenv book_manage_envnginx
在centos7本體下安裝配置mariadb數據庫,且建立數據庫數據,遷移導入圖書管理系統數據sql
-測試使用linux的python解釋器去運行項目 切換到 項目中運行(注意要解決解釋器的模塊問題,才能正常運轉項目)數據庫
完成uWSGI命令學習,使用uWSGI啓動圖書管理系統項目,支持多進程django
(1)使用pip安裝uwsgi模塊vim
pip3 install uwsgi
(2)建立一個測試文件testuwsgi.py, 運行簡單的uWSGI站點windows
第一步vim /opt/book_homework/testuwsgi.py 寫入如下文件
def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello World"]
第二步 使用uwsgi命令啓動此文件
uwsgi --http :9000 --file testuwsgi.py
第三步 在瀏覽器經過IP加端口進行訪問
(3)使用uwsgi.ini文件,簡單的命令就能夠將uwsgi啓動起來
cd /opt/book_manage
vim uwsgi.ini
寫入配置文件
[uwsgi] # Django-related settings # the base directory (full path) # 寫上項目的絕對路徑 chdir = /opt/book_manage # Django's wsgi file # 填寫找到django的wsgi文件,填寫相對路徑,以chdir參數爲相對路徑 module = book_manage.wsgi # the virtualenv (full path) # 填寫虛擬環境的絕對路徑 home = /root/Envs/book_manage_env/ # process-related settings # master #啓動uwsgi主進程 master = true # maximum number of worker processes processes = 1 # the socket (use the full path to be safe #若是你使用了nginx,作反向代理,必須填寫socket連接,而不是http參數 socket = 0.0.0.0:8000 #若是你不用nginx,直接使用uwsgi,運行一個http服務端,就用這個http參數 http = 0.0.0.0:8000 # ... with appropriate permissions - may be needed # chmod-socket = 664 # clear environment on exit vacuum = true
使用uwsgi命令指定配置文件啓動,單個項目是能夠這麼啓動
uwsgi -ini /opt/book_homework/uwsgi.ini
收集django靜態文件
vim /opt/book_homework/book_homework/settings.py
加入一行配置,靜態文件
STATIC_ROOT='/opt/static'
回到django項目主目錄下(有manage.py文件的目錄), 輸入命令進行收集靜態文件
python3 manage.py collectstatic
下圖爲/opt/nginx112/conf/uwsgi_params文件
添加如下配置
location / { # nginx自帶ngx_http_uwsgi_module模塊,起到nginx和uwsgi交互做用 # 經過uwsgi_pass設置服務器地址和協議,將動態請求轉發給uwsgi處理 include /opt/nginx112/conf/uwsgi_params; uwsgi_pass 0.0.0.0:8000; root html; index index.html index.htm; } ************************************************************************************************************* location /static { alias /opt/static; }
如圖配置
nginx.conf所有配置文件以下
worker_processes 1; error_log logs/error.log; pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; sendfile on; keepalive_timeout 65; # nginx反向代理uwsgi server { listen 80; server_name qishijd.com; location / { # nginx自帶ngx_http_uwsgi_module模塊,起到nginx和uwsgi交互做用 # 經過uwsgi_pass設置服務器地址和協議,將動態請求轉發給uwsgi處理 include /opt/nginx112/conf/uwsgi_params; uwsgi_pass 0.0.0.0:8000; root html; index index.html index.htm; } # nginx處理靜態頁面資源 # 當用戶請求是qishijd.com/static/的時候, 就會進入這個location匹配 # 經過alias參數進行路徑別名,讓nginx去/opt/static底下去找靜態資源 location /static { alias /opt/static; } # nginx處理媒體資源 location /media{ alias /opt/nginx112/media; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
/opt/nginx112/sbin/nginx -s reload
這個主要是用於守護進程
/root/Envs/book_manage/bin/uwsgi --ini /opt/book_manage/uwsgi.ini
ps -ef | grep uwsgi
在瀏覽器訪問http://192.168.1.44已經能夠正常訪問,靜態文件也能夠正常加載了,修改數據也沒有問題, 說明數據庫鏈接正常
supervisor 是基於 python 的任務管理工具,用來自動運行各類後臺任務,固然你也能直接利用 nohup 命令使任務自動後臺運行,但若是要重啓任務,每次都本身手動 kill 掉任務進程,這樣很繁瑣,並且一旦程序錯誤致使進程退出的話,系統也沒法自動重載任務。
這裏咱們要配置基於virtualenv的supervisor,可是請注意:因爲supervisor在python3下沒法使用,所以只能用python2去下載!!!!!!
安裝suprvisor
easy_install supervisor # 這個是python2下面的安裝模塊命令,等同於python3下面的pip
若是沒有easy_install這個命令,就須要安裝setuptools工具
yum install python-setuptools
echo_supervisord_conf > /etc/supervisord.conf
[program:book_manage] command=/root/Envs/book_manage_env/bin/uwsgi /opt/book_manage/uwsgi.ini stopasgroup=true # 若是發現關閉supervisor進程後,結束uwsgi進 killasgroup=true # 程無效,就須要加上這兩個參數
如圖所示
supervisord -c /etc/supervisord.conf
# 任務管理命令以下:有兩種,一個是參數形式, 一個是交互式 # 參數形式 supervisorctl -c /etc/supervisor.conf stop/start/restart all supervisorctl -c /etc/supervisor.conf start crm_knight # 交互式形式 supervisorctl -c /etc/supervisor.conf
1、添加好配置文件後 2、更新新的配置到supervisord supervisorctl update 3、從新啓動配置中的全部程序 supervisorctl reload 4、啓動某個進程(program_name=你配置中寫的程序名稱) supervisorctl start program_name 5、查看正在守候的進程 supervisorctl 6、中止某一進程 (program_name=你配置中寫的程序名稱) pervisorctl stop program_name 7、重啓某一進程 (program_name=你配置中寫的程序名稱) supervisorctl restart program_name 8、中止所有進程 supervisorctl stop all 注意:顯示用stop中止掉的進程,用reload或者update都不會自動重啓。
a