最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解Django+uwsgi+Nginx上線最佳實(shí)戰(zhàn)

 更新時(shí)間:2019年03月14日 10:57:50   作者:BlueMiaomiao  
這篇文章主要介紹了Django+uwsgi+Nginx上線最佳實(shí)戰(zhàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

什么是uwsgi?

uWSGI是一個(gè)Web服務(wù)器,它實(shí)現(xiàn)了WSGI協(xié)議、uwsgi、http等協(xié)議。Nginx中HttpUwsgiModule的作用是與uWSGI服務(wù)器進(jìn)行交換。WSGI是一種Web服務(wù)器網(wǎng)關(guān)接口。它是一個(gè)Web服務(wù)器(如nginx,uWSGI等服務(wù)器)與web應(yīng)用(如用Flask框架寫(xiě)的程序)通信的一種規(guī)范。

  1. WSGI是一種通信協(xié)議。
  2. uwsgi是一種線路協(xié)議而不是通信協(xié)議,在此常用于在uWSGI服務(wù)器與其他網(wǎng)絡(luò)服務(wù)器的數(shù)據(jù)通信。uwsgi協(xié)議是一個(gè)uWSGI服務(wù)器自有的協(xié)議,它用于定義傳輸信息的類型(type of information),每一個(gè)uwsgi packet前4byte為傳輸信息類型描述,它與WSGI相比是兩樣?xùn)|西。
  3. uWSGI是實(shí)現(xiàn)了uwsgi和WSGI兩種協(xié)議的Web服務(wù)器。

在開(kāi)始之前

最小化安裝CentOS 6

備份網(wǎng)卡文件

~$ mkdir /etc/sysconfig/network-scripts/backup
~$ cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/backup/ifcfg-eth0.backup

配置阿里云鏡像源

~$ mkdir /etc/yum.repos.d/old
~$ mv /etc/yum.repos.d/CentOS-* /etc/yum.repos.d/old/
~$ cd /etc/yum.repos.d/
~$ curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
~$ yum clean all && yum repolist all && yum update -y
~$ reboot

Python3.6.0

上傳Python-3.6.0.tar.xz

~$ rz

安裝依賴

yum install zlib* gcc openssl openssl-devel libffi-devel -y
yum install pcre pcre-devel pcre-static -y

解壓Python-3.6.0.tar.xz

~$ tar -xvf Python-3.6.0.tar.xz
~$ cd Python-3.6.0

修改部分源代碼

~$ vim Modules/Setup.dist
# 將該文件的204到209行部分代碼取消注釋,完成后如下所示:
# Socket module helper for socket(2)
_socket socketmodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
_ssl _ssl.c \
  -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
  -L$(SSL)/lib -lssl -lcrypto

# The crypt module is now disabled by default because it breaks builds

編譯安裝

~$ ./configure
~$ make -j
~$ make install
~$ cd
~$ rm -rf Python-3.6.0

防火墻

# 恢復(fù)默認(rèn)配置
iptables -F
# 放通3306/8000/80端口
iptables -I INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 8000 -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
# 保存規(guī)則
/etc/init.d/iptables save

SELinux

關(guān)閉SELinux

~$ vim /etc/selinux/config
# 修改配置為如下所示:
SELINUX=permissive

~$ reboot

數(shù)據(jù)庫(kù)

二進(jìn)制方式安裝

# 查找相關(guān)舊文件并刪除
find / -name mysql
find / -name mariadb
# 移除全部相關(guān)包
rpm -qa | grep mysql
rpm -qa | grep mariadb
# 添加用戶
useradd mysql -s /sbin/nologin -M
# 解壓移動(dòng)文件
tar -xvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.24-linux-glibc2.12-x86_64 /applications/
ln -s /applications/mysql-5.7.24-linux-glibc2.12-x86_64/ /applications/mysql
# 創(chuàng)建配置文件
vim /etc/my.cnf
# 創(chuàng)建相關(guān)目錄
mkdir -p /data/mysql/data
mkdir -p /data/mysql/log
# 手動(dòng)創(chuàng)建日志文件
touch /data/mysql/log/mysqld.log
# 修改權(quán)限
chown -R mysql.mysql /applications/mysql
chown -R mysql.mysql /data/mysql

MySQL配置文件

[client]
port=3306
socket=/data/mysql/mysql.sock

[mysqld]
port=3306
datadir=/data/mysql/data
basedir=/applications/mysql
pid-file=/data/mysql/mysqld.pid
socket=/data/mysql/mysql.sock
user=mysql
character-set-server=utf8mb4
default-storage-engine=INNODB
collation-server = utf8mb4_general_ci
init_connect='SET NAMES utf8mb4'
max_connections = 1000
max_connect_errors = 1200
max_allowed_packet = 128M
explicit_defaults_for_timestamp = true
query_cache_size = 0
query_cache_type = 0
log_error = /data/mysql/log/error.log
slow_query_log = 1
slow_query_log_file = /data/mysql/log/slow.log
log_queries_not_using_indexes = 1
log_throttle_queries_not_using_indexes = 5
long_query_time = 8
log_slow_slave_statements = 1
min_examined_row_limit = 100
expire_logs_days = 5
tmpdir = /tmp
innodb_buffer_pool_size = 128M

[mysqld_safe]
log-error=/data/mysql/log/mysqld.log
pid-file=/data/mysql/mysqld.pid
# 同步數(shù)據(jù)
/applications/mysql/bin/mysql_install_db --basedir=/applications/mysql/ --datadir=/data/mysql/data/ --user=mysql

配置并啟動(dòng)

cp /applications/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld 
vim /etc/init.d/mysqld
# 修改以下兩行
basedir=/applications/mysql
datadir=/data/mysql/data
# 查看是否啟動(dòng)
netstat -tunlap | grep mysql
# 添加服務(wù)并設(shè)置為開(kāi)機(jī)自啟動(dòng)
chkconfig --add mysqld
chkconfig mysqld on

初始化數(shù)據(jù)庫(kù)

/applications/mysql/bin/mysql_secure_installation
-- 設(shè)置用戶密碼
alter user 'root'@'localhost' identified by '123456';
-- 允許root遠(yuǎn)程訪問(wèn)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Django

配置pip3源

mkdir /root/.pip
touch /root/.pip/pip.conf
echo '[global]' >> /root/.pip/pip.conf
echo 'trusted-host=mirrors.aliyun.com' >> /root/.pip/pip.conf
echo 'index-url=https://mirrors.aliyun.com/pypi/simple/' >> /root/.pip/pip.conf

創(chuàng)建虛擬環(huán)境安裝依賴

# PublisherPro,一個(gè)支持MD輕量級(jí)的CMS程式.
git clone https://gitee.com/bluemiaomiao/PublisherPro.git
pip3 install virtualenv
cd PROJECT_DIR
virtualenv venv
source venv/bin/activate
pip3 install -r requestments.txt
pip3 install uwsgi
mkdir log
mkdir script
touch PublisherPro/script/uwsgi.pid
touch PublisherPro/script/uwsgi.status
vim uwsgi.ini

修改項(xiàng)目配置

# PROJECT_DIR/PROJECT_NAME/settings.py
# 設(shè)置為生產(chǎn)環(huán)境
DEBUG = False
# 配置數(shù)據(jù)庫(kù)
DATABASES = {
 'default': {
  'ENGINE': 'django.db.backends.mysql',
  'NAME': 'publisher_pro',
  'USER': 'pubpro',
  'PASSWORD': 'bluemiaomiao',
  'HOST': '192.168.1.203',
  'PORT': '3306',
  'OPTIONS': {'init_command': 'SET default_storage_engine=INNODB;'},
 }
}
# 配置靜態(tài)文件相關(guān)
# STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

創(chuàng)建數(shù)據(jù)庫(kù)和用戶

CREATE DATABASE `publisher_pro` CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
CREATE USER `pubpro`@`localhost` IDENTIFIED BY 'bluemiaomiao' PASSWORD EXPIRE NEVER;
CREATE USER `pubpro`@`%` IDENTIFIED BY 'bluemiaomiao' PASSWORD EXPIRE NEVER;
GRANT All ON `publisher\_pro`.* TO `pubpro`@`%`;

同步數(shù)據(jù)庫(kù)

./venv/bin/python3 manage.py makemigrations
./venv/bin/python3 manage.py migrate
./venv/bin/python3 manage.py createsuperuser
./venv/bin/python3 manage.py collectstatic

uwsgi

配置文件內(nèi)容

# uwsig使用配置文件啟動(dòng)
[uwsgi]
# 項(xiàng)目目錄
chdir=/applications/website/PublisherPro
# 指定項(xiàng)目的application
module=PublisherPro.wsgi:application
# 指定sock的文件路徑  
socket=/applications/website/PublisherPro/script/uwsgi.sock
# 進(jìn)程個(gè)數(shù)  
workers=5
pidfile=/applications/website/PublisherPro/script/uwsgi.pid
# 狀態(tài)文件
stats=/applications/website/PublisherPro/script/uwsgi.status
# 指定IP端口  
http=0.0.0.0:8000
# 指定靜態(tài)文件
static-map=/static=/applications/website/PublisherPro/static
# 啟動(dòng)uwsgi的用戶名和用戶組
uid=pubpro
gid=pubpro
# 啟用主進(jìn)程
master=true
# 自動(dòng)移除unix Socket和pid文件當(dāng)服務(wù)停止的時(shí)候
vacuum=true
# 序列化接受的內(nèi)容,如果可能的話
thunder-lock=true
# 啟用線程
enable-threads=true
# 設(shè)置自中斷時(shí)間
harakiri=30
# 設(shè)置緩沖
post-buffering=4096
# 設(shè)置日志目錄
daemonize=/applications/website/PublisherPro/log/uwsgi.log

創(chuàng)建用戶和組并修改權(quán)限

# 創(chuàng)建用戶
useradd pubpro -s /sbin/nologin -M
# 檢查結(jié)果
id pubpro
# 修改權(quán)限
chown -R pubpro.pubpro /applications/website/PublisherPro/
# 檢查結(jié)果
ll -d /applications/website/PublisherPro/

測(cè)試Django應(yīng)用

# 啟動(dòng)應(yīng)用
uwsgi --ini uwsgi.ini
# 重載應(yīng)用
uwsgi --reload script/uwsgi.pid
# 狀態(tài)信息
uwsgi --connect-and-read script/uwsgi.status
# 停止應(yīng)用
uwsgi --stop script/uwsgi.pid

Nginx

server {
 listen 80;
 server_name 192.168.2.108;
 access_log /var/log/nginx/access.log main;
 charset utf-8;
 gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php application/json text/json image/jpeg image/gif image/png application/octet-stream;
 error_page 404 /404.html;
 error_page 500 502 503 504 /50x.html;

 # 指定項(xiàng)目路徑uwsgi
 location / {
    # 導(dǎo)入一個(gè)Nginx模塊他是用來(lái)和uWSGI進(jìn)行通訊的
  include uwsgi_params; 
    # 設(shè)置連接uWSGI超時(shí)時(shí)間
  uwsgi_connect_timeout 30; 
    # 指定uwsgi的sock文件所有動(dòng)態(tài)請(qǐng)求就會(huì)直接丟給他
  uwsgi_pass unix:/data/PublisherPro/script/uwsgi.sock; 
 }

 # 指定靜態(tài)文件路徑
 location /static/ {
  alias /data/PublisherPro/static;
  index index.html index.htm;
 }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解Python的Django框架中的Cookie相關(guān)處理

    詳解Python的Django框架中的Cookie相關(guān)處理

    這篇文章主要介紹了詳解Python的Django框架中的Cookie相關(guān)處理,Cookie存儲(chǔ)是每個(gè)開(kāi)發(fā)框架都會(huì)著重注意的重要功能,需要的朋友可以參考下
    2015-07-07
  • Python數(shù)據(jù)預(yù)處理時(shí)缺失值的不同處理方式總結(jié)

    Python數(shù)據(jù)預(yù)處理時(shí)缺失值的不同處理方式總結(jié)

    在使用python做數(shù)據(jù)分析的時(shí)候,經(jīng)常需要先對(duì)數(shù)據(jù)做統(tǒng)一化的處理,缺失值的處理是經(jīng)常會(huì)使用到的。今天介紹的是使用差補(bǔ)法/均值/固定值等不同的方式完成數(shù)據(jù)填充從而保證數(shù)據(jù)的完整性,感興趣的可以了解一下
    2022-12-12
  • python登錄pop3郵件服務(wù)器接收郵件的方法

    python登錄pop3郵件服務(wù)器接收郵件的方法

    這篇文章主要介紹了python登錄pop3郵件服務(wù)器接收郵件的方法,涉及Python操作郵件的相關(guān)技巧,需要的朋友可以參考下
    2015-04-04
  • Django和Ueditor自定義存儲(chǔ)上傳文件的文件名

    Django和Ueditor自定義存儲(chǔ)上傳文件的文件名

    這篇文章主要介紹了Django和Ueditor自定義存儲(chǔ)上傳文件的文件名,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02
  • Python3?DataFrame缺失值的處理方法

    Python3?DataFrame缺失值的處理方法

    這篇文章主要介紹了Python3?DataFrame缺失值的處理,包括缺失值的判斷缺失值數(shù)據(jù)的過(guò)濾及缺失值數(shù)據(jù)的填充,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-05-05
  • 跟老齊學(xué)Python之for循環(huán)語(yǔ)句

    跟老齊學(xué)Python之for循環(huán)語(yǔ)句

    看這個(gè)標(biāo)題,有點(diǎn)匪夷所思嗎?為什么for是難以想象的呢?因?yàn)樵趐ython中,它的確是很常用而且很強(qiáng)悍,強(qiáng)悍到以至于另外一個(gè)被稱之為迭代的東西,在python中就有點(diǎn)相形見(jiàn)絀了。在別的語(yǔ)言中,for的地位從來(lái)沒(méi)有如同python中這么高的。
    2014-10-10
  • python逐行讀取文件內(nèi)容的三種方法

    python逐行讀取文件內(nèi)容的三種方法

    這篇文章主要介紹了python逐行讀取文件內(nèi)容的三種方法,非常的簡(jiǎn)單,下面直接看代碼吧
    2014-01-01
  • 卸載所有通過(guò)pip安裝的Python包的方法總結(jié)(Windows系統(tǒng))

    卸載所有通過(guò)pip安裝的Python包的方法總結(jié)(Windows系統(tǒng))

    這篇文章主要介紹了卸載所有通過(guò)pip安裝的Python包的方法總結(jié)(Windows系統(tǒng)),文中通過(guò)代碼示例和圖文講解的非常詳細(xì),并具有一定的參考價(jià)值,需要的朋友可以參考下
    2024-08-08
  • Python開(kāi)發(fā)虛擬環(huán)境使用virtualenvwrapper的搭建步驟教程圖解

    Python開(kāi)發(fā)虛擬環(huán)境使用virtualenvwrapper的搭建步驟教程圖解

    virtualenvwrapper是用來(lái)管理virtualenv的擴(kuò)展包,用著很方便。這篇文章主要介紹了Python開(kāi)發(fā)虛擬環(huán)境使用virtualenvwrapper的搭建步驟 ,需要的朋友可以參考下
    2018-09-09
  • 數(shù)據(jù)庫(kù)連接池DBUtils的安裝使用方法

    數(shù)據(jù)庫(kù)連接池DBUtils的安裝使用方法

    DBUtils是Python的一個(gè)用于實(shí)現(xiàn)數(shù)據(jù)庫(kù)連接池的模塊,這篇文章主要介紹了數(shù)據(jù)庫(kù)連接池DBUtils的安裝使用方法,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-03-03

最新評(píng)論

陕西省| 永登县| 双桥区| 墨竹工卡县| 南通市| 革吉县| 河东区| 普兰店市| 凉城县| 平邑县| 闽清县| 南木林县| 兴宁市| 定日县| 平江县| 香格里拉县| 北宁市| 彰化市| 扶余县| 鸡泽县| 固镇县| 永修县| 永安市| 长阳| 盐津县| 蒙山县| 荥阳市| 无棣县| 鱼台县| 丹东市| 邵阳市| 柘城县| 三台县| 尚义县| 新民市| 河津市| 孟州市| 郓城县| 麟游县| 寿光市| 潜江市|