专业的编程技术博客社区

网站首页 > 博客文章 正文

centos7部署rap2(centos7部署网站)

baijin 2024-08-22 09:17:57 博客文章 2 ℃ 0 评论

@[toc]

centos7部署rap2

rap2-delos: 后端数据API服务器,基于Koa + MySQLlink

rap2-dolores: 前端静态资源,基于React link

rap2-delos 后端API服务器

安装 redis

安装 mysql

创建数据库

CREATE DATABASE IF NOT EXISTS RAP2_DELOS_APP DEFAULT CHARSET utf8 COLLATE utf8_general_ci

下载源码

初始化,在项目根目录下

npm install

修改配置文件,数据库 和 redis 的配置

/config/config.dev.js
 pool: {
import { IConfigOptions } from "../types";

let config: IConfigOptions = {
 version: '2.3',
 serve: {
 port: 8090,
 },
 keys: ['some secret hurr'],
 session: {
 key: 'rap2:sess',
 },
 db: {
 dialect: 'mysql',
 host: '127.0.0.1',
 port: 3306,
 username: 'root',
 password: '123456',
 database: 'RAP2_DELOS_APP',
 pool: {
 max: 5,
 min: 0,
 idle: 10000,
 },
 logging: false,
 },
 redis: {
 host:'localhost',
 port:6379,
 auth_pass:'123456',
 },
 mail: {
 host: 'smtp-mail.outlook.com',
 port: 587,
 secure: false,
 auth: {
 user: 'rap2_notify@outlook.com',
 pass: ''
 }
 },
 mailSender: 'rap2_notify@outlook.com',
}
export default config

安装 && TypeScript编译,根目录下

npm install -g typescript
npm run build

初始化数据库表,根目录下

npm run create-db

启动开发模式的服务器 监视并在发生代码变更时自动重启

npm run dev

在服务器上,使用 pm2

npm install -g pm2

用他替代:npm run dev,就可以写成:pm2 start npm -- run dev,项目启动

$ pm2 start npm -- run dev

>>>> In-memory PM2 is out-of-date, do:
>>>> $ pm2 update
In memory PM2 version: 2.10.4
Local PM2 version: 3.2.3

[PM2] Starting /usr/bin/npm in fork_mode (1 instance)
[PM2] Done.
┌──────────────────┬────┬─────────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬─────────┬──────────┐
│ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├──────────────────┼────┼─────────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼─────────┼──────────┤
│ npm │ 1 │ N/A │ fork │ 18468 │ online │ 0 │ 0s │ 0% │ 6.8 MB │ hcadmin │ disabled │
│ rap-server-delos │ 0 │ N/A │ fork │ 30697 │ online │ 0 │ 21m │ 0% │ 26.1 MB │ hcadmin │ disabled │
└──────────────────┴────┴─────────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴─────────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app

验证是否安装成功,访问刚才配置的端口号 http://127.0.0.1:8090/ 返回如下信息,则表示安装成功

RAP2后端服务已启动,请从前端服务(rap2-dolores)访问。 RAP2 back-end server is started, please visit via front-end service (rap2-dolores). 

rap2-dolores 前端静态资源

可以先在本地打包好,再上传到服务器

下载地址

development 开发模式

初始化

npm install
# config development mode server API path in /src/config/config.dev.js
# 配置开发模式后端服务器的地址。 /src/config/config.dev.js

# test cases 测试用例
npm run test

# will watch & serve automatically 会自动监视改变后重新编译
npm run dev

production

# 1. config server API path in /src/config/config.prod.js(production config file)
# 1. 配置后端服务器的地址。 /src/config/config.prod.js(生产模式配置文件)

# 2. produce react production package
# 2. 编译React生产包
npm run build

# 3. use serve or nginx to serve the static build directory
# 3. 用serve命令或nginx服务器路由到编译产出的build文件夹作为静态服务器即可

npm install -g serve

serve -s ./build -p 80

部署到 tomcat

  • 将 build 下的内容复制到 webapp/ROOT 下
  • 启动即可

可能会报404错误,在退出时,找不到路径,修改 tomcat web.xml 如下

 <welcome-file-list>
 <welcome-file>index.html</welcome-file>
 <welcome-file>index.htm</welcome-file>
 <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>

 <error-page>
 <error-code>404</error-code>
 <location>/index.html</location>
 </error-page>

重启 tomcat 可正常使用

用户密码加密规则

md5(md5($pass))

参考链接

PM2来部署nodejs服务器永久开启

Vue项目webpack打包部署到Tomcat

通过create-react-app创建的react项目,build以后,在tomcat中部署配置

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表