Linux项目部署实验步骤 项目Linux部署上线

Linux项目部署实验步骤
项目Linux部署上线
 
 
nginx
 
 
 
 
 
uwsgi+django
1.创建新的虚拟环境,且解决crm的环境依赖
 
2.在虚拟环境下安装uwsgi
pip3 install uwsgi
 
3.uwsgi命令,如何启动python应用
启动python web文件
创建一个test.py写入如下代码
def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return [b"Hello World"] # python3
 
    
用uwsgi启动一个python web文件
#指定8000端口启动 http服务
#指定wsgi文件
uwsgi --http :8000   --wsgi-file  test.py
 
 
 
4.用uwsgi启动django项目
uwsgi --http :9000 --module Alibab_crm.wsgi
如果被密码阻挡住的话就去Alibab_crm里面改settings.py里面的密码配置
 
 
uwsgi加上热加载命令
uwsgi --http :8000 --module Alibab_crm.wsgi   --py-autoreload=1
 
 
使用uwsgi配置文件去启动项目
    1.手动创建uwsgi.ini 配置文件
        (alicrm) [root@s16ds Alibab_crm]# cat uwsgi.ini
        # mysite_uwsgi.ini file
        [uwsgi]
        # Django-related settings
        # the base directory (full path)
        #指定django的项目目录,第一层
        chdir           = /opt/Alibab_crm
        # Django's wsgi file
        #找到django的wsgi文件
        #这里需要写项目的第二层目录Alibab_crm
        module          = Alibab_crm.wsgi
        # the virtualenv (full path)
        #填写虚拟环境的绝对路径
        home            = /root/Envs/alicrm
        # process-related settings
        # master
        master          = true
        # maximum number of worker processes
        processes       = 5
        # the socket (use the full path to be safe
        #指定socket协议,运行django,只能与nginx结合时使用
        #指定socket协议,运行django,只能与nginx结合时使用
        #指定socket协议,运行django,只能与nginx结合时使用
        socket          = 0.0.0.0:8000
 
        #如果你没用nginx,只想自己启动一个http界面,用这个
        #http =  0.0.0.0:8000
 
        # ... with appropriate permissions - may be needed
        # chmod-socket    = 664
        # clear environment on exit
        vacuum          = true
 
    2.通过配置文件启动uwsgi
    uwsgi --ini uwsgi.ini  
    
    
    
    
 
5.收集django  crm的静态文件
 
编辑crm的settings.py配置文件
写入如下代码
 
#定义django的静态资源根目录,便于用命令收集资源,存放的地儿
STATIC_ROOT="/opt/crm_static"
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
 
]
 
 
用命令收集静态文件
python3 manage.py collectstatic
 
 
6.配置nginx,反响代理django服务器,且解析静态文件
 
proxy_pass 仅仅是请求转发的参数,与uwsgi结合,还有跟高级的协议参数
 
修改nginx配置文件如下
 
    server {
        listen       80;
        server_name   s16chiji.com;
        location / {
            #root   /opt/s16chiji;
            #index  index.html;
            #使用uwsgi_pass 转发基于uwsgi协议的一个请求
            
            uwsgi_pass 192.168.15.71:8000;
            include  /opt/nginx112/conf/uwsgi_params;
        }
        #配置一个url的入口,告诉django静态文件在哪里去找
        #当请求url是 s16chiji.com/static/的时候
        #就进行别名,nginx去/opt/crm_static下寻找js文件
        location /static {
        alias  /opt/crm_static/;
}
       #通过这个参数,定义错误页面的文件  ,当状态码是 404 400 401 时,返回40x.html页面
        error_page  404 401 400 403              /40x.html;
    }
 
    
    
7.此时nginx结合uwsgi 已经完成
192.168.15.71
 
 
8.记住这里退出虚拟环境,使用物理环境去运行
8.记住这里退出虚拟环境,使用物理环境去运行
8.记住这里退出虚拟环境,使用物理环境去运行
deactivate
 
 
 
配置supervisor工具,管理django后台
 
这个东西只能用python2去实现
 
    1.下载supervisor
    easy_install supervisor
    
    2.配置supervisor的配置文件,编写django任务
    echo_supervisord_conf >  /etc/supervisor.conf
 
    3.编写运行django的任务
    vim /etc/supervisor.conf
    在最底行写入如下代码
 
    [program:s16alicrm]
    command=/root/Envs/alicrm/bin/uwsgi  --ini /opt/Alibab_crm/uwsgi.ini
    autorestart=true
    stopasgroup=true
    killasgroup=true
 
    4.启动suopersivod这个程序
    
    
    启动服务端
    supervisord -c /etc/supervisor.conf
    通过客户端命令查看任务
    supervisorctl -c /etc/supervisor.conf
    
    5.学习supervisor管理命令
    
    [root@s16ds alicrm]# supervisorctl -c /etc/supervisor.conf
    s16alicrm                        RUNNING   pid 5293, uptime 0:03:03
    supervisor> stop all   #停止所有任务
    supervisor> start all  #启动s所有任务
    supervisor> status s16alicrm
 
 
 
 
 
提示:如果下次开启连接数据库的时候被拒绝可能是因为mariadb 关闭了,输入
systemctl start mariadb
然后看3306端口是否存在
netstat -tunlp
 
查看进程
ps -ef |grep root
 
 
 

猜你喜欢

转载自www.cnblogs.com/hdy19951010/p/10447185.html