基于 Vue+Spring Cloud 前后端服务的云部署
Published in:2023-04-20 |
Words: 809 | Reading time: 4min | reading:

基于 Vue+Spring Cloud 前后端服务的云部署

系统环境

  • 基础环境
1
2
3
4
5
centos 8 # 操作系统
JDK 1.8 # java
yum -y install java
git
yum install git

前端打包

  • 1.打包指令
1
npm run build
  • 2.文件上传

  • 使用 FTP 工具上传dist文件

后端打包

  • 1.Maven 打包
1
mvn clean package #or mvn install 只需在父服务中运行
  • 2.jar 包上传

  • 使用 FTP 上传 jar 包

  • 3.jar 包运行

1
nohub java -jar rs_shop_service.jar & 1 &out.log

云服务器部署

  • 1.基础镜像配置

  • 镜像源设置

1
2
3
4
5
6
7
mkdir /etc/yum.repos.d.bak
mv /etc/yum.repos.d/* /etc/yum.repos.d.bak/
ll /etc/yum.repos.d/
ll /etc/yum.repos.d.bak/
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
sed -i 's/releasever\//releasever-stream\//g' /etc/yum.repos.d/CentOS-Base.repo
  • 缓存清除与元数据重建
1
2
yum clean all
yum makecache
  • 2.Docker 安装与使用

  • 更新 yum 源

1
yum -y update
  • 安装
1
2
3
4
5
6
7
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce
systemctl start docker
systemctl enable docker
  • 3.基础镜像安装与使用

  • mysql

1
2
3
4
docker pull mysql # 镜像拉取
docker images # 查看镜像
docker run --name testmysql -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=smx0920 mysqlimagesname #运行
docker ps -a
  • redis
1
2
3
4
docker pull redis
docker images
docker run -p 6379:6379 -v $PWD/data:/data  -d redis redis-server --appendonly yes
docker ps -a
  • nginx
1
2
3
4
5
6
7
8
docker pull nginx
docker images
mkdir -p /data/nginx/conf
mkdir -p /data/nginx/conf.d
mkdir -p /data/nginx/html
mkdir -p /data/nginx/logs
docker run --name mynginx -d -p 80:80 -v /data/nginx/html:/usr/share/nginx/html -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf -v /data/nginx/logs:/var/log/nginx nginx
docker ps -a
  • 4.基础镜像配置

  • mysql

mysql需做如下配置

1
2
3
4
5
6
7
8
9
10
11
12
13
docker exec -it mysql bash
mysql -u root -p
# 输入密码回车
```
`对数据库做如下配置`
```sql
alter user 'root'@'%' identified with mysql_native_password by 'smx0920';
flush privileges;
```
```sh
exit
docker restart mysql
docker ps -a
  • redis
    运行完后做如下测试:
1
curl -L 127.0.0.1:6379
  • nginx

nginx.conf 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/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 /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;
}

default.conf 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
server {
listen 6666;
server_name localhost;

#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;

location / {
root /usr/share/nginx/html;
index 1.html;
}

#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 /usr/share/nginx/html;
}

location /api/ {
proxy_pass http://localhost:10000/shop #端口代理转发
}
# 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;
#}
}
  • 配置完成后,重启容器
1
docker restart containerid
  • 或者进入容器重启 nginx 服务
1
2
3
docker exec -it nginx  bash
nginx -s reload
nginx -t
  • 5.服务搭建与测试

最终测试

  • 1.前端页面测试
1
curl -L http://localhost:6666
  • 2.后端接口测试
1
curl -L http://localhost:10000/api/shop/test

上述有结果反馈,即为部署成功!

Prev:
Android常用脚本
Next:
Electron Egg 框架研究