diff --git a/.env.example b/.env.example index 43542cf..1c71d28 100644 --- a/.env.example +++ b/.env.example @@ -31,6 +31,9 @@ MEILISEARCH_PORT=7700 MEILISEARCH_DATA=${DATA_DIR}/data.ms MEILISEARCH_KEY=masterKey +# Swagger +SWAGGER_ROOT=${APP_DIR}/swagger.localhost/public + # Resource PHP_MEMORY_LIMITS=2G PHP8_MEMORY_LIMITS=2G @@ -38,3 +41,4 @@ MYSQL_MEMORY_LIMITS=4G NGIX_MEMORY_LIMITS=128M REDIS_MEMORY_LIMITS=16M MEILSEARCH_MEMORY_LIMITS=512M + diff --git a/bin/dump_db.sh b/bin/dump_db.sh index 524c340..fa066cd 100755 --- a/bin/dump_db.sh +++ b/bin/dump_db.sh @@ -19,7 +19,7 @@ EOL exit 1 } -SECURE_DIR=$($CMD mysql -N -e "SHOW VARIABLES LIKE 'secure_file_priv';" | awk '{ print $2 }') +SECURE_DIR=$($CMD mysql -u root -N -e "SHOW VARIABLES LIKE 'secure_file_priv';" | awk '{ print $2 }') [ "$SECURE_DIR" = "" ] && SECURE_DIR=/var/lib/mysql-files [ -d "${DB_DUMP_DIR}" ] && @@ -28,7 +28,11 @@ SECURE_DIR=$($CMD mysql -N -e "SHOW VARIABLES LIKE 'secure_file_priv';" | awk '{ find "${DB_DUMP_DIR}" -type f -exec rm -f {} \; } && { echo "Dump Started to ${DB_DUMP_DIR}" - $CMD mysqldump "$DATABASE" --tab=$SECURE_DIR --fields-terminated-by=0x1e --single-transaction --order-by-primary + $CMD mysqldump -u root "$DATABASE" --tab=$SECURE_DIR --fields-terminated-by=0x1e --single-transaction --order-by-primary + #$CMD mysqlpump -u root "$DATABASE" --tab=$SECURE_DIR --fields-terminated-by=0x1e --single-transaction --skip-definer +} && { + echo "Remove DEFINER" + $CMD find $SECURE_DIR -type f -name "*.sql" -exec perl -pi -E 's/\/\*![0-9]+\sDEFINER=.+\*\///g' {} \; } && { echo "The job has been successfully done!" } diff --git a/bin/restore_db.sh b/bin/restore_db.sh index bf774b2..da771e7 100755 --- a/bin/restore_db.sh +++ b/bin/restore_db.sh @@ -19,16 +19,16 @@ EOL exit 1 } -SECURE_DIR=$($CMD mysql -N -e "SHOW VARIABLES LIKE 'secure_file_priv';" | awk '{ print $2 }') +SECURE_DIR=$($CMD mysql -u root -N -e "SHOW VARIABLES LIKE 'secure_file_priv';" | awk '{ print $2 }') [ "$SECURE_DIR" = "" ] && SECURE_DIR=/var/lib/mysql-files -echo "Start to restore database from ${SRC}" +echo "Start to restore database from ${SRC}"; { echo "Drop database: ${DATABASE}" - $CMD mysql -e "DROP DATABASE IF EXISTS $DATABASE" + $CMD mysql -u root -e "DROP DATABASE IF EXISTS $DATABASE" } && { echo "Create database" - $CMD mysql -e "CREATE DATABASE IF NOT EXISTS $DATABASE" 2> /dev/null + $CMD mysql -u root -e "CREATE DATABASE IF NOT EXISTS $DATABASE" 2> /dev/null } && { echo "Restore $DATABASE" for localTxtFile in "${SRC}"/*.txt; do @@ -38,18 +38,18 @@ echo "Start to restore database from ${SRC}" sqlFile=${localSqlFile/.txt/.sql} txtFile=${localTxtFile/${SRC}/${SECURE_DIR::-1}} - #echo "Create table: $table" - $CMD mysql "${DATABASE}" -e "SET FOREIGN_KEY_CHECKS=0;SET UNIQUE_CHECKS=0;source ${sqlFile};" + echo "Create table: $table" + $CMD mysql -u root "${DATABASE}" -e "SET FOREIGN_KEY_CHECKS=0;SET UNIQUE_CHECKS=0;source ${sqlFile};" echo -n "Restore data: $table (${rows} rows)" startedAt=$(date +%s.%3N) - $CMD mysql "${DATABASE}" --local-infile=1 -e "SET FOREIGN_KEY_CHECKS=0;SET UNIQUE_CHECKS=0;SET AUTOCOMMIT=0;ALTER TABLE ${table} DISABLE KEYS;LOAD DATA LOCAL INFILE '${txtFile}' INTO TABLE ${table} FIELDS TERMINATED BY 0x1e LINES TERMINATED BY '\n';COMMIT;ALTER TABLE ${table} ENABLE KEYS;" + $CMD mysql -u root "${DATABASE}" --local-infile=1 -e "SET FOREIGN_KEY_CHECKS=0;SET UNIQUE_CHECKS=0;SET AUTOCOMMIT=0;ALTER TABLE ${table} DISABLE KEYS;LOAD DATA LOCAL INFILE '${txtFile}' INTO TABLE ${table} FIELDS TERMINATED BY 0x1e LINES TERMINATED BY '\n';COMMIT;ALTER TABLE ${table} ENABLE KEYS;" endedAt=$(date +%s.%3N) time1=$(echo "scale=3; ${endedAt} - ${startedAt}" | bc) echo " $time1 sec" done - $CMD mysql "${DATABASE}" -e "SET FOREIGN_KEY_CHECKS=1;SET UNIQUE_CHECKS=1;SET AUTOCOMMIT=1;" + $CMD mysql -u root "${DATABASE}" -e "SET FOREIGN_KEY_CHECKS=1;SET UNIQUE_CHECKS=1;SET AUTOCOMMIT=1;" } && { echo "The job has been successfully done!" } diff --git a/config.sh b/config.sh new file mode 100755 index 0000000..b40dea2 --- /dev/null +++ b/config.sh @@ -0,0 +1,2 @@ +#!/bin/sh +for f in `grep -vE '^#' docker-compose.conf`;do echo -n "-f $f "; done diff --git a/docker-compose.conf b/docker-compose.conf new file mode 100644 index 0000000..57c4d03 --- /dev/null +++ b/docker-compose.conf @@ -0,0 +1,3 @@ +docker-compose.yml +#docker-compose.swagger.yml +#docker-compose.meilisearch.yml diff --git a/docker-compose.meilisearch.yml b/docker-compose.meilisearch.yml new file mode 100644 index 0000000..5540c53 --- /dev/null +++ b/docker-compose.meilisearch.yml @@ -0,0 +1,20 @@ +version: "3" +services: + meilisearch: + image: getmeili/meilisearch:latest + deploy: + resources: + limits: + memory: ${MEILSEARCH_MEMORY_LIMITS} + hostname: meilisearch + container_name: meilisearch + user: ${USER_UID}:${USER_UID} + #restart: unless-stopped + #command: ./meilisearch --master-key=${MEILISEARCH_KEY} --no-analytics + command: ./meilisearch --no-analytics --http-payload-size-limit=500Mb + ports: + - "127.0.0.1:${MEILISEARCH_PORT}:${MEILISEARCH_PORT}" + volumes: + - ${MEILISEARCH_DATA}:/data.ms + networks: + - intranet diff --git a/docker-compose.swagger.yml b/docker-compose.swagger.yml new file mode 100644 index 0000000..22ec906 --- /dev/null +++ b/docker-compose.swagger.yml @@ -0,0 +1,25 @@ +version: "3" +services: + swagger-editor: + image: swaggerapi/swagger-editor + hostname: swagger-editor + container_name: "swagger-editor" + ports: + - "8081:8080" + networks: + - intranet + + swagger-ui: + image: swaggerapi/swagger-ui + hostname: swagger-ui + container_name: "swagger-ui" + ports: + - "127.0.0.1:8082:8080" + volumes: + #- ./swagger/openapi.json:/openapi.json + - ${SWAGGER_ROOT}/openapi.json:/openapi.json + environment: + SWAGGER_JSON: /openapi.json + # API_URL: "" + networks: + - intranet diff --git a/docker-compose.yml b/docker-compose.yml index e2918c8..5017629 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -49,7 +49,10 @@ services: - intranet mysql: - image: mysql:8.0 + image: mysql:8.0.23 + # to fix mbind: Operation not permitted + cap_add: + - SYS_NICE deploy: resources: limits: @@ -75,7 +78,8 @@ services: - ${DB_DUMP_DIR}:/var/lib/mysql-files networks: - intranet - command: --explicit_defaults_for_timestamp=ON + command: --user=mysql + --explicit_defaults_for_timestamp=ON --character-set-server=utf8mb4 --collation-server=utf8mb4_0900_ai_ci @@ -113,25 +117,6 @@ services: networks: - intranet - meilisearch: - image: getmeili/meilisearch:latest - deploy: - resources: - limits: - memory: ${MEILSEARCH_MEMORY_LIMITS} - hostname: meilisearch - container_name: meilisearch - user: ${USER_UID}:${USER_UID} - #restart: unless-stopped - #command: ./meilisearch --master-key=${MEILISEARCH_KEY} --no-analytics - command: ./meilisearch --no-analytics --http-payload-size-limit=500Mb - ports: - - "127.0.0.1:${MEILISEARCH_PORT}:${MEILISEARCH_PORT}" - volumes: - - ${MEILISEARCH_DATA}:/data.ms - networks: - - intranet - networks: intranet: driver: bridge diff --git a/mysql/etc/mysqld.cnf b/mysql/etc/mysqld.cnf index f097ebf..37ccdef 100644 --- a/mysql/etc/mysqld.cnf +++ b/mysql/etc/mysqld.cnf @@ -39,28 +39,38 @@ local_infile = 1 secure_file_priv = "/var/lib/mysql-files/" #secure_file_priv = "" #skip-networking = 1 -disable_log_bin = 1 -skip_log_bin = 1 #host_cache_size = 0 +disable_log_bin = 1 -# https://stackoverflow.com/questions/59391611/how-to-improve-performance-of-mysql-dump-restore#:~:text=Summary%20(for%20best%20dump%20restore,should%20be%20enabled%20on%20production. -#innodb_buffer_pool_size = 268435456 -innodb_buffer_pool_size = 2G -#innodb_log_file_size = 1G -innodb_redo_log_capacity = 1G +sql_mode = ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION # https://dev.mysql.com/doc/refman/8.0/en/stored-programs-logging.html#:~:text=By%20default%2C%20this%20variable%20has,enabled%2C%20log_bin_trust_function_creators%20does%20not%20apply. #binlog_format = MIXED # https://stackoverflow.com/questions/1404107/permissions-for-creating-a-trigger-in-mysql log_bin_trust_function_creators = ON -sql_mode = ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION +# https://stackoverflow.com/questions/59391611/how-to-improve-performance-of-mysql-dump-restore#:~:text=Summary%20(for%20best%20dump%20restore,should%20be%20enabled%20on%20production. +# Default +#innodb_buffer_pool_size = 134217728 +#innodb_log_file_size = 50331648 +#bulk_insert_buffer_size = 8388608 +#max_connections = 151 + +# 4G for MySQL +innodb_buffer_pool_size = 2G +innodb_log_file_size = 128M +#innodb_redo_log_capacity = 128M +bulk_insert_buffer_size = 128M + +# default #sort_buffer_size = 262144 #innodb_sort_buffer_size = 1048576 -sort_buffer_size = 4M -innodb_sort_buffer_size = 10M +# tune +sort_buffer_size = 8M +innodb_sort_buffer_size = 16M -#innodb_max_undo_log_size = 1073741824 - -#innodb-force-recovery=1 +#innodb_force_recovery=6 +# +## default max_allowed_packet = 67108864 +#max_allowed_packet = 1G diff --git a/nginx/etc/www.localhost.conf b/nginx/etc/www.localhost.conf index 1f0dfa2..057aa92 100644 --- a/nginx/etc/www.localhost.conf +++ b/nginx/etc/www.localhost.conf @@ -23,13 +23,26 @@ server { fastcgi_param PATH_INFO $fastcgi_path_info; } + # S:Swagger + location /swagger/editor/ { + proxy_buffering off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Port $server_port; + proxy_pass http://swagger-editor:8080/; + } + + location /swagger/docs/ { + proxy_buffering off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Port $server_port; + proxy_pass http://swagger-ui:8080/; + } + # E:Swagger + location / { -# try_files $uri $uri/ /index.php?$query_string @not_found; try_files $uri $uri/ /index.php?$query_string; gzip_static on; } - -# location @not_found { -# echo "404 - Please create $file_path/public/index.html"; -# } } diff --git a/start.sh b/start.sh index d8e8689..374080b 100755 --- a/start.sh +++ b/start.sh @@ -1,11 +1,12 @@ #!/bin/bash +CFG=$(./config.sh) OPT="$1" uname -a | grep 'Darwin' > /dev/null if [ $? -eq 0 ]; then # Mac - docker-compose up -d $OPT + docker-compose $CFG up -d $OPT else # Ubuntu # laradock_elasticsearch_1 exited with code 78 @@ -20,7 +21,7 @@ else sudo systemctl start docker.socket && { sudo systemctl start docker.service - docker-compose down - docker-compose up -d $OPT + docker-compose $CFG down + docker-compose $CFG up -d $OPT } && sudo systemctl status docker.service fi diff --git a/stop.sh b/stop.sh index b8f564c..c4e2016 100755 --- a/stop.sh +++ b/stop.sh @@ -1,5 +1,6 @@ #!/bin/bash -docker-compose down && { +CFG=$(./config.sh) +docker-compose $CFG down && { sudo systemctl stop docker.socket && sudo systemctl stop docker } && {