华为云L实例云服务器部署前后端分离项目全过程记录

1、配置云服务器

https://blog.csdn.net/modaoshi51991/article/details/139547630

2、上传前端项目并配置nginx

首先在前端项目运行以下代码将项目打包

我遇到node.js和openssl两个版本不兼容问题,更新版本依次解决即可

bash 复制代码
vue-cli-service build

看一下package.json文件里脚本配置里面对应的命令,运行那个

一般会把项目整个打包到dist文件里,然后上传dist文件即可

bash 复制代码
> ruoyi@3.8.1 build:prod
> vue-cli-service build


|  Building for production...Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports (C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\util\createHash.js:135:53)
    at NormalModule._initBuildHash (C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:417:16)
    at handleParseError (C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:471:10)
    at C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:503:5
    at C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:358:12
    at C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:373:3
    at iterateNormalLoaders (C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
    at iterateNormalLoaders (C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:221:10)
    at C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:236:3
    at runSyncOrAsync (C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:130:11)
    at iterateNormalLoaders (C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:232:2)
    at Array.<anonymous> (C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:205:4)
    at Storage.finished (C:\D\USERPROG\ruoyi-ui\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
    at C:\D\USERPROG\ruoyi-ui\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
|  Building for production...C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:114
                        throw e;
                        ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports (C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\util\createHash.js:135:53)
    at NormalModule._initBuildHash (C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:417:16)
    at handleParseError (C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:471:10)
    at C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:503:5
    at C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:358:12
    at C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:373:3
    at iterateNormalLoaders (C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
    at iterateNormalLoaders (C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:221:10)
    at C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:236:3
    at context.callback (C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:111:13)
    at C:\D\USERPROG\ruoyi-ui\node_modules\cache-loader\dist\index.js:147:7
    at C:\D\USERPROG\ruoyi-ui\node_modules\graceful-fs\graceful-fs.js:61:14
    at FSReqCallback.oncomplete (node:fs:197:23) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}
bash 复制代码
Browserslist: caniuse-lite is outdated. Please run:
  npx browserslist@latest --update-db
  Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating

|  Building for production...Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports (C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\util\createHash.js:135:53)
    at NormalModule._initBuildHash (C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:417:16)
    at handleParseError (C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:471:10)
    at C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:503:5
    at C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:358:12
    at C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:373:3
    at iterateNormalLoaders (C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
    at iterateNormalLoaders (C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:221:10)
    at C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:236:3
    at runSyncOrAsync (C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:130:11)
    at iterateNormalLoaders (C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:232:2)
    at Array.<anonymous> (C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:205:4)
    at Storage.finished (C:\D\USERPROG\ruoyi-ui\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
    at C:\D\USERPROG\ruoyi-ui\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:114
                        throw e;
                        ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports (C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\util\createHash.js:135:53)
    at NormalModule._initBuildHash (C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:417:16)
    at handleParseError (C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:471:10)
    at C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:503:5
    at C:\D\USERPROG\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:358:12
    at C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:373:3
    at iterateNormalLoaders (C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
    at C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:186:6
    at context.callback (C:\D\USERPROG\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:111:13)
    at C:\D\USERPROG\ruoyi-ui\node_modules\cache-loader\dist\index.js:240:7
    at C:\D\USERPROG\ruoyi-ui\node_modules\neo-async\async.js:2830:7
    at done (C:\D\USERPROG\ruoyi-ui\node_modules\neo-async\async.js:2865:11)
    at C:\D\USERPROG\ruoyi-ui\node_modules\neo-async\async.js:2818:7
    at Array.<anonymous> (C:\D\USERPROG\ruoyi-ui\node_modules\cache-loader\dist\index.js:229:9) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v18.13.0

安装 EPEL(Extra Packages for Enterprise Linux)存储库:

bash 复制代码
sudo yum install epel-release

安装 Nginx:

bash 复制代码
sudo yum install nginx

启动并启用 Nginx:

bash 复制代码
sudo systemctl start nginx
sudo systemctl enable nginx

上传dist文件到服务器指定目录

bash 复制代码
scp -r ./dist/* username@your_server_ip:/var/ww/myapp

编辑 Nginx 配置文件以指向你的应用目录:

bash 复制代码
sudo vi /etc/nginx/conf.d/myapp.conf

在配置文件中添加以下内容:

bash 复制代码
server {
    listen       80;
    server_name  your_domain_or_ip;//只需要将your_domain_or_ip改成服务器域名或者公网ip即可

    location / {
        root   /var/www/myapp;
        index  index.html;
        try_files $uri $uri/ /index.html;
    }

# 转发后端请求到 Tomcat
    location /backend/ {
        proxy_pass http://localhost:8080/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    # Serve gzipped files if available
    gzip_static on;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_min_length 256;
}

测试 Nginx 配置文件的正确性:

bash 复制代码
sudo nginx -t

如果配置文件测试通过,重启 Nginx:

bash 复制代码
sudo systemctl restart nginx

确保防火墙允许 HTTP 流量:

bash 复制代码
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

在浏览器中访问你的域名或服务器 IP,确保你的前端应用已经成功部署。

然后就可以通过http://your_eip访问你的前端页面了

3、下载jdk,tomcat、maven,mysql,打包后端项目,创建新数据库,上传后端项目并复制到tomcat目录下

下载jdk

bash 复制代码
sudo dnf install java-1.8.0-openjdk-devel

验证

bash 复制代码
java -version

使用 wget 命令下载 Tomcat 9.0.89:(需要到官网查看最新版本,替换里面的版本号)

bash 复制代码
cd /tmp
wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.89/bin/apache-tomcat-9.0.89.tar.gz

将下载的压缩包解压到你想安装的目录,例如 /opt/tomcat:

bash 复制代码
sudo mkdir /opt/tomcat
sudo tar xvf apache-tomcat-9.0.89.tar.gz -C /opt/tomcat --strip-components=1

验证

bash 复制代码
sudo systemctl status tomcat

在浏览器中打开 http://:8080,如果看到 Tomcat 欢迎页面,说明 Tomcat 已成功安装并运行。

下载maven

如果遇到yum的问题看如下文章解决

https://blog.csdn.net/modaoshi51991/article/details/139606895

打包java后端项目

使用 cd 命令切换到你的项目目录。

bash 复制代码
cd C:\D\USERPROG\rear\RuoYi-Vue

运行 Maven 构建命令:

bash 复制代码
mvn clean package

下载mysql

如果遇到问题参考我的这篇文章

https://blog.csdn.net/modaoshi51991/article/details/139725384?csdn_share_tail={"type"%3A"blog"%2C"rType"%3A"article"%2C"rId"%3A"139725384"%2C"source"%3A"modaoshi51991"}

安装 MySQL:

bash 复制代码
sudo yum install mysql-community-server -y

启动 MySQL 服务:

bash 复制代码
sudo systemctl start mysqld

设置 MySQL 开机自启动:

bash 复制代码
sudo systemctl enable mysqld

获取 MySQL 临时 root 密码:

bash 复制代码
sudo grep 'temporary password' /var/log/mysqld.log

运行 MySQL 安全安装向导:

bash 复制代码
sudo mysql_secure_installation

运行这个命令后,系统会提示你输入临时 root 密码,然后进行一些安全配置:

Enter password for user root: 输入临时密码 dw)<Zk*rs1b+

New password: 设置一个新的 root 密码

Re-enter new password: 再次输入新密码以确认

Do you wish to continue with the password provided? (Press y|Y for Yes, any other key for No): 输入 Y

Remove anonymous users? (Press y|Y for Yes, any other key for No): 输入 Y

Disallow root login remotely? (Press y|Y for Yes, any other key for No): 输入 Y

Remove test database and access to it? (Press y|Y for Yes, any other key for No): 输入 Y

Reload privilege tables now? (Press y|Y for Yes, any other key for No): 输入 Y

登录 MySQL:

bash 复制代码
mysql -u root -p
相关推荐
传而习乎1 小时前
Linux:CentOS 7 解压 7zip 压缩的文件
linux·运维·centos
soulteary1 小时前
突破内存限制:Mac Mini M2 服务器化实践指南
运维·服务器·redis·macos·arm·pika
爱吃青椒不爱吃西红柿‍️1 小时前
华为ASP与CSP是什么?
服务器·前端·数据库
运维&陈同学2 小时前
【zookeeper01】消息队列与微服务之zookeeper工作原理
运维·分布式·微服务·zookeeper·云原生·架构·消息队列
是阿建吖!2 小时前
【Linux】进程状态
linux·运维
hzyyyyyyyu2 小时前
内网安全隧道搭建-ngrok-frp-nps-sapp
服务器·网络·安全
明明跟你说过3 小时前
Linux中的【tcpdump】:深入介绍与实战使用
linux·运维·测试工具·tcpdump
Mr_Xuhhh4 小时前
重生之我在学环境变量
linux·运维·服务器·前端·chrome·算法
中云DDoS CC防护蔡蔡5 小时前
微信小程序被攻击怎么选择高防产品
服务器·网络安全·微信小程序·小程序·ddos