采取的部署方案 阿里云服务器->FinalShell->宝塔面板。 购买服务器,阿里云,腾讯云,华为云等,24周岁以下通过实名认证有优惠补贴,或者搜索试用,可以试用1个月。我这里采取的是阿里云服务器。 通过FinalShell工具,安装宝塔面板,安装成功后,会响应一个面板地址和用户名密码信息。 通过FinalShell响应的外网面板地址,登录宝塔面板。 在宝塔面板新建一个数据库,记住数据库名和账户密码。 将前端项目npm run biuld打包成dist文件。 将后端项目通过maven打jar包。(注意:后端项目在打包前,需要在对应的application文件中修改数据库信息,这里的数据库不是本地的localhost了,是刚刚在宝塔上创建的数据库信息) 将前后端项目上传到宝塔面板。 进入终端,cd到你上传的jar包目录下,启动项目。 二、使用步骤 1.购买服务器https://www.aliyun.com/ 点击进入实例,配置安全组,就是放开你项目中所需要运行的端口 点击添加安全组,配置你所需放行的端口 Windows版下载地址: 宝塔地址: yum install -y wget && wget -O install.sh https://download.bt.cn/install/install_6.0.sh && sh install.sh ed8484bec 这里注意 进入到宝塔面板会让你绑定宝塔的账号,就用手机号注册就行了。 打包前修改原来的启动端口: 把target的指向改为自己宝塔左上角的ip地址+后端端口号 在控制台(当前目录)输入:npm run biuld命令进行打包。生成dist文件 sg-blog-admin: index.js配置如下: export const constantRoutes = [ { path: '/login', component: () => import('@/views/login/index'), hidden: true }, { path: '/', component: Layout, redirect: '/dashboard', children: [{ path: 'dashboard', name: 'Dashboard', component: () => import('@/views/dashboard/index'), meta: { title: '首页', icon: 'dashboard' } }] }, { path: '/write', component: Layout, children: [{ path: '/', name: 'Write', component: () => import('@/views/content/article/write/index'), hidden: true }] }, { path: '/system/user', component: Layout, children: [{ path: '/', name: 'User', component: () => import('@/views/system/user'), hidden: true }] }, { path: '/system/role', component: Layout, children: [{ path: '/', name: 'role', component: () => import('@/views/system/role'), hidden: true }] }, { path: '/system/menu', component: Layout, children: [{ path: '/', name: 'menu', component: () => import('@/views/system/menu'), hidden: true }] }, { path: '/system/role', component: Layout, children: [{ path: '/', name: 'role', component: () => import('@/views/system/role'), hidden: true }] }, { path: '/content/article', component: Layout, children: [{ path: '/', name: 'article', component: () => import('@/views/content/article/index'), hidden: true }] }, { path: '/content/category', component: Layout, children: [{ path: '/', name: 'category', component: () => import('@/views/content/category/index'), hidden: true }] }, { path: '/content/link', component: Layout, children: [{ path: '/', name: 'link', component: () => import('@/views/content/link/index'), hidden: true }] }, { path: '/content/tag', component: Layout, children: [{ path: '/', name: 'tag', component: () => import('@/views/content/tag/index'), hidden: true }] } ] 这里退出登录的路由会跳转到index, 如果出现打包错误: 注释掉以下内容: 这里如果代码打包出现问题,可以去我主页看看我总结的解决方案: admin和blog子模块添加biuld: <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.6.2</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> <finalName>${project.artifactId}</finalName> </build>刷新maven后,将前端sg-blog-vue和sg-blog-admin生成的dist文件,新建一个static包,然后复制到src\main\resources\static目录下,将前后端项目整合打包,实现一个伪前后端分离,便于宝塔直接部署。 在打包之前,配置一下两个模块中application的数据库文件,换成自己的ip地址,并且这里的username和password要和宝塔上创建的数据库一致,不然连接不了数据库。 然后进行打包 在指定的目录下创建两个文件夹,用来存放刚才的两个jar包 上传目标jar包 如果启动发现端口被占用了, 输入netstat -lnp命令查看端口信息, 使用sudo kill xxx进行删除 前台: 后台: 并且宝塔退出后网站也不会挂掉。 总结部署结束,感谢B站三更和C站的博主为我的项目提供了莫大的帮助,部署过程中出现困难或者文章有纰漏欢迎留言讨论。 参考文章👍: |