-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
# 云服务器部署步骤 | ||
|
||
todo: 图片还没上传。。 | ||
|
||
## Frontend | ||
|
||
以阿里云ECS为例,通过NodeSource提供的官方包安装,自带最新npm | ||
|
||
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - &&\ | ||
sudo apt-get install -y nodejs | ||
|
||
npm run build打包 | ||
|
||
```sh | ||
cd cloudmall-vue3 | ||
npm i | ||
npm run dev | ||
``` | ||
|
||
## 部署后端环境 | ||
|
||
### 打包上传后端代码 | ||
|
||
IDEA打开项目工程,在application-dev.yml文件中修改datasource和redis的主机和端口,如下图 | ||
|
||
然后打开右边的maven,点击跳过测试,然后执行package | ||
|
||
接着在你的本地就会生成一个jar包,一般在该目录的target目录下,参考下图 | ||
|
||
在cloudmall目录上传刚才我们打包好的jar包 | ||
|
||
### 配置Redis | ||
|
||
拉取Redis镜像,默认最新版 | ||
|
||
```sh | ||
docker pull redis | ||
``` | ||
|
||
在cloudmall目录下创建redis目录,进入redis目录,在该目录下创建redis.conf文件 | ||
|
||
编辑redis.conf文件为如下内容 | ||
|
||
```c | ||
#持久化存储 | ||
appendonly yes | ||
#设置redis密码 | ||
requirepass 123456 | ||
``` | ||
|
||
创建redis容器,因为redis需要修改配置文件,我们采用外部挂载的方式会方便很多 | ||
|
||
```sh | ||
docker run -v /home/wi1sonh/cloudmall/redis/redis.conf:/etc/redis/redis.conf \ | ||
-v /home/wi1sonh/cloudmall/redis/data:/home/wi1sonh/cloudmall \ | ||
-d --name myredis \ | ||
-p 6380:6379 \ | ||
redis:latest redis-server /etc/redis/redis.conf | ||
``` | ||
|
||
连接测试 | ||
|
||
```sh | ||
docker exec -it myredis redis-cli -a 123456 | ||
ping | ||
``` | ||
|
||
### 配置MySQL | ||
|
||
拉取MySQL镜像,默认为最新版 | ||
|
||
```sh | ||
docker pull mysql | ||
``` | ||
|
||
创建mysql容器,这里的镜像id需要使用`docker images`命令查看自己对应的mysql镜像id,和之前使用过的操作一样 | ||
|
||
```sh | ||
docker run -id --name=mysql -p 3305:3306 -e MYSQL_ROOT_PASSWORD=123456 <镜像id> | ||
``` | ||
|
||
建表 | ||
|
||
```sh | ||
docker cp /home/wi1sonh/cloudmall/cloudmall_database.sql <容器id>:/ | ||
``` | ||
|
||
连接测试 | ||
|
||
```sh | ||
docker exec -it mysql bash | ||
mysql -uroot -p | ||
show databases; | ||
source /cloudmall_database.sql; | ||
show tables; | ||
exit | ||
exit | ||
``` | ||
|
||
### 部署后端代码 | ||
|
||
在项目jar文件所在目录下编写 DockerFile 文件 | ||
|
||
```c | ||
#拉取jdk22版本的镜像 | ||
FROM openjdk:22-jdk-slim | ||
#作者自己自定义 | ||
LABEL maintainer=wilson | ||
|
||
COPY *.jar /app.jar | ||
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime | ||
RUN echo 'Asia/Shanghai' > /etc/timezone | ||
ENTRYPOINT ["java","-jar","/app.jar"] | ||
``` | ||
|
||
构建docker镜像,后面的 `.` 不要误删,代表在该目录工作: | ||
|
||
`docker build -t java-cloudmall:v1.0 -f DockerFile .` | ||
|
||
建立java容器(最好先检查容器是否全部启动,指令是docker ps) | ||
|
||
`docker run -d -p 8081:8081 --name cloudmall java-cloudmall:v1.0 -v /etc/timezone:/etc/timezone -v /etc/localtime:/etc/localtime` | ||
|
||
|
||
|
||
域名DNS解析 | ||
|
||
nginx 反向代理 | ||
|
||
`sudo apt install nginx` | ||
|
||
`sudo vim /etc/nginx/nginx.conf` | ||
|
||
```c | ||
server { | ||
listen 80; | ||
server_name cloud-mall.hwyl.run; | ||
|
||
location / { | ||
root html; | ||
index index.html index.htm; | ||
proxy_pass http://47.121.122.236:5173; | ||
} | ||
|
||
error_page 500 502 503 504 /50x.html; | ||
location = /50x.html { | ||
root html; | ||
} | ||
} | ||
``` | ||
|
||
测试 `nginx -t` | ||
|
||
重启 `nginx -s reload` | ||
|
||
修改系统时间 | ||
|
||
`ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime` | ||
|
||
`/usr/share/zoneinfo/tzselect` | ||
|
||
`echo "Asia/Shanghai" > /etc/timezone` | ||
|
||
查看时间 | ||
|
||
`date` | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.