成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

fabric+supervisor+nginx+gunicorn配置實(shí)戰(zhàn)

AnthonyHan / 2836人閱讀

摘要:以為例系統(tǒng)初始化步驟初始化用戶豆瓣源,可以換成其他的源取消版本檢查,排除每次都報(bào)最新的具體配置文件后續(xù)說明添加開機(jī)自啟配置的情形,其實(shí)只要指

以ubuntu為例:

系統(tǒng)初始化步驟
#!/bin/bash

#初始化用戶
sudo useradd -rm -s /bin/bash demo
sudo adduser demo sudo
sudo passwd demo

sudo apt-get install build-essential python-software-properties software-properties-common -y
sudo apt-get install vim nano -y
sudo apt-get install supervisor -y

sudo add-apt-repository ppa:nginx/stable 
sudo add-apt-repository -y ppa:rwky/redis
sudo apt-get update

sudo apt-get install nginx aria2 axel wget curl -y
sudo apt-get install  redis-server -y

sudo apt-get install build-essential libssl-dev libffi-dev python-dev python3-dev -y
sudo apt-get install python3-pip -y
sudo apt-get install  convmv libevent-dev libssl-dev libffi-dev libsasl2-dev libpq-dev  libxml2-dev libxslt1-dev libldap2-dev  -y

vim ~/.pip/pip.conf
#[global]
#index-url = https://pypi.douban.com/simple #豆瓣源,可以換成其他的源
#disable-pip-version-check = true          #取消pip版本檢查,排除每次都報(bào)最新的pip
#timeout = 120

sudo pip3 install virtualenv
mkdir venv && cd venv 
virtualenv mdwiki
source mdwiki/bin/activate

pip3 install gunicorn

#具體配置文件后續(xù)說明
sudo vim  mdwiki/gunicorn.conf.py
sudo vim /etc/supervisor/conf.d/default.conf
sudo vim /etc/nginx/conf.d/default.conf

#添加開機(jī)自啟
sudo vim /etc/rc.local
#/usr/bin/supervisord -c /etc/supervisor/supervisord.conf

sudo update-rc.d nginx disable
supervisor配置

celery+virtualenv+supervisor的情形,其實(shí)只要指定celery程序?yàn)関irtaulenv下面的那個(gè)即可,例如/home/xby/venv/mdwiki/bin/celery

如果在gunicorn下出現(xiàn)"ascii" codec can"t encode...報(bào)錯(cuò),那么請?jiān)趕upervisor加入environment如下

environment=LANG="en_US.utf8", LC_ALL="en_US.UTF-8", LC_LANG="en_US.UTF-8"
[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
stopsignal=QUIT
priority=1
;user=www-data
[program:celeryworker]
directory=/opt/www/mdwiki
command=/path/to/celery worker -A app.util.tasks.celery_app  -f celery.worker.log -l info 
priority=5
autostart=true
autorestart=true
startsecs=10
user=www-data
[program:celerybeat]
directory=/opt/www/mdwiki
command=/path/to/celery beat -A app.util.tasks.celery_app  -f celery.beat.log -l info 
priority=6
autostart=true
autorestart=true
startsecs=10
user=www-data

[program:mdwiki]
;environment=SECRET_KEY=value,aliyun_api_key=value,aliyun_secret_key=value,MAIL_PASSWORD=value
;command=/usr/bin/gunicorn -n mdwiki -w 4 -b 127.0.0.1:4000 -k gevent app:app
environment=LANG="en_US.utf8", LC_ALL="en_US.UTF-8", LC_LANG="en_US.UTF-8"
command=/path/to/gunicorn app:app -c /path/to/gunicorn.conf.py
directory=/opt/www/mdwiki
;user=www-data
autostart=true
autorestart=true
priority=10
redirect_stderr = true  
stdout_logfile_maxbytes = 20MB  
stdout_logfile_backups = 20 
stdout_logfile = /var/log/mdwiki/mdwiki.log

; environment=PYTHONPATH=$PYTHONPATH:/path/to/somewhere
nginx配置
server {
    listen              80;
    listen              443 ssl;
    server_name         demo.com;
    ssl_certificate     /etc/nginx/ssl/nginx.crt;
    ssl_certificate_key /etc/nginx/ssl/nginx.key;
    server_tokens off;
    charset utf-8;
    client_max_body_size 20M;
    set $projdir "/opt/www/mdwiki";
    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
        proxy_pass http://127.0.0.1:4000;
    }
    location ~ ^/[^static].*.(jpg|png|gif|bmp|zip|docx)$ {
        expires 30d;
        root $projdir;
    }
    location ~ ^/static.*.(js|css|png|jpg|gif|bmp|map|ico|eot|svg|ttf|woff)$ {
        expires 30d;
        root $projdir/app;
    }

}
gunicorn.conf.py配置
#!/bin/bash

import multiprocessing

bind = "127.0.0.1:4000"
workers = multiprocessing.cpu_count() * 2 + 1
worker_class="gevent"
proc_name = "mdwiki"
user = "www-data"
chdir="/opt/www/mdwiki"
#daemon=False
#group = "nginx"
loglevel = "info"
errorlog = chdir+"/log/gunicorn/error.log"
accesslog= chdir+"/log/gunicorn/access.log"
raw_env = [
   r"MAIL_PASSWORD=pass",
   r"SECRET_KEY=xe6"
]
#ssl
#keyfile=
#certfile=
#ca_certs=
fabric遠(yuǎn)程發(fā)布
fab -f fabfile.py deploy

fabfile.py文件

from fabric.api import *
import os,sys
import tarfile
from contextlib import contextmanager
from fabric.contrib.files import exists

#$ fab -f fabfile.py -H localhost,remote host_type
def host_type():
    run("uname -s")

env.user= os.environ.get("USER","")
env.hosts= os.environ.get("HOST","").split(",")
env.password= os.environ.get("PASSWORD","")
env.sudo_password= os.environ.get("PASSWORD","")

active="source /home/xby/venv/mdwiki/bin/activate"

srcPath=r"C:Users	aojwDesktoppyworkmdwiki"
distPath=r"C:Users	aojwDesktoppyworkmdwikidist"
distFile=distPath+os.sep+"mdwiki.tar.gz"

#用于處理virtualenv環(huán)境,將其包裝成with上下文
@contextmanager
def virtualenv():
    with prefix(active):
        yield


if not os.path.exists(distPath):
    os.mkdir(distPath)

#本地打包分發(fā)文件
def pack():
    def ecludefiles(path):
        for name in ["venv","node_modules","websrc","__pycache__",".git",".idea","dist"]:
            if path.find(os.sep+name)>0:
                return True
        return False

    if os.path.exists(distFile):
        os.remove(distFile)
    #壓縮成tar.gz格式
    with tarfile.open(distFile,"w:gz") as f:
        f.add(srcPath,arcname="mdwiki",exclude=ecludefiles)

#部署
def deploy():
    #local pack dist file
    pack()
    
    remote_tmp="/tmp/mdwiki.tar.gz"

    localsize=os.path.getsize(distFile)
    remotesize=0
    #check if should upload again if there is a same file
    if exists(remote_tmp):
        remotesize=int(run("stat -c "%s" {0}".format(remote_tmp)))
        print(str(localsize)+":"+str(remotesize))
    if localsize!=remotesize:
        sudo("rm -f %s" % remote_tmp)
        # upload dist file
        put(distFile,remote_tmp)
    if not exists("/opt/www"):
        sudo("mkdir /opt/www")
        sudo("chown www-data:www-data /opt/www")

    #stop app and bak now
    with settings(warn_only=True):
        #delete previous bak
        sudo("rm -rf /opt/www/mdwiki_bak")
        sudo("supervisorctl stop all")
        if exists("/opt/www/mdwiki"):
            sudo("mv /opt/www/mdwiki /opt/www/mdwiki_bak")

    sudo("tar -zxvf /tmp/mdwiki.tar.gz -C /opt/www/")

    with cd("/opt/www/"):
        #replace data dir
        if exists("mdwiki_bak/data"):
            sudo("rm -rf mdwiki/data")
            sudo("cp -R mdwiki_bak/data mdwiki/")
        if exists("mdwiki_bak/app.db"):
            sudo("cp mdwiki_bak/app.db mdwiki/")

        sudo("chown -R www-data:www-data mdwiki")

        with virtualenv():
            run("pip3 install -r  mdwiki/requirements.txt")

    sudo("rm -f %s" % remote_tmp)
    sudo("supervisorctl start all")

#in your local shell run "fab deploy" command

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/38251.html

相關(guān)文章

  • fabric+supervisor+nginx+gunicorn配置實(shí)戰(zhàn)

    摘要:以為例系統(tǒng)初始化步驟初始化用戶豆瓣源,可以換成其他的源取消版本檢查,排除每次都報(bào)最新的具體配置文件后續(xù)說明添加開機(jī)自啟配置的情形,其實(shí)只要指 以ubuntu為例: 系統(tǒng)初始化步驟 #!/bin/bash #初始化用戶 sudo useradd -rm -s /bin/bash demo sudo adduser demo sudo sudo passwd demo sudo apt...

    lentoo 評論0 收藏0
  • 基于Flask-Angular的項(xiàng)目組網(wǎng)架構(gòu)與部署

    摘要:基于網(wǎng),分享項(xiàng)目的組網(wǎng)架構(gòu)和部署。項(xiàng)目組網(wǎng)架構(gòu)架構(gòu)說明流項(xiàng)目訪問分為兩個(gè)流,通過分兩個(gè)端口暴露給外部使用數(shù)據(jù)流用戶訪問網(wǎng)站。通過進(jìn)行配置,使用作為異步隊(duì)列來存儲任務(wù),并將處理結(jié)果存儲在中。 基于Raindrop網(wǎng),分享項(xiàng)目的組網(wǎng)架構(gòu)和部署。 項(xiàng)目組網(wǎng)架構(gòu) showImg(https://cloud.githubusercontent.com/assets/7239657/1015704...

    kelvinlee 評論0 收藏0
  • 如何在 virtualenv 環(huán)境下搭建 Python Web

    摘要:生產(chǎn)環(huán)境下,自帶的服務(wù)器,無法滿足性能要求。配置前面我們已經(jīng)在系統(tǒng)環(huán)境下安裝了安裝好的二進(jìn)制文件放在文件夾下,接下來使用來管理。參考文章探針安裝部署部署筆記在生產(chǎn)環(huán)境上部署使用詳解本文系工程師編譯整理。 由于字?jǐn)?shù)的限制,其實(shí)本篇文章的全標(biāo)題為 《如何在 virtualenv 環(huán)境下 Django + Nginx + Gunicorn+ Supervisor 搭建 Python Web》...

    roland_reed 評論0 收藏0
  • 如何在 virtualenv 環(huán)境下搭建 Python Web

    摘要:生產(chǎn)環(huán)境下,自帶的服務(wù)器,無法滿足性能要求。配置前面我們已經(jīng)在系統(tǒng)環(huán)境下安裝了安裝好的二進(jìn)制文件放在文件夾下,接下來使用來管理。參考文章探針安裝部署部署筆記在生產(chǎn)環(huán)境上部署使用詳解本文系工程師編譯整理。 由于字?jǐn)?shù)的限制,其實(shí)本篇文章的全標(biāo)題為 《如何在 virtualenv 環(huán)境下 Django + Nginx + Gunicorn+ Supervisor 搭建 Python Web》...

    godiscoder 評論0 收藏0
  • nginx + gunicorn + supervisor 部署 django 項(xiàng)目

    摘要:寫好項(xiàng)目后,要將項(xiàng)目部署到服務(wù)器上,可以采用,和的方式進(jìn)行部署。安裝虛擬環(huán)境當(dāng)一臺機(jī)器上部署多個(gè)項(xiàng)目的時(shí)候,各個(gè)項(xiàng)目依賴的包可能有沖突,互相影響。使用虛擬環(huán)境可以將各個(gè)項(xiàng)目的執(zhí)行環(huán)境隔離,互不影響。 寫好Django項(xiàng)目后,要將項(xiàng)目部署到服務(wù)器上,可以采用nginx,gunicorn和supervisor的方式進(jìn)行部署。 安裝虛擬環(huán)境 當(dāng)一臺機(jī)器上部署多個(gè)項(xiàng)目的時(shí)候,各個(gè)項(xiàng)目依賴的包可...

    Pocher 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<