From 115ed7e6c559128da47b2016d41c656235205bf5 Mon Sep 17 00:00:00 2001 From: lijiahangmax Date: Sun, 25 Feb 2024 00:18:08 +0800 Subject: [PATCH] =?UTF-8?q?:whale:=20=E6=B7=BB=E5=8A=A0=20docker=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 53 +++++++++++++++++++ docker/.gitkeep | 0 docker/mysql/Dockerfile | 9 ++++ docker/mysql/my.cnf | 25 +++++++++ docker/orion-ops-pro/Dockerfile | 10 ++++ docker/orion-ops-pro/entrypoint.sh | 4 ++ docker/orion-ops-pro/nginx.conf | 53 +++++++++++++++++++ .../src/main/resources/application-prod.yaml | 14 ++--- 8 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 docker-compose.yml delete mode 100644 docker/.gitkeep create mode 100644 docker/mysql/Dockerfile create mode 100644 docker/mysql/my.cnf create mode 100644 docker/orion-ops-pro/Dockerfile create mode 100644 docker/orion-ops-pro/entrypoint.sh create mode 100644 docker/orion-ops-pro/nginx.conf diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..3df218e4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,53 @@ +version: '3.3' +services: + orion-ops-pro: + build: + context: . + dockerfile: docker/orion-ops-pro/Dockerfile + image: orion-ops-pro:1.0.0 + ports: + - 1081:80 + environment: + - REDIS_HOST=orion-ops-pro-redis + - MYSQL_HOST=orion-ops-pro-db + - MYSQL_USER=orion + - MYSQL_PASSWORD=Data@123456 + - SECRET_KEY=secret-key + volumes: + - /data/orion-ops-pro-space/docker-volumes/orion-ops-pro/logs:/root/orion/logs/orion-ops-pro + depends_on: + - orion-ops-pro-db + - orion-ops-pro-redis + orion-ops-pro-db: + build: + context: . + dockerfile: docker/mysql/Dockerfile + privileged: true + ports: + - 3307:3306 + environment: + - MYSQL_DATABASE=orion-ops-pro + - MYSQL_USER=orion + - MYSQL_PASSWORD=Data@123456 + - MYSQL_ROOT_PASSWORD=Data@123456 + volumes: + - /data/orion-ops-pro-space/docker-volumes/mysql/var-lib-mysql:/var/lib/mysql + - /data/orion-ops-pro-space/docker-volumes/mysql/var-lib-mysql-files:/var/lib/mysql-files + - /data/orion-ops-pro-space/docker-volumes/mysql/etc-mysql:/etc/mysql + image: orion-ops-pro-db:8.0 + orion-adminer: + image: adminer + restart: always + ports: + - 8081:8080 + orion-ops-pro-redis: + image: redis:6.0.16-alpine + command: redis-server --requirepass Data@123456 + ports: + - 6380:6379 + volumes: + - /data/orion-ops-pro-space/docker-volumes/redis/var-lib-mysql:/etc/redis + - /data/orion-ops-pro-space/docker-volumes/redis/data:/data + + +: \ No newline at end of file diff --git a/docker/.gitkeep b/docker/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/docker/mysql/Dockerfile b/docker/mysql/Dockerfile new file mode 100644 index 00000000..c67b3ecd --- /dev/null +++ b/docker/mysql/Dockerfile @@ -0,0 +1,9 @@ +FROM mysql:8.0.28 +COPY sql/init-1-schema-databases.sql /tmp +COPY sql/init-2-schema-tables.sql /tmp +COPY sql/init-3-data.sql /tmp +COPY docker/mysql/my.cnf /etc/mysql/conf.d/my.cnf +RUN cat /tmp/init-1-schema-databases.sql >> /tmp/init.sql && \ + cat /tmp/init-2-schema-tables.sql >> /tmp/init.sql && \ + cat /tmp/init-3-data.sql >> /tmp/init.sql && \ + cp /tmp/init.sql /docker-entrypoint-initdb.d diff --git a/docker/mysql/my.cnf b/docker/mysql/my.cnf new file mode 100644 index 00000000..f048ec51 --- /dev/null +++ b/docker/mysql/my.cnf @@ -0,0 +1,25 @@ +[client] +# 客户端默认字符集 +default_character_set=utf8mb4 +[mysql] +# 默认字符集 +default_character_set=utf8mb4 +[mysqld] +# pid文件 +pid-file=/var/run/mysqld/mysqld.pid +# sock文件 +socket=/var/run/mysqld/mysqld.sock +# 数据目录 +datadir=/var/lib/mysql +# 不区分大小 0区分 1不区分 +lower_case_table_names=1 +# 服务器时区 +default-time_zone='+8:00' +# 服务端字符集 +character_set_server=utf8mb4 +# 字符排序规则 +collation_server=utf8mb4_general_ci +# 默认存储引擎 +default-storage-engine=InnoDB +# 禁止 DNS 解析 +skip-name-resolve diff --git a/docker/orion-ops-pro/Dockerfile b/docker/orion-ops-pro/Dockerfile new file mode 100644 index 00000000..e007f33f --- /dev/null +++ b/docker/orion-ops-pro/Dockerfile @@ -0,0 +1,10 @@ +FROM nginx:alpine +USER root +RUN apk add openjdk8 +RUN rm -rf /etc/nginx/conf.d/* +WORKDIR /app +COPY orion-ops-launch/target/orion-ops-launch.jar /app/app.jar +COPY orion-ops-ui/dist /usr/share/nginx/html +ADD docker/orion-ops-pro/entrypoint.sh /app/entrypoint.sh +ADD docker/orion-ops-pro/nginx.conf /etc/nginx/conf.d +ENTRYPOINT [ "sh", "/app/entrypoint.sh" ] diff --git a/docker/orion-ops-pro/entrypoint.sh b/docker/orion-ops-pro/entrypoint.sh new file mode 100644 index 00000000..9c4c1f3f --- /dev/null +++ b/docker/orion-ops-pro/entrypoint.sh @@ -0,0 +1,4 @@ +#!/bin/bash +nginx +cd /app +java -jar app.jar --spring.profiles.active=prod diff --git a/docker/orion-ops-pro/nginx.conf b/docker/orion-ops-pro/nginx.conf new file mode 100644 index 00000000..9542e7ea --- /dev/null +++ b/docker/orion-ops-pro/nginx.conf @@ -0,0 +1,53 @@ +server { + listen 80; + server_name localhost; + + # 是否启动 gzip 压缩 + gzip on; + # 需要压缩的常见静态资源 + gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; + # 如果文件大于 1k 就启动压缩 + gzip_min_length 1k; + # 缓冲区 + gzip_buffers 4 16k; + # 压缩的等级 + gzip_comp_level 2; + # access_log /var/log/nginx/host.access.log main; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /orion/api { + proxy_pass http://localhost:9200/orion/api; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /orion/keep-alive { + proxy_pass http://localhost:9200/orion/keep-alive; + proxy_http_version 1.1; + 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-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + +} + diff --git a/orion-ops-launch/src/main/resources/application-prod.yaml b/orion-ops-launch/src/main/resources/application-prod.yaml index cd8514ba..d9815c47 100644 --- a/orion-ops-launch/src/main/resources/application-prod.yaml +++ b/orion-ops-launch/src/main/resources/application-prod.yaml @@ -1,9 +1,9 @@ spring: datasource: druid: - url: jdbc:mysql://127.0.0.1:3306/orion-ops-pro?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true - username: root - password: Data@123456 + url: jdbc:mysql://${MYSQL_HOST:127.0.0.1}:3306/orion-ops-pro?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true + username: ${MYSQL_USER:root} + password: ${MYSQL_PASSWORD:Data@123456} # 初始连接数 initial-size: 5 # 最小连接池数量 @@ -18,10 +18,10 @@ spring: stat: enabled: true redis: - host: 127.0.0.1 - port: 6379 + host: ${REDIS_HOST:127.0.0.1} + port: ${REDIS_PORT:6379} database: 0 - password: lijiahang + password: ${REDIS_PASSWORD:Data@123456} timeout: 3000 springdoc: @@ -40,7 +40,7 @@ orion: crypto: aes: # 加密秘钥 - secret-key: uQeacXV8b3isvKLK + secret-key: ${SECRET_KEY:uQeacXV8b3isvKLK} async: executor: core-pool-size: 8