线上部署面试蛙
线上部署面试蛙
1.核心部署
一 本地准备
- 修改代码:去掉es、sentinel、hotkey第三方代码,保证核心代码能够线上运行
- 修改 application-prod.yml ,主要配置线上mysql、redis信息
- maven打包
- 上传jar包到宝塔
二 宝塔部署-后端
- 添加项目启动命令:(等待半分钟后刷新页面查看是否显示端口)
--server.port=8102 --spring.profiles.active=prod
- nginx 转发:
- 在php项目新建,域名是公网ip,目录是mianshiwa
- php版本必须是80
- 其他默认
- php项目创建后,在其nginx添加配置:(用于访问api路径打头)
location /api { proxy_pass http://127.0.0.1:8102; proxy_set_header Host $proxy_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_buffering off; proxy_set_header Connection ""; }
- 将nginx默认静态配置注释:
# location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ # { # expires 30d; # error_log /dev/null; # access_log /dev/null; # } # location ~ .*\.(js|css)?$ # { # expires 12h; # error_log /dev/null; # access_log /dev/null; # }
- 测试nginx转发是否成功,如果成功,则能访问后端swagger界面:
三 宝塔部署-前端
- 修改前端代码:request.js
// 创建 Axios 示例 // 区分开发和生产环境 const DEV_BASE_URL = "http://localhost:8102"; const PROD_BASE_URL = "http://线上ip"; const myAxios = axios.create({ baseURL: PROD_BASE_URL, timeout: 10000, withCredentials: true,// cookie 自动携带 });
- 修改next.config.mjs,next单机部署
/** @type {import('next').NextConfig} */ const nextConfig = { output: "standalone", }; export default nextConfig;
- build 前端项目,生成
注意:如果有报错,可以直接一键忽略:在next.config.mjs添加以下内容
/** @type {import('next').NextConfig} */ const nextConfig = { output: "standalone", typescript: { // !! WARN !! // Dangerously allow production builds to successfully complete even if // your project has type errors. // !! WARN !! ignoreBuildErrors: true, }, }; export default nextConfig;
- build成功效果:(有个小bug,○代表静态内容,如果管理员修改题库图片,并不会修改首页的图片显示)
Route (app) Size First Load JS ┌ ○ / 6.22 kB 277 kB ├ ○ /_not-found 883 B 88.6 kB ├ ○ /admin/bank 3.13 kB 681 kB ├ ○ /admin/question 4.13 kB 874 kB ├ ○ /admin/user 2.57 kB 681 kB ├ ƒ /bank/[questionBankId] 664 B 279 kB ├ ƒ /bank/[questionBankId]/question/[questionId] 4.47 kB 456 kB ├ ○ /banks 2.42 kB 270 kB ├ ƒ /question/[questionId] 1.44 kB 437 kB ├ ƒ /questions 3.69 kB 674 kB ├ ○ /user/center 338 kB 588 kB ├ ○ /user/login 1.78 kB 513 kB └ ○ /user/register 1.52 kB 504 kB + First Load JS shared by all 87.7 kB ├ chunks/7023-357c18e1abddc78a.js 31.7 kB ├ chunks/fd9d1056-6091cd8ebb63e356.js 53.7 kB └ other shared chunks (total) 2.36 kB ○ (Static) prerendered as static content ƒ (Dynamic) server-rendered on demand
- 修第一个bug:
// 强制主页动态渲染 export const dynamic = 'force-dynamic';
- 修改打包后的文件位置
- 在 .next 目录下会生成 standalone 目录,该目录就是可以独立部署的前端包。但是必须按照如下模式组织目录,一定不能有错!
- 将项目根目录下的 public 目录移动到 .next/standalone 内
- 将 .next/static 目录移动到 .next/standalone/.next 内
- 将standalone里的文件都压缩并复制到宝塔
- 上传到服务器后,添加 Node 项目。注意修改启动选项(start 或者自定义命令
node server.js
)和项目端口(3000) - 修改 Nginx 配置,访问前端资源时,反向代理到 Node.js 服务:
location / { proxy_pass http://127.0.0.1:3000; proxy_set_header Host $proxy_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_buffering off; proxy_set_header Connection ""; }
- 测试:http://线上ip
至此,已经部署好一个基础的核心面试蛙项目,但是还未集成es分词检索、sentinel流量控制、hotkey热点检测
2.es部署
代码接口:题目搜索接口、ES 定时同步任务
修改代码
安装es
开放端口
测试es
后台运行:
nohup ./bin/elasticsearch > elasticsearch.log 2>&1 &
安装kibana
安装ik 分词器:
bin/elasticsearch-plugin install https://get.infini.cloud/elasticsearch/analysis-ik/7.17.24
重启es
测试ik
bug:打开题目详情页的任意一道题都需要登陆
4
3.sentinel部署
4.hotKey部署
比任何人都要努力
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)