【Linux】部署单机项目以及前后端分离项目

Linux部署单机项目:

优点:

简化了系统管理:由于所有服务都在同一台机器上运行,因此可以简化系统管理和维护。

提高了性能:由于没有网络延迟和其他因素的影响,所以可以提高系统的性能。

缺点:

容易出现故障:如果一台机器发生故障,那么整个系统都会受到影响。

难以扩展:随着业务的发展,可能需要增加更多的服务器来处理请求,但是这在单机项目中是很难实现的。

一,部署单机

(这里我以之前发布过的项目:OA项目为例)

1.导入后台提供的数据库

2.将部署包放在主机上配置服务

关于部署包的生成,eclipse工具就选中我们要打包的文件进行打jar就行,idear开发工具使用maven先要clean,再install就行

然后启动项目

报错(原因是配置文件,配置sql的数据库不对)

修改配置连接的密码

二,部署前后端分离项目

2.1导入数据库

2.2后端连接,403是后端验证,这时我们就要使用node.js

2.3安装node.js

这里这篇博客已经非常详细了http://t.csdnimg.cn/hx7MChttp://t.csdnimg.cn/hx7MC

npm config set cache "C:\software\node-v18.16.1-win-x64\node-v18.16.1-win-x64\node_cache"

npm config set prefix "C:\software\node-v18.16.1-win-x64\node-v18.16.1-win-x64\node_global"

npm config set registry https://registry.npm.taobao.org/

npm config get registry

node_global:npm全局安装位置

node_cache: npm缓存路径

node.js的环境配置: %NODE_HOME%;%NODE_HOME%\node_global;

注:C:\software\node-v18.16.1-win-x64\node-v18.16.1-win-x64\node_cache为安装node.js的根目录

2.4如果直接这么访问就会访问不到,只有虚拟机自己才可访问。

2.5解决方法第一种:

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

#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;
    #    }
    #}
 
}

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

成功

方法二:在spa项目中找到config 文件下的index.jshost:'localhost' 改为0.0.0.0

部署成功!!!

相关推荐
存储服务专家StorageExpert9 分钟前
DELL SC compellent存储的四种访问方式
运维·服务器·存储维护·emc存储
hakesashou1 小时前
python如何比较字符串
linux·开发语言·python
Ljubim.te1 小时前
Linux基于CentOS学习【进程状态】【进程优先级】【调度与切换】【进程挂起】【进程饥饿】
linux·学习·centos
cooldream20091 小时前
Linux性能调优技巧
linux
大G哥1 小时前
记一次K8S 环境应用nginx stable-alpine 解析内部域名失败排查思路
运维·nginx·云原生·容器·kubernetes
长天一色1 小时前
【ECMAScript 从入门到进阶教程】第三部分:高级主题(高级函数与范式,元编程,正则表达式,性能优化)
服务器·开发语言·前端·javascript·性能优化·ecmascript
醉颜凉1 小时前
银河麒麟桌面操作系统修改默认Shell为Bash
运维·服务器·开发语言·bash·kylin·国产化·银河麒麟操作系统
QMCY_jason2 小时前
Ubuntu 安装RUST
linux·ubuntu·rust
慕雪华年2 小时前
【WSL】wsl中ubuntu无法通过useradd添加用户
linux·ubuntu·elasticsearch
苦逼IT运维2 小时前
YUM 源与 APT 源的详解及使用指南
linux·运维·ubuntu·centos·devops