From 643982446856ddcb9ab163473f14ed74d04375c6 Mon Sep 17 00:00:00 2001 From: isummer Date: Sun, 21 Aug 2022 16:26:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96docker=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + README.md | 34 ++++++ build.sh | 12 -- build_client.sh | 7 -- docker.md | 59 ++++++---- docker/build/docker-compose.yml | 67 +++++++++++ docker/flyapps/docker-compose.yml | 45 ++++++++ docker/init/clean.sh | 9 ++ docker/init/init.sh | 27 +++++ docker/init/timezone | 1 + docker/mariadb/docker-compose.yml | 43 +++++++ docker/mariadb/server.cnf | 108 ++++++++++++++++++ docker/redis/docker-compose.yml | 25 ++++ docker/scripts/build.sh | 13 +++ docker/scripts/start_all.sh | 9 ++ docker/scripts/stop_all.sh | 10 ++ fir_admin/.env.production | 2 +- fir_client/package.json | 1 - fir_client/src/components/FirLogin.vue | 3 +- .../src/components/user/FirSuperSignBase.vue | 4 +- fir_client/src/restful/download.js | 20 ++-- fir_client/src/restful/index.js | 72 ++++++------ fir_client/src/utils/index.js | 2 +- fir_client/vue.config.js | 47 +++++--- .../management/commands/services/command.py | 2 +- fir_ser/config.py | 5 +- nginx.conf.d/flyapps-vhost.conf | 4 +- start.sh | 41 ------- 28 files changed, 519 insertions(+), 155 deletions(-) delete mode 100644 build.sh delete mode 100644 build_client.sh create mode 100644 docker/build/docker-compose.yml create mode 100644 docker/flyapps/docker-compose.yml create mode 100644 docker/init/clean.sh create mode 100644 docker/init/init.sh create mode 100644 docker/init/timezone create mode 100644 docker/mariadb/docker-compose.yml create mode 100644 docker/mariadb/server.cnf create mode 100644 docker/redis/docker-compose.yml create mode 100644 docker/scripts/build.sh create mode 100644 docker/scripts/start_all.sh create mode 100644 docker/scripts/stop_all.sh delete mode 100644 start.sh diff --git a/.gitignore b/.gitignore index d560af3..a0aaa73 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ fir_client/src/assets/down_right.png mailhtml/build/ mailhtml/node_modules/ mailhtml/.idea/ +fir_client/dist_index/ +fir_client/dist_short/ diff --git a/README.md b/README.md index b55f4f5..3db37b5 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,40 @@ - 需要阿里云OSS存储和阿里云CDN,并且OSS存储和阿里云服务器部署同一个地区 - 可以申请一个极验进行滑动验证,或者开启验证码验证 - 阿里云备案域名:api和前端可以使用一个域名,下载页单独域名 + +#### 部署必备资料 +- 域名证书 + - web域名和证书 + - api域名和证书 + - 下载页域名(可配置证书) + - 存储域名和证书 + - 本地存储,则该域名和证书可以和api域名证书一致 + - 阿里云oss存储 + - 开启cdn,需要新域名和证书 + - 不开启,无需域名和证书 +- Centos8Stream 服务器 + +#### 修改配置文件 +##### fir_ser配置文件 config.py +```python +class DOMAINCONF(object): + API_DOMAIN = "https://app.hehelucky.cn" # 用与开启本地存储,上传应用配置 + WEB_DOMAIN = "https://app.hehelucky.cn" # 用于超级签跳转配置,该域名一般为前端页面域名 + MOBILEPROVISION = "https://static.hehejoy.cn/embedded3.mobileprovision" # 用于苹果包企业签信任企业跳转 + +``` + +##### fir_client配置文件 vue.confjg.js +```javascript +const pro_base_env = { + baseUrl: '/', //该选项可以填写web-api的域名,类似 https://api.xxx.com/ + index_static: '/', //若配置cdn等加速,可以填写cdn加速域名 + baseShortUrl: '/', //该选项可以填写short-api的域名,也可以和web-api域名一样,类似 https://api.xxx.com/ + short_static: '/short/', //若配置cdn等加速,可以填写cdn加速域名 + version: version, +}; +``` + ##### 从git上面下载源码 ```shell cd /data/ diff --git a/build.sh b/build.sh deleted file mode 100644 index 33e6455..0000000 --- a/build.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# -# -# shellcheck disable=SC2006 -s_path=`pwd` - -#first build fir_client -docker pull node:14.17.3 -\cp -a build_client.sh fir_client/ -docker run --rm --privileged=true -v "${s_path}"/fir_client:/fir_client -it node:14.17.3 sh /fir_client/build_client.sh - -cd "${s_path}"/fir_ser/ && docker build . -t flyapps diff --git a/build_client.sh b/build_client.sh deleted file mode 100644 index 2a0217f..0000000 --- a/build_client.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# -# - -cd /fir_client/ && yarn config set registry https://registry.npm.taobao.org && yarn install && yarn build - - diff --git a/docker.md b/docker.md index fca7053..84b1635 100644 --- a/docker.md +++ b/docker.md @@ -4,48 +4,65 @@ cd /data/ git clone https://github.com/nineaiyu/FlyApps ``` -#### docker环境安装 [centos7] +#### docker环境安装 [centos8] ``` -yum install epel-release -y -yum clean all && yum makecache -yum install docker -y - +cd /data/FlyApps/docker/init +sh init.sh ``` +#### 域名证书准备 +- 域名: app.hehelucky.cn +- 证书(nginx) + - app.hehelucky.cn.key + - app.hehelucky.cn.pem + #### 配置域名和证书,如果有cdn或者oss,也要进行配置 ```shell script nginx.conf.d/app.hehelucky.cn.key nginx.conf.d/app.hehelucky.cn.pem nginx.conf.d/flyapps-vhost.conf ``` -### api服务需要修改api和web域名,短信,邮箱,geetest,存储等信息 -```shell script -vim fir_ser/config.py - -API_DOMAIN = "https://app.hehelucky.cn" -WEB_DOMAIN = "https://app.hehelucky.cn" -MOBILEPROVISION = "https://ali-static.jappstore.com/embedded.mobileprovision" +#### api服务需要修改api和web域名,短信,邮箱,geetest,存储等信息 +##### fir_ser配置文件 config.py +```python +class DOMAINCONF(object): + API_DOMAIN = "https://app.hehelucky.cn" # 用与开启本地存储,上传应用配置 + WEB_DOMAIN = "https://app.hehelucky.cn" # 用于超级签跳转配置,该域名一般为前端页面域名 ``` -### web页面需要修改指定api域名 -```vuejs -vim fir_client/vue.config.js +##### fir_client配置文件 vue.confjg.js +```javascript const pro_base_env = { - baseUrl: 'https://flyapps.cn', - index_static: 'https://static.flyapps.cn/index/', - baseShortUrl: 'https://flyapps.top', - short_static: 'https://static.flyapps.top/short/', + baseUrl: '/', //该选项可以填写web-api的域名,类似 https://api.xxx.com/ + index_static: '/', //若配置cdn等加速,可以填写cdn加速域名 + baseShortUrl: '/', //该选项可以填写short-api的域名,也可以和web-api域名一样,类似 https://api.xxx.com/ + short_static: '/short/', //若配置cdn等加速,可以填写cdn加速域名 + version: version, }; ``` ##### 构建静态资源和api服务 ``` +cd /data/FlyApps/docker/scripts sh build.sh ``` - ##### 启动所有服务 ``` -sh start.sh +cd /data/FlyApps/docker/scripts +sh start_all.sh +``` + +##### 关闭所有服务 +``` +cd /data/FlyApps/docker/scripts +sh stop_all.sh +``` + +##### 根据提示创建默认管理用户 +```shell +docker exec -it flyapps python manage.py createsuperuser ``` +##### 测试访问 +在浏览器输入自己配置的域名 https://app.hehelucky.cn/ 进行访问 \ No newline at end of file diff --git a/docker/build/docker-compose.yml b/docker/build/docker-compose.yml new file mode 100644 index 0000000..9cd1d0e --- /dev/null +++ b/docker/build/docker-compose.yml @@ -0,0 +1,67 @@ +version: '3.2' + +services: + buildflyapps: + image: 'flyapps' + build: + context: ../../fir_ser + dockerfile: Dockerfile + command: + - echo + - success + + buildclient: + container_name: buildclient + image: 'node:14.17.3' + working_dir: /fir_client + volumes: + - /etc/localtime:/etc/localtime:ro + - ../../fir_client:/fir_client + - ../../data/web/:/web + command: + - bash + - -c + - yarn config set registry https://registry.npm.taobao.org && yarn install && yarn build index && yarn build short && ([ ! -e /web/fir_client ] && \cp -a dist_index /web/fir_client || \cp -a dist_index/* /web/fir_client/) && ([ ! -e /web/fir_client/short ] && \cp -a dist_short /web/fir_client/short || \cp -a dist_short/* /web/fir_client/short/) && echo build success + + buildindex: + container_name: buildindex + image: 'node:14.17.3' + working_dir: /fir_client + volumes: + - /etc/localtime:/etc/localtime:ro + - ../../fir_client:/fir_client + - ../../data/web/:/web + command: + - bash + - -c + - yarn config set registry https://registry.npm.taobao.org && yarn install && yarn build index && ([ ! -e /web/fir_client ] && \cp -a dist_index /web/fir_client || \cp -a dist_index/* /web/fir_client/) && echo build success + + + + buildshort: + container_name: buildshort + image: 'node:14.17.3' + working_dir: /fir_client + volumes: + - /etc/localtime:/etc/localtime:ro + - ../../fir_client:/fir_client + - ../../data/web/:/web + command: + - sh + - -c + - yarn config set registry https://registry.npm.taobao.org && yarn install && yarn build short && ([ ! -e /web/fir_short ] && \cp -a dist_short /web/fir_short || \cp -a dist_short/* /web/fir_short/) && echo build success + + + buildadmin: + container_name: buildadmin + image: 'node:14.17.3' + working_dir: /fir_admin + volumes: + - /etc/localtime:/etc/localtime:ro + - ../../fir_admin:/fir_admin + - ../../data/web/:/web + command: + - sh + - -c + - yarn config set registry https://registry.npm.taobao.org && yarn install && yarn build:prod && ([ ! -e /web/fir_admin ] && \cp -a dist /web/fir_admin || \cp -a dist/* /web/fir_admin/) && echo build success + diff --git a/docker/flyapps/docker-compose.yml b/docker/flyapps/docker-compose.yml new file mode 100644 index 0000000..e5131d3 --- /dev/null +++ b/docker/flyapps/docker-compose.yml @@ -0,0 +1,45 @@ +version: '3' + +networks: + flyapps: + external: true + name: flyapps + +services: + flyapps: + container_name: flyapps + restart: always + image: 'flyapps' + working_dir: /data/fir_ser + volumes: + - /etc/localtime:/etc/localtime:ro + - ../../fir_ser:/data/fir_ser + - ../../data/flyapps/files:/data/fir_ser/files + - ../../data/logs/flyapps/:/data/fir_ser/logs + - ../../data/flyapps/supersign/:/data/fir_ser/supersign + networks: + flyapps: + ipv4_address: 172.31.31.100 + external_links: + - mariadb:mariadb + - redis:redis + sysctls: + - net.core.somaxconn=4096 + nginx: + container_name: nginx + restart: always + image: 'nginx:1.21.3' + volumes: + - /etc/localtime:/etc/localtime:ro + - ../../data/web:/data + - ../../nginx.conf.d:/etc/nginx/conf.d + networks: + flyapps: + ipv4_address: 172.31.31.200 + ports: + - 80:80 + - 443:443 + external_links: + - flyapps:flyapps + depends_on: + - flyapps diff --git a/docker/init/clean.sh b/docker/init/clean.sh new file mode 100644 index 0000000..62332fc --- /dev/null +++ b/docker/init/clean.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# +# + +for i in flyapps mariadb redis buildclient buildshort buildadmin;do echo $i;docker rm -f $i;done + + +docker network rm flyapps + diff --git a/docker/init/init.sh b/docker/init/init.sh new file mode 100644 index 0000000..299e32b --- /dev/null +++ b/docker/init/init.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# +# + +which dockerd +if [ $? -ne 0 ];then + dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo + dnf install docker-ce -y +fi +which docker-compose +if [ $? -ne 0 ];then + curl -L https://get.daocloud.io/docker/compose/releases/download/v2.5.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose + chmod +x /usr/local/bin/docker-compose +fi + +data_path="$(dirname $(dirname `pwd`))/data" +mkdir -pv ${data_path}/{flyapps,web,mariadb,redis,logs/{mariadb,nginx,flyapps}} +chown 1001.1001 -R ${data_path}/{flyapps,web,mariadb,redis,logs/{mariadb,nginx,flyapps}} +systemctl start docker && docker network create flyapps --driver bridge --subnet=172.31.31.0/24 +systemctl enable docker +systemctl status docker + + +#docker pull 'bitnami/mariadb:10.7.3' +#docker pull 'bitnami/redis:6.2.7' +#docker pull 'nginx:1.21.3' +#docker pull 'node:14.17.3' diff --git a/docker/init/timezone b/docker/init/timezone new file mode 100644 index 0000000..421b7a4 --- /dev/null +++ b/docker/init/timezone @@ -0,0 +1 @@ +Asia/Shanghai diff --git a/docker/mariadb/docker-compose.yml b/docker/mariadb/docker-compose.yml new file mode 100644 index 0000000..26c92e5 --- /dev/null +++ b/docker/mariadb/docker-compose.yml @@ -0,0 +1,43 @@ +version: '3.2' + + + +networks: + flyapps: + external: true + name: flyapps + +services: + + mariadb: + image: bitnami/mariadb:10.7.3 + container_name: mariadb + restart: always + environment: + - MARIADB_ROOT_PASSWORD=rootIPD.xx2.19 + - MARIADB_DATABASE=flyappnew + - MARIADB_USER=flyuser + - MARIADB_PASSWORD=KGzKjZpWBp4R4RSa + #- ALLOW_EMPTY_PASSWORD=yes + - MARIADB_ENABLE_SLOW_QUERY=1 + - MARIADB_LONG_QUERY_TIME=3 + - MARIADB_SKIP_TEST_DB=yes + - MARIADB_EXTRA_FLAGS=--max-connect-errors=3000 --max_connections=30000 + ports: + - 3306:3306 + networks: + flyapps: + ipv4_address: 172.31.31.90 + volumes: + - ../init/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + - ../../data/mariadb:/bitnami/mariadb/data + - ../../data/logs/mariadb:/data/logs/mariadb + - ./server.cnf:/opt/bitnami/mariadb/conf/my_custom.cnf:ro + +# adminer: +# image: adminer +# ports: +# - 8080:8080 +# networks: +# - fungame diff --git a/docker/mariadb/server.cnf b/docker/mariadb/server.cnf new file mode 100644 index 0000000..e0727f1 --- /dev/null +++ b/docker/mariadb/server.cnf @@ -0,0 +1,108 @@ +# +# These groups are read by MariaDB server. +# Use it for options that only the server (but not clients) should see +# +# See the examples of server my.cnf files in /usr/share/mysql/ +# + + +# this is only for the mysqld standalone daemon +[mysqld] +binlog_cache_size = 192K +thread_stack = 384K +join_buffer_size = 4096K +query_cache_type = 1 +max_heap_table_size = 1024M + +default_storage_engine = InnoDB +performance_schema_max_table_instances = 400 +table_definition_cache = 400 +skip-external-locking +key_buffer_size = 512M +max_allowed_packet = 1G +table_open_cache = 1024 +sort_buffer_size = 2048K +net_buffer_length = 4K +read_buffer_size = 2048K +read_rnd_buffer_size = 1024K +myisam_sort_buffer_size = 16M +thread_cache_size = 192 +query_cache_size = 256M +tmp_table_size = 1024M +sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES + + +max_connections = 30000 +max_connect_errors = 1000 +open_files_limit = 65535 + +expire_logs_days = 10 +#log_queries_not_using_indexes=on + +character-set-client-handshake = FALSE +character-set-server = utf8mb4 +collation-server = utf8mb4_general_ci +init_connect='SET NAMES utf8mb4' +#character-set-server=utf8 +skip_name_resolve +event_scheduler=1 +#skip-grant-tables + + +#innodb_data_home_dir = /var/lib/mysql/ +#innodb_data_file_path = ibdata1:10M:autoextend +#innodb_log_group_home_dir = /var/lib/mysql/ +#innodb_buffer_pool_size = 1024M +#innodb_log_file_size = 128M +#innodb_log_buffer_size = 32M +#innodb_flush_log_at_trx_commit = 1 +#innodb_lock_wait_timeout = 50 +#innodb_max_dirty_pages_pct = 90 +#innodb_read_io_threads = 4 +#innodb_write_io_threads = 4 + + + +# +# Allow server to accept connections on all interfaces. +# +#bind-address=0.0.0.0 +# +# this is only for embedded server +# This group is only read by MariaDB servers, not by MySQL. +# If you use the same .cnf file for MySQL and MariaDB, +# you can put MariaDB-only options here +[mariadb] +#autoset_open_files_limit +#enable_slow_query_log + +#audit +plugin_load_add=server_audit +server_audit_logging=on +server_audit_events=connect,query +server_audit=force_plus_permanent +server_audit_events=QUERY_DDL,QUERY_DML,CONNECT +server_audit_output_type=file +server_audit_file_rotate_now=on +server_audit_file_rotations=9 +server_audit_file_rotate_size=1G +server_audit_file_path=/data/logs/mariadb + + +log_error=/data/logs/mariadb/mariadb.err.log + +log_output=FILE +slow_query_log +long_query_time=3 +slow_query_log_file=/data/logs/mariadb/mariadb-slow.log +log_queries_not_using_indexes=ON #Logging Queries That Don't Use Indexes + + + +#server_id=2 +log-bin=/data/logs/mariadb/mysql-bin + +# This group is only read by MariaDB-10.5 servers. +# If you use the same .cnf file for MariaDB of different versions, +# use this group for options that older servers don't understand + diff --git a/docker/redis/docker-compose.yml b/docker/redis/docker-compose.yml new file mode 100644 index 0000000..06b9b4d --- /dev/null +++ b/docker/redis/docker-compose.yml @@ -0,0 +1,25 @@ +version: '3.2' + + +networks: + flyapps: + external: true + name: flyapps + +services: + redis: + image: 'bitnami/redis:6.2.7' + container_name: redis + restart: always + volumes: + - ../init/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + - ../../data/redis:/bitnami/redis/data + environment: + #- REDIS_REPLICATION_MODE=master + #- ALLOW_EMPTY_PASSWORD=yes + - REDIS_PASSWORD=nineven + networks: + - flyapps + #ports: + # - 6379:6379 diff --git a/docker/scripts/build.sh b/docker/scripts/build.sh new file mode 100644 index 0000000..5dc11d1 --- /dev/null +++ b/docker/scripts/build.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# +# + +cd ../build/ + +for i in buildclient buildadmin;do + docker-compose up ${i} +done + +docker-compose build + + diff --git a/docker/scripts/start_all.sh b/docker/scripts/start_all.sh new file mode 100644 index 0000000..b6c3775 --- /dev/null +++ b/docker/scripts/start_all.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# +# + +cd ../mariadb/ && docker-compose up -d +cd ../redis/ && docker-compose up -d + +cd ../flyapps/ && docker-compose up -d + diff --git a/docker/scripts/stop_all.sh b/docker/scripts/stop_all.sh new file mode 100644 index 0000000..da1a10f --- /dev/null +++ b/docker/scripts/stop_all.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# +# + + +cd ../flyapps/ && docker-compose down + +cd ../redis/ && docker-compose down + +cd ../mariadb/ && docker-compose down diff --git a/fir_admin/.env.production b/fir_admin/.env.production index 80c8103..8e31700 100644 --- a/fir_admin/.env.production +++ b/fir_admin/.env.production @@ -2,5 +2,5 @@ ENV = 'production' # base api -VUE_APP_BASE_API = '/prod-api' +VUE_APP_BASE_API = '/api/v3/fir/server' diff --git a/fir_client/package.json b/fir_client/package.json index ae3ac04..3eca518 100644 --- a/fir_client/package.json +++ b/fir_client/package.json @@ -36,7 +36,6 @@ "eslint": "^5.16.0", "eslint-plugin-vue": "^5.0.0", "html-webpack-plugin": "^5.3.1", - "image-webpack-loader": "^7.0.1", "script-ext-html-webpack-plugin": "^2.1.5", "uglifyjs-webpack-plugin": "^2.2.0", "vue-template-compiler": "^2.6.10", diff --git a/fir_client/src/components/FirLogin.vue b/fir_client/src/components/FirLogin.vue index 5beb0be..ede70ea 100644 --- a/fir_client/src/components/FirLogin.vue +++ b/fir_client/src/components/FirLogin.vue @@ -125,7 +125,7 @@