vagrant虚拟机的安装和Django的在虚拟机部署

    xiaoxiao2022-07-07  202

    linuk的安装

    1,首先进入到wwwroot下也就是虚拟机安装的目录下,查看当前安装的虚拟机

    vagrant box list

    2,删除原来的虚拟机

    vagrant box remove laravel/homestead

    3修改metadata.json文件,

    将version修改成9.1.0版本,防止下次进入自动更新虚拟机,最后记得修改成当前box文件的名称

    { "name": "laravel/homestead", "versions": [{ "version": "9.1.0", "providers": [{ "name": "virtualbox", "url": "e:/wwwroot/homestead-7.1.0.box" }] }] }

    4在wwwroot下运行metadata,json文件

    用js的方式安装,可以设置版本号,可以设置名称,一般用于被防火墙,只能下载包安装。

    vagrant box add metadata.json

    5将原来的homestead文件删除

    再从github上clone一份

    git clone https://github.com/laravel/homestead.git

    6切换到homestead文件下面

    初始化

    bash init.sh

    7修改Homestead.yaml

    修改成正确的路径,该路径就是映射目录

    folders: - map: E:/code to: /home/vagrant/code

    8打开虚拟机,首次打开会比较慢

    vagrant up

    报这个错是因为ssh的错误和缺少文件使用下面这个命令在生成一个ssh文件

    Check your Homestead.yaml (or Homestead.json) file, the path to your private key does not exist.

    解决办法

    ssh-keygen

    关机命令

    vagrant halt

    虚拟机的部署

    1安装pip3方便导入包

    sudo apt install python3-pip
    2安装ipython 带单词提示
    pip3 install IPython

    3分布式的安装

    pip3 install celery

    4安装的软件方便异步消息和部署

    sudo apt-get install rabbitmq-server

    5安装uwsgi

    pip3 install uwsgi

    6安装nginx

    sudo apt-get install nginx

    7项目根目录建立问价加config,里面新建文件uwsgi.ini和nginx.conf和uwsgi.pid里面只写进程数就行,例如2864

    [uwsgi] # variables projectname = huizong base = /home/vagrant/code/huizong # configuration master = true # virtualenv = /home/env/%(projectname) pythonpath = %(base) chdir = %(base) module = huizong.wsgi:application socket = /tmp/%(projectname).sock pidfile=%(base)/config/uwsgi.pid # the upstream component nginx needs to connect to upstream huizong { server unix:///tmp/huizong.sock; } server { # listen 80; listen 9000; # server_name www.shixiaolei.com shixiaolei.com; server_name 192.168.10.10:9000 ; location / { include /etc/nginx/uwsgi_params; uwsgi_pass huizong; } location /static/ { alias /home/vagrant/code/huizong/static/; } location /media/ { alias /home/vagrant/code/huizong/media/; } }

    8为nginx配置文件建立软链接

    sudo ln -s /home/vagrant/code/huizong/config/nginx.conf /etc/nginx/sites-enabled/huizong.conf

    8Django项目目录中输入命令,收集静态文件

    python3 manage.py collectstatic

    9Django项目目录中,执行命令

    uwsgi --ini config/uwsgi.ini

    10然后执行重启nginx命令

    sudo service nginx restart

    有什么问题可以跟小编交流啊,

    最新回复(0)