实现部署django

 

 

 

 

去配置中:

 

 

 

 切换完了之后要发送到远程的服务器,首先要先造一个服务器,(k8s-node-01 就作为测试服务器)

[root@k8s-node-01 ~]# yum install python3 python3-devel -y
[root@k8s-node-01 ~]# pip3 install uwsgi

[root@k8s-node-01 ~]# pip3 install django==2.2.2
在pycharm中新建myweb.ini [uwsgi] # 端口号 socket = :8000 # 指定项目的目录 chdir = /opt/linux # wsgi文件路径 wsgi-file = linux/wsgi.py # 模块wsgi路径 module = linux.wsgi # 是否开启master进程 master = true # 工作进程的最大数目 processes = 4 # 结束后是否清理文件 vacuum = true #指定PID文件路径 pidfile = /var/run/linux.pid


[root@k8s-node-01 ~]# cd /opt
[root@k8s-node-01 opt]# ll

drwx--x--x 4 root root  28 Jan  1 16:40 containerd

链接远程的测试服务器

[root@jenkins django]# ssh-keygen
[root@jenkins django]# cat ~/.ssh/id_rsa

在Jenkins中增加实验环境

 

 

 

 

 如果测试不成功,先去做免密

[root@jenkins django]# ssh-copy-id root@192.168.15.104

 此时再去jenkins-django中配置 构建后操作

 

 

 

[root@k8s-node-01 opt]# which uwsgi
/usr/local/bin/uwsgi

[root@k8s-node-01 opt]# mkdir /opt/linux

 

 

 

 记得push myweb.ini

修改settings.py

ALLOWED_HOSTS = ["*"]

DATABASES = {


}
记得部署前打标签

 

 


[root@k8s-node-01 linux]# yum install nginx
[root@k8s-node-01 linux]# vim /etc/nginx/nginx.conf  #删除注释
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
    worker_connections 1024;
}
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    include /etc/nginx/conf.d/*.conf;
}
vim /etc/nginx/conf.d/django.conf

server {
        # 监听的端口
        listen 80;
        # 配置域名
        server_name bbs.test.com;
        # 配置路径
        location / {
                # 加载Nginx代理uwsgi的配置项 
                include uwsgi_params;
                # 指定uwsgi的访问地址
                uwsgi_pass 127.0.0.1:8000;
                # 连接uwsgi的超时时间
                uwsgi_read_timeout 2;
                # 自定义uwsgi代理项目的路径及配置项
                uwsgi_param UWSGI_SCRIPT linux.wsgi;
                # 指定python项目的路径
                uwsgi_param UWSGI_CHDIR /opt/linux;
                # 索引文件
                index  index.html index.htm;
                # 客户端上传文件的最大值
                client_max_body_size 35m;
        }
}
[root@k8s-node-01 linux]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@k8s-node-01 linux]# systemctl restart nginx

此时,浏览器访问http://192.168.15.104/

 

 此时,更改views.py中hello baby为hello china,重新push,构建,浏览器访问,

 

 

 

 
posted @ 2022-01-13 18:57  甜甜de微笑  阅读(123)  评论(0编辑  收藏  举报