先安裝 apt-get中 需要安裝的包,然后再安裝 pip中的包
apt-get中需要安裝的包:
sudo apt-get install python3.6-dev
sudo apt-get install mysql-server
sudo?apt-get install mysql-client
?sudo?apt-get install redis-server
?安裝 nginx:??https://www.cnblogs.com/EasonJim/p/7806879.html
部署虛擬環(huán)境
現(xiàn)在非虛擬環(huán)境下安裝好python3.6
sudo pip install virtualenv? ?#安裝虛擬環(huán)境需要的包
virtualenv -p /usr/bin/python3.6 venv? #創(chuàng)建帶有python3.6的虛擬環(huán)境(自動(dòng)包含pip對(duì)應(yīng)版本)
virtualenv -p /usr/bin/python2.7 venv??#創(chuàng)建帶有python2.7的虛擬環(huán)境(自動(dòng)包含pip對(duì)應(yīng)版本,安裝supervisor時(shí)需要)
cd venv? ?#進(jìn)入到虛擬環(huán)境的目錄
source bin/activate? #進(jìn)入虛擬環(huán)境 成功后,命令行開頭 有 (venv)
安裝pip的包
pip install -r file.txt? ?#安裝pip相關(guān)包,先進(jìn)入虛擬環(huán)境
安裝supervisor
./bin/pip2.7 install supervisor? #通過pip2.7安裝 superviosr(因?yàn)閟upervisor不支持python3)
echo_supervisord_conf > supervisord.conf? #生成superviosr配置文件? ?https://blog.csdn.net/wr166/article/details/79051725? ?在python2的環(huán)境下用supervisor來運(yùn)行python3的web項(xiàng)目
vi supervisor.conf #打開后,輸入相關(guān)配置
supervisord -c supervisord.conf? #通過配置文件啟動(dòng)supervisor服務(wù)
?deactivate? #退出虛擬環(huán)境? ? ? ? # https://blog.csdn.net/charlie_heng/article/details/60573688? ??supervisor 在python3下的簡(jiǎn)易解決方案
?
防火墻/端口 開啟和關(guān)閉
開啟防火墻: ufw enable
關(guān)閉防火墻:ufw disable
開啟防火墻的端口 :ufw allow 端口號(hào); 如:ufw allow 5000
關(guān)閉防火墻的端口:ufw deny 端口號(hào);
重啟防火墻:ufw reload
查看防火墻端口的狀態(tài): ufw status
測(cè)試遠(yuǎn)程主機(jī)的端口是否開啟:? telnet 192.168.1.103 80
?
啟動(dòng)服務(wù)并外網(wǎng)可以訪問:
supervisor 中的配置文件:
[program:fws] #項(xiàng)目名
directory= /home/ubuntu/fws? #項(xiàng)目位置
environment = PATH='home/ubuntu/venv/bin'? #環(huán)境
command= /home/ubuntu/venv/bin/python3.6 run.py #運(yùn)行命令
autostart = true #自動(dòng)啟動(dòng)
startsecs = 1
autorestart = true #自動(dòng)重啟
stopasgroup = true?
killasgroup = true
user = ubuntu
stdout_logfile = /home/ubuntu/fws/logs/supevisor.log #輸出日志
stderr_logfile = /home/ubuntu/fws/logs/supevisor_err.log #錯(cuò)誤日志
run.py文件內(nèi)容:
from fws import appif __name__ == '__main__':app.run(host='10.104.136.123',port=5000) #host為內(nèi)網(wǎng)地址,端口號(hào)要檢查外網(wǎng)是否可以訪問
nginx配置內(nèi)容:
worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; log_format main escape=json '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" "$request_body"'; access_log /home/ubuntu/fws/logs/nginx.log main; error_log /home/ubuntu/fws/logs/nginx_err.log; sendfile on; keepalive_timeout 65; server { listen 8080; location / { proxy_pass http://10.104.136.123:5000; proxy_set_header X-Real-Ip $remote_addr; } location ^~ /index.html { alias /home/web/fws/fws/static/dist/; } location /static { alias /home/web/fws/fws/static/; } }}
?
然后啟動(dòng) supervisor,和nginx即可
?
?
其他相關(guān)命令記錄
pip list --format freeze? ?#?pip 列表
pip install -r file.txt? ?#pip批量安裝?
pip -V? ?#查看對(duì)應(yīng)的python編譯版本
whereis python3.6? ?#查看安裝路徑
https://www.cnblogs.com/yjlch1016/p/8641910.html? ? ? ?Ubuntu怎樣安裝Python3.6,pip
https://blog.csdn.net/San_South/article/details/80715682? ? ??Ubuntu16.04上pip報(bào)錯(cuò)ModuleNotFoundError: No module named 'pip._internal'
?https://blog.csdn.net/wangtaoking1/article/details/51554959? ? ??安裝Python mysqlclient出現(xiàn)“OSError: mysql_config not found”錯(cuò)誤
https://blog.csdn.net/meteor_s/article/details/79115360? ? ? ? ? ? ?Error記錄--ImportError: No module named apt_pkg
?error: command 'x86_64-linux-gnu-gcc' failed with exit status 1? ? ?需要根據(jù)python版本安裝對(duì)應(yīng)的python-dev包,如apt-get install pyton3.6-dev
?
來源:http://www.icode9.com/content-3-28391.html聯(lián)系客服