一.安裝python3.6
1. 獲取
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
tar -xzvf Python-3.6.3.tgz -C? /tmp
cd? /tmp/Python-3.6.3/
2. 把Python3.6安裝到 /usr/local 目錄
yum install gcc
yum install zlib zlib-devel -y
./configure --prefix=/usr/local
make
make altinstall
3. 更改/usr/bin/python鏈接
????ln -s /usr/local/bin/python3.6 /usr/bin/python3
二. maridb
1. 安裝
? ? sudo yum install mariadb-server
2. 啟動斑响, 重啟
? ? sudo systemctl start mariadb
? ? sudo systemctl restart mariadb
3. 設置bind-ip
? ? vim /etc/my.cnf
? ? 在 [mysqld]:
? ? ? ? 下面加一行
? ? ? ? bind-address = 0.0.0.0
4. 設置外部ip可以訪問
? ? 先進入mysql才能運行下面命令:
? ? ? ? mysql 直接進入就行
? ? GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
? ? FLUSH PRIVILEGES;
5. 設置阿里云的對外端口
略
6. 安裝mysqlclient出問題
? ? centos 7:
? ? ? ? yum install python-devel mariadb-devel -y
? ? ubuntu:
? ? ? ? sudo apt-get install libmysqlclient-dev
? ? 然后:
? ? ? ? pip install mysqlclient
7.mariadb設置初始密碼
https://blog.csdn.net/hyq776141352/article/details/69808662
8.本地數(shù)據(jù)庫同步到mariadb(navicat)
全部數(shù)據(jù):右鍵本地數(shù)據(jù)庫--數(shù)據(jù)傳輸---選擇要同步的數(shù)據(jù)庫
表結構:暫無
三. 安裝nginx
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7
四. 安裝virtualenvwrapper
yum install python-setuptools python-devel
pip install virtualenvwrapper
編輯.bashrc文件鳖谈,添加下面2行
export WORKON_HOME=$HOME/.virtualenvs
source/usr/bin/virtualenvwrapper.sh
重新加載.bashrc文件
source? ~/.bashrc
新建虛擬環(huán)境
mkvirtualenv --no-site-packages -p /usr/bin/python3?mxonline
(刪除命令rmvirtualenv)
進入虛擬環(huán)境
workon mxonline (退出命令deactive)
安裝pip包
我們可以通過 pip freeze > requirements.txt 將本地的虛擬環(huán)境安裝包相信信息導出來
然后將requirements.txt文件上傳到服務器之后運行:
pip install -r requirements.txt
安裝依賴包
python manage.py runserver 0.0.0.0:8000 運行服務器測試
五. 安裝uwsgi
pip install uwsgi(虛擬環(huán)境下)
六. 測試uwsgi
https://www.cnblogs.com/teachen/p/9118926.html
setting配置
DEBUG =True
STATIC_URL ='/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static/mxshop"),)
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
進入服務器項目的文件目錄
python manage.py collectstatic 部署時收集靜態(tài)資源文件
uwsgi --http :8000 --module MxShop.wsgi?--static-map=/static=static? --static-map=/media=media(在沒有nginx情況下强饮,映射靜態(tài)資源并啟動)
uwsgi --http :8000 --file MxShop/wsgi.py? -d uwsgi.log?
七. 配置nginx
新建uc_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen? ? ? 80;
# the domain name it will serve for
server_name 你的ip地址 ; # substitute your machine's IP address or FQDN
charset? ? utf-8;
# max upload size
client_max_body_size 75M;? # adjust to taste
# Django media
location /media? {
? ? alias 你的目錄/Mxonline/media;? # 指向django的media目錄
}
location /static {
? ? alias 你的目錄/Mxonline/static; # 指向django的static目錄
}
# Finally, send all non-media requests to the Django server.
location / {
? ? uwsgi_pass? django;
? ? include? ? uwsgi_params; # the uwsgi_params file you installed
}
}
八. 將該配置文件加入到nginx的啟動配置文件中
sudo ln -s 你的目錄/Mxonline/conf/nginx/uc_nginx.conf /etc/nginx/conf.d/
更改/etc/nginx/nginx.conf 里面user為user root;防止訪問靜態(tài)資源出現(xiàn)403錯誤
九. 拉取所有需要的static file 到同一個目錄(已做過就不用)
在django的setting文件中,添加下面一行內容:
? ? STATIC_ROOT = os.path.join(BASE_DIR, "static/")
運行命令
? ? python manage.py collectstatic
十. 運行nginx
sudo /usr/sbin/nginx
這里需要注意 一定是直接用nginx命令啟動淮菠, 不要用systemctl啟動nginx不然會有權限問題
十一. 通過配置文件啟動uwsgi
新建uwsgi.ini 配置文件琴昆, 內容如下:
? ? # mysite_uwsgi.ini file
? ? [uwsgi]
? ? # Django-related settings
? ? # the base directory (full path)
? ? chdir? ? ? ? ? = /home/bobby/Projects/MxOnline
? ? # Django's wsgi file
? ? module? ? ? ? ? = MxOnline.wsgi
? ? # the virtualenv (full path)
? ? # process-related settings
? ? # master
? ? master? ? ? ? ? = true
? ? # maximum number of worker processes
? ? processes? ? ? = 10
? ? # the socket (use the full path to be safe
? ? socket? ? ? ? ? = 127.0.0.1:8000
? ? # ... with appropriate permissions - may be needed
? ? # chmod-socket? ? = 664
? ? # clear environment on exit
? ? vacuum? ? ? ? ? = true
? ? virtualenv = /home/bobby/.virtualenvs/mxonline
? ? logto = /tmp/mylog.log
注:
? ? chdir: 表示需要操作的目錄居夹,也就是項目的目錄
? ? module: wsgi文件的路徑
? ? processes: 進程數(shù)
? ? virtualenv:虛擬環(huán)境的目錄
workon mxonline
uwsgi --ini 你的目錄/Mxonline/conf/uwsgi.ini &
訪問
http://你的ip地址/
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?注:本文來自http://projectsedu.com/