【Linux】虚拟机项目部署与发布

目录

一、Linux部署单机项目

1.1 优缺点

1.2  将项目共享到虚拟机

1.3 解压后将war包放入tomcat

1.4 数据库导入脚本 

1.5 Tomcat启动项目

二、部署前后端分离项目

2.1 准备工作

2.2 部署SPA项目

2.2.1 nginx反向代理

2.2.2 SPA项目宿主机访问 


一、Linux部署单机项目

1.1 优缺点

  • 优点:

        简化了系统管理:由于所有服务都在同一台机器上运行,因此可以简化系统管理和维护。提高了性能:由于没有网络延迟和其他因素的影响,所以可以提高系统的性能。

  • 缺点:

        容易出现故障:如果一台机器发生故障,那么整个系统都会受到影响。难以扩展:随着业务的发展,可能需要增加更多的服务器来处理请求,但是这在单机项目中是很难实现的。

1.2  将项目共享到虚拟机

1.3 解压后将war包放入tomcat

1.4 数据库导入脚本 

连接虚拟机数据库,新建数据库导入脚本 

1.5 Tomcat启动项目

在主机通过虚拟机ip地址进行访问 

如果登入不上,很有可能是数据库的密码和项目配置的数据库密码不一致,在tomcat已开启的项目中进行修改,找到项目中配置数据库密码的配置文件,在里面进行修改密码即可:

列如 : ( tomcat/webapps/oapro/WEB-INF/classes )

二、部署前后端分离项目

2.1 准备工作

1、在虚拟机中,将前后端分离项目的wer包放到tomcat的webapps目录中。

2、通过主机将所需数据表导入进虚拟机的数据库,需要数据库的名称是很后端的数据库配置的名称一致。

3.nodeJS下载暗转

        官网下载: nodeJS 资源包 : 下载 | Node.js

        博文参考:

Vue路由与nodejs环境搭建

2.2 部署SPA项目

通过npm run dev 指令启动spa项目

        最后运行前端项目会发现一个问题。在主机中的浏览器不能访问虚拟机中的前端项目。因为主机在虚拟机中的前端项目的被端口限制了的问题。解决以下问题呢,有两种方法可以解决

2.2.1 nginx反向代理

        Nginx是一款高性能的Web服务器和反向代理服务器,它可以处理高并发的请求,支持多种协议和编程语言,具有高度的可扩展性和稳定性。Nginx最初是由Igor Sysoev编写的,于2004年首次发布。

Nginx是一款高性能、高可用、安全可靠的Web服务器和反向代理服务器,广泛应用于各种Web应用场景,是现代Web应用架构中不可或缺的一部分。 

解决方案1:

1、利用nginx做反向代理处理该问题,在nginx文件中找到nginx.conf 文件,将文件种的 location 进行修改。

nginx.config :

 
#user  nobody;
worker_processes  1;
 
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
#pid        logs/nginx.pid;
 
 
events {
    worker_connections  1024;
}
 
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    #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  logs/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
    #keepalive_timeout  0;
    keepalive_timeout  65;
 
    #gzip  on;
 
    server {
        listen       80;
        server_name  localhost;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            proxy_pass   http://localhost:8081;
        }
 
        #error_page  404              /404.html;
 
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
 
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
 
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
 
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
 
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
 
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
 
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
}

2、在nginx根目录下输入cmd进入命令窗口输入 nginx.exe -s reload重启

2.2.2 SPA项目宿主机访问 

在spa项目中找到config文件下的index.js将localhost改为0.0.0.0 

猜你喜欢

转载自blog.csdn.net/Justw320/article/details/134086935
今日推荐