diff --git a/README.md b/README.md index e6bf38209c8e8cfd2859682b316ca39e1ef6f8e7..a9ca71d0e95daf3756fa0cde064ef14ed48c21f2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ +# magic-api-example +## 简介 +基于maigc-api的示例工程 +https://gitee.com/ssssssss-team/magic-api +## 部署 +[部署文档](./doc/deployment.md) ## mysql 建表语句 ```sql CREATE TABLE `magic_api_file` ( diff --git a/doc/deployment.md b/doc/deployment.md new file mode 100644 index 0000000000000000000000000000000000000000..d8d3aab81629c96db50bd2914ebfd48dc2cfc23a --- /dev/null +++ b/doc/deployment.md @@ -0,0 +1,149 @@ +# magic-api-example部署 + +## linux部署 +### 准备环境 +- jdk 1.8 +- mysql 5.7 + +### 导入数据 +- 创建用户 +```shell script +create user 'magic_api'@'%' identified by 'robot_123456#'; +``` +- 创建数据库库 +mysql 5 +``` +create database magic_api DEFAULT CHARSET utf8mb4 COLLATE 'utf8mb4_general_ci'; +grant all privileges on magic_api.* to "magic_api"@"%" identified by "robot_123456#"; +grant all privileges on magic_api.* to "magic_api"@"localhost" identified by "robot_123456#"; +grant all privileges on magic_api.* to "magic_api"@"127.0.0.01" identified by "robot_123456#"; +flush privileges; +``` +- 导入数据 +登录 +```shell script +mysql -umagic_api -probot_123456# +``` +```sql +use magic_api; +CREATE TABLE `magic_api_file` ( + `file_path` varchar(512) NOT NULL, + `file_content` mediumtext, + PRIMARY KEY (`file_path`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +CREATE TABLE `magic_api_backup` ( + `id` varchar(32) NOT NULL COMMENT '原对象ID', + `create_date` bigint(13) NOT NULL COMMENT '备份时间', + `tag` varchar(32) DEFAULT NULL COMMENT '标签', + `type` varchar(32) DEFAULT NULL COMMENT '类型', + `name` varchar(64) DEFAULT NULL COMMENT '原名称', + `content` mediumtext COMMENT '备份内容', + `create_by` varchar(64) DEFAULT NULL COMMENT '操作人', + PRIMARY KEY (`id`,`create_date`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +``` +### 下载 +https://gitee.com/ppnt/magic-api-example/releases/ +### 安装 +```shell script +tar -xf magic-api-example-2.0.2.tar.gz -C /opt/ +``` +```shell script +# ls +application.properties logs magic-api-demo.jar spring-boot.pid spring-boot.sh +``` +### 启动 +查看配置文件 可以根据需要进行修改 +```shell script +# cat application.properties +spring.application.name=magic-api +server.port=9999 +server.compression.enabled=true +server.compression.min-response-size=128 +spring.jackson.date-format=yyyy-MM-dd HH:mm:ss +spring.jackson.time-zone=GMT+8 +spring.datasource.url=jdbc:mysql://localhost/magic_api?useSSL=false&useUnicode=true&characterEncoding=UTF8&serverTimezone=Asia/Shanghai +spring.datasource.username=magic_api +spring.datasource.password=robot_123456# +magic-api.web=/magic/web +magic-api.resource.type=database +magic-api.resource.table-name=magic_api_file +magic-api.resource.prefix=/magic-api +``` + +```shell script +#启动 +./spring-boot.sh start +#查看日志 +tail -f logs/spring-boot.log +``` +### 配置nginx代理 +```shell script + location / { + proxy_pass http://127.0.0.1:9999; + proxy_http_version 1.1; + proxy_read_timeout 300; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host:$server_port; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Real-PORT $remote_port; + } +``` + +### 访问 +http://192.168.0.6/magic/web/index.html +![](deployment_files/1.jpg) + +### 添加context-path +有些时候nginx之后一个端口开发出来,默认代理业务系统,这个时候可以添加一个context-path,让nginx识别context-path,代理到magic-api +添加context-path=/ppnt-portal/admin +- 修改applicaiton.properties,添加server.servlet.context-path,并重启 +```shell script +server.servlet.context-path=/ppnt-portal/admin +``` + +```shell script +./spring-boot.sh restart +``` +- 修改nginx配置 +```shell script + location /ppnt-portal/admin { + proxy_pass http://127.0.0.1:9999; + proxy_http_version 1.1; + proxy_read_timeout 300; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Real-PORT $remote_port; + } +``` +- 访问 +http://192.168.0.6//ppnt-portal/admin/magic/web/index.html + +### 添加开机启动 +```shell script +vi /lib/systemd/system/magic-api.service +``` +```shell script +[Unit] +Description=magic-api service +After=network.target + +[Service] +Type=forking +PrivateTmp=true +ExecStart=/opt/magic-api/spring-boot.sh start +ExecStop=/opt/magic-api/spring-boot.sh stop +ExecReload=/opt/magic-api/spring-boot.sh restart +[Install] +WantedBy=multi-user.target +``` + +```shell script +systemctl enable magic-api +systemctl start magic-api +systemctl status magic-api +``` \ No newline at end of file diff --git a/doc/deployment_files/1.jpg b/doc/deployment_files/1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..91900b41d1e6b6504823eef9d078345e7a7c8b6d Binary files /dev/null and b/doc/deployment_files/1.jpg differ diff --git a/pom.xml b/pom.xml index 83f55e7aa427b18dd5499480ab29a96d3b462f07..daabd931b5fe15c0271d0df0ee9efc88f42cf7aa 100644 --- a/pom.xml +++ b/pom.xml @@ -2,70 +2,70 @@ - 4.0.0 + 4.0.0 - + + org.springframework.boot + spring-boot-starter-parent + 2.4.5 + + + org.ssssssss + magic-api-example + 2.0.2 + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-jdbc + + + mysql + mysql-connector-java + + + org.ssssssss + magic-api-spring-boot-starter + 2.0.2 + + + org.ssssssss + magic-api-plugin-swagger + 2.0.2 + + + io.springfox + springfox-swagger2 + 2.9.2 + + + io.springfox + springfox-swagger-ui + 2.9.2 + + + com.alibaba + druid + 1.2.1 + + + + + org.springframework.boot - spring-boot-starter-parent - 2.4.5 - - - org.ssssssss - magic-api-example - 2.0.2 - - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-jdbc - - - mysql - mysql-connector-java - - - org.ssssssss - magic-api-spring-boot-starter - 2.0.2 - - - org.ssssssss - magic-api-plugin-swagger - 2.0.2 - - - io.springfox - springfox-swagger2 - 2.9.2 - - - io.springfox - springfox-swagger-ui - 2.9.2 - - - com.alibaba - druid - 1.2.1 - - - - - - org.springframework.boot - spring-boot-maven-plugin - - org.ssssssss.example.MagicAPIExampleApplication - magic-api-demo - - - - + spring-boot-maven-plugin + + org.ssssssss.example.MagicAPIExampleApplication + magic-api-demo + + + + diff --git a/src/main/java/org/ssssssss/example/MagicAPIExampleApplication.java b/src/main/java/org/ssssssss/example/MagicAPIExampleApplication.java index 00dca63cdc8c41d34cbaaedd160a3a6c93848045..cda32ff4682dc6c4e90b7f184d8b0d515111c50e 100644 --- a/src/main/java/org/ssssssss/example/MagicAPIExampleApplication.java +++ b/src/main/java/org/ssssssss/example/MagicAPIExampleApplication.java @@ -6,11 +6,13 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; @SpringBootApplication -@EnableSwagger2 // 配置swagger 文档 +@EnableSwagger2 // 配置swagger 文档 public class MagicAPIExampleApplication { - - public static void main(String[] args) { - SpringApplication.run(MagicAPIExampleApplication.class, args); - } + public static void main(String[] args) { + long start = System.currentTimeMillis(); + SpringApplication.run(MagicAPIExampleApplication.class, args); + long end = System.currentTimeMillis(); + System.out.println((end - start) + "(ms)"); + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 7c9bb2653abd8883e29a54a4f516f7a71bf19767..3bb3a37cf3f086d22f0653985e3f0369dfe3f620 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -10,9 +10,9 @@ spring: date-format: yyyy-MM-dd HH:mm:ss time-zone: GMT+8 datasource: - url: jdbc:mysql://localhost/magic?useSSL=false&useUnicode=true&characterEncoding=UTF8&serverTimezone=Asia/Shanghai - username: root - password: 123456789 + url: jdbc:mysql://localhost/magic_api?useSSL=false&useUnicode=true&characterEncoding=UTF8&serverTimezone=Asia/Shanghai + username: magic_api + password: robot_123456# # data: # 配置mongo数据源 # mongodb: @@ -31,7 +31,7 @@ magic-api: web: /magic/web resource: type: database # 配置接口存储方式,这里选择存在数据库中 - table-name: magic_api_file_v2 # 数据库中的表名 + table-name: magic_api_file # 数据库中的表名 prefix: /magic-api # 前缀 # location: classpath:magic-api # 其它配置请参考 https://ssssssss.org/magic-api/config/