项目上线全程

Posted djflask

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了项目上线全程相关的知识,希望对你有一定的参考价值。

1.买服务器,掏钱吧

2.连上服务器,22端口改一下,默认密码改复杂一点.其他的随意, 再adduser 一个个人账户, 没事别用root

给它加上sudo权限

usermod -a -G sudo wqk
# 再确认一下
groups wqk
切换到wqk
su wqk

3.安装虚拟环境,隔离项目

可以用pip或者apt安装,这里我们选择pip

a. 查看pip版本
          查看pip版本: pip -V
        查看pip3版本: pip3 -V
    b. 安装pip(如果存在则不需要安装)
        安装pip3: apt install python3-pip    
         安装pip2: apt install python-pip    
    c. 更新pip
          更新pip (如果pip版本高于9.0则不需要更新): 
              更新pip3: pip3 install --upgrade pip
             更新pip: pip install --upgrade pip
 
         注意: 更新后如出现以下错误(这是pip 10.0.0版本的BUG):
            Traceback (most recent call last): 
            File “/usr/bin/pip”, line 9, in 
            from pip import main

            解决方法:修改对应pip文件中的代码(pip和pip3类似)
                  例如更新pip时报错则需要修改 /usr/bin/pip 文件中的代码,
                使用: sudo vim /usr/bin/pip 打开pip文件
                将:          
                    from pip import main
                    if __name__ == __main__:
                        sys.exit(main())
                改成:
                    from pip import __main__
                    if __name__ == __main__:
                        sys.exit(__main__._main())

        
    d. pip命令
          pip install xxx:安装xxx依赖包
        pip list:查看所有依赖包
        pip freeze:查看新安装的包
        pip uninstall xxx :卸载xxx包

1.3, virtualenv和virtualenvwrapper 的安装和使用
   【请使用普通用户】 
    a. 安装虚拟环境
          sudo apt update
          sudo pip3 install virtualenv virtualenvwrapper
        sudo pip install virtualenv virtualenvwrapper
        sudo apt install virtualenv virtualenvwrapeer
        
        
        mkvirtualenv env3 -p /usr/bin/python3
          安装后如果不能使用虚拟环境命令,则需要配置环境变量
            1, 进入家目录: cd ~
            2, 使用vim打开.bashrc, 定位到最后:shift+g,并添加以下2行代码(注意修改自己Ubuntu的用户名)
                    export WORKON_HOME=/home/自己Ubuntu的用户名/.virtualenvs
                    source /usr/local/bin/virtualenvwrapper.sh
            3, 在家目录创建.virtualenvs目录: mkdir .virtualenvs
            4, 加载修改后的设置,使之生效:source .bashrc
            (如果找不到virtualenvwrapper.sh,
             则将路径改成/usr/local/bin/virtualenvwrapper.sh
             然后重试 )
      b. 创建虚拟环境: 
          mkvirtualenv env  
          mkvirtualenv env2 -p /usr/bin/python3  (指定python路径)
      c. 退出虚拟环境
          deactivate 
    d. 进入虚拟环境: 
          workon 虚拟环境名称

 4.虚拟环境里面安装库文件,  一般从开发环境里面pip -freeze > environment.txt直接拿出来  然后pip install -r environment.txt 进行安装

5.安装nginx,配置uwsgi,配置文件如下

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    
    limit_conn_zone $binary_remote_addr zone=one:100m;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
    server {
    listen 80 default_server;
    # listen [::]:8000 default_server;
    # limit_rate 12048k;
    root /var/www/OnlinePay;


    server_name _;
    location /static {
            alias /var/www/OnlinePay/static;
        }

    location / {
        include /etc/nginx/uwsgi_params;
        uwsgi_pass 127.0.0.1:8888;
        
    }
    location /down {
        limit_conn   one  1;  #限制每个IP只能发起一个并发连接
        limit_rate 9000k;
        alias /var/www/ipa/;
    }
}
    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    server {
    # listen [::]:8000 default_server;

    root /var/www/OnlinePay;
    server_name www.52qq.fun; # managed by Certbot

    location /static {
            alias /var/www/OnlinePay/static;
        }

    location / {
        include /etc/nginx/uwsgi_params;
        uwsgi_pass 127.0.0.1:8888;
        
    }
    location /down {
            alias /var/www/ipa/;
        }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/www.52qq.fun/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.52qq.fun/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
    server {
    if ($host = www.52qq.fun) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80 ;
    server_name www.52qq.fun;
    return 404; # managed by Certbot


}}


#mail {
#    # See sample authentication script at:
#    # http://wiki.nginx.org/ImapAuthenticateWithApachephpScript
# 
#    # auth_http localhost/auth.php;
#    # pop3_capabilities "TOP" "USER";
#    # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#    server {
#        listen     localhost:110;
#        protocol   pop3;
#        proxy      on;
#    }
# 
#    server {
#        listen     localhost:143;
#        protocol   imap;
#        proxy      on;
#    }
#}
[uwsgi]
# 使用nginx连接时 使用
socket=0.0.0.0:8888

# 直接作为web服务器使用
# http=0.0.0.0:8888
# 配置工程目录
chdir=/var/www/OnlinePay

# 配置项目的wsgi目录。相对于工程目录
wsgi-file=OnlinePay/wsgi.py

#配置进程,线程信息
processes=4

threads=10

enable-threads=True

master=True

pidfile=uwsgi.pid

daemonize=uwsgi.log

supervisord.conf

;[include]
;files = relative/directory/*.ini
[program:celery.worker] 
;指定运行目录 
directory=/var/www/OnlinePay
;运行目录下执行命令
command=celery -A OnlinePay worker --loglevel=info --concurrency=1

 

以上是关于项目上线全程的主要内容,如果未能解决你的问题,请参考以下文章

新书上市:Android APP开发实战 从规划到上线全程详解

新书上市:Android APP开发实战 从规划到上线全程详解

网页代码上线详解

[新增ST-001片段]全程字幕-20套UML+Enterprise Architect建模示范视频

牛棚资讯|全程托管化繁为简,京东云上线API网关服务

[新增EA003考勤系统演示片段]全程字幕-22套UML+Enterprise Architect建模示范视频