linux --- 6. 项目部署
一.负载均衡1.准备三台机器,准备3台虚拟机,或者和俩同桌交流一下 192.168.226.128 是nginx资源服务器,返回页面的 192.168.226.129 用作nginx负载均衡服务器 192.168.226.130 也用作nginx资源服务器 2.分别配置三台机器 确保 128和130这2台机器,能正确的资源返回即可 这三个机器,都是通过修改nginx.conf来实现效果的 128此时返回 超哥 一米五的 页面 130返回 129配置反向代理 3.配置关键点 129(反向代理)负载均衡配置修改nginx.conf 1.轮询方式? ? 2.加权轮询? ? 3.哈希方式对ip地址进行哈希,适当分配 ? ? ?二.项目部署1.背景①django的启动方式 python3 manage.py runserver 为什么不能在生产环境用? django只是一个web逻辑框架,它通过python3 manage.py runserver命令启动的socket服务端
是借助python内置的wsgi框架 wsgiref框架实现的
它是一个单机模块,单进程模块,性能很低
? ? ②为什么要用nginx? 和uwsgi? nginx 可以解决uwsgi的静态文件问题,并且支持高并发请求,
? ? 2.准备 uwsgi? 工作①下载 uwsgi pip3 install uwsgi ? ? ②最开始的使用uwsgi命令启动django项目 ① uwsgi --http :8000 --module Crm_Project.wsgi --py-autoreload=1 ? ? ③ 如果你想启动一个http页面,提供测试访问,就用--http参数 ? 如果你结合了nginx反向代理,必须用--socket参数 ? ? ? ? ③ 引入配置文件?uwsgi.ini 1).放置位置无要求,可放在项目目录下, ? 2).内容如下 [uwsgi] # Django-related settings # the base directory (full path) #填写项目的绝对路径(第一层路径) chdir = /root/login # Django‘s wsgi file #填写crm第二层目录下的wsgi.py文件的路径 module = login.wsgi # the virtualenv (full path) #填写虚拟环境的绝对路径 home = /root/Envs/mycrm # process-related settings # master master = true # maximum number of worker processes #基于uwsgi的多进程,根据cpu来优化 processes = 4 # the socket (use the full path to be safe #如果你用了nginx反向代理,就填写socket参数 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 ? ④ 配置好文件后,启动 uwsgi --ini uwsgi.ini ? 3.静态文件的准备①编辑项目的 settings.py 文件 ? ? ②执行命令,收集crm 所有的静态文件 python3 manage.py collectstatic ? ? ? ③查看?/opt/crmstatic? 下静态文件是否已存在 ? ? 4.nginx的配置文件? nginx.conf① ? ? #当用户访问 www.s18dnf.com的时候,就进入这个虚拟主机 location / { uwsgi_pass 0.0.0.0:8000; include uwsgi_params; } #这个location是解决crm的静态文件的问题的 location /static { #alias参数 就是将/static转化为/opt/crmstatic ,也就找到了我们所有的静态文件 alias /opt/crmstatic; } ? ? ? ? ?② 重启?? nginx -s reload ? ? 三.配置 supervisro 工具? 注意要退出虚拟环境 ? ? 1.安装easy_install pip3是python3的软件包管理工具 easy_install 是python2的软件包管理工具 yum install python-setuptools 2.安装supervisor easy_install supervisor 3.创建supervisor的配置文件 echo_supervisord_conf > /etc/supervisor.conf 4.修改supervisor的配置文件,添加启动uwsgi的命令 supervisor其实就是帮咱们执行了,需要手动执行的命令而已 vim /etc/supervisor.conf 写入如下内容,在最底部写 [program:s18crm] command=/opt/python36/bin/uwsgi --ini /root/login/uwsgi.ini stopasgroup=true killasgroup=true ? 5.测试用supervisor启动uwsgi ,注意要确保此时uwsgi已经退出 supervisord -c /etc/supervisor.conf #这是启动supervisor服务端命令 supervisorctl -c /etc/supervisor.conf #这是supervisor客户端管理命令 6.学习supervisor的命令 status s18crm #查看状态 start s18crm #启动任务 stop s18crm #停止任务 start all stop all #启停所有的任务 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- linux – 使用scp将文件复制到不同的服务器
- How to allow/block PING on Linux server – IP
- 在Linux中使用C代码的Curly Brace用途(include /
- 如何在Linux x86上使用C对蓝牙LE设备进行编程?
- linux – Rundeck 2.5.1 – 本地执行的作业没有匹
- 按Ctrl键以使用Sublime Linux运行Makefile
- embedded-linux – 如何在Yocto图像配方中使用特
- 在Linux中使用LD_PRELOAD混合64位/ 32位环境
- linux – 新的KVM来宾无法访问外部局域网
- linux – 什么是脏私有内存?