chore: 优化 Docker Compose 容器编排文件,进一步简化安装过程

This commit is contained in:
xiongxiaoyang 2023-04-02 01:56:30 +08:00
parent a0f5bb8449
commit eb26b6e599
5 changed files with 89 additions and 43 deletions

32
doc/docker/.env Normal file
View File

@ -0,0 +1,32 @@
# MYSQL 配置
MYSQL_VERSION=8.0
MYSQL_ROOT_PASSWORD=test123456
# Redis 配置
REDIS_VERSION=7.0
REDIS_PASSWORD=test123456
# RabbitMQ 配置
RABBITMQ_VERSION=3-management
RABBITMQ_DEFAULT_USER=xxyopen
RABBITMQ_DEFAULT_PASS=test123456
RABBITMQ_DEFAULT_VHOST=novel
# Elasticsearch 配置
ELASTIC_VERSION=8.6.2
# 'elastic' 账户的密码 (至少 6 个字符)
ELASTIC_PASSWORD=Fy2JWjJ1hcO2mi1USFL1
# 'kibana_system' 账号的密码 (至少 6 个字符)
KIBANA_PASSWORD=5JbbVsW9TkYcJu9Y9
# Kibana 配置
KIBANA_VERSION=8.6.2
# XXL-JOB 配置
XXLJOB_VERSION=2.3.1
XXLJOB_ACCESSTOKEN=123
# Nacos 配置
NACOS_VERSION=v2.2.1

View File

@ -3,76 +3,92 @@ version: '3.9'
services: services:
novel-mysql: novel-mysql:
container_name: novel-mysql container_name: novel-mysql
image: mysql:8.0 image: mysql:${MYSQL_VERSION}
restart: always restart: always
hostname: novel-mysql hostname: novel-mysql
environment: environment:
- MYSQL_ROOT_PASSWORD=test123456 - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
volumes: volumes:
- "/data/docker/mysql/data:/var/lib/mysql" - "/data/docker/mysql/data:/var/lib/mysql"
- "/data/docker/mysql/init.sql:/docker-entrypoint-initdb.d/init.sql" - "/data/docker/mysql/init.sql:/docker-entrypoint-initdb.d/init.sql"
command: mysqld --max_allowed_packet=100M command: mysqld --max_allowed_packet=100M
ports: ports:
- 3306:3306 - "3306:3306"
networks: networks:
- novelnet - novelnet
novel-redis: novel-redis:
container_name: novel-redis container_name: novel-redis
image: redis:7.0 image: redis:${REDIS_VERSION}
restart: always restart: always
hostname: novel-redis hostname: novel-redis
command: redis-server --save 60 1 --loglevel warning command: redis-server --save 60 1 --loglevel warning --requirepass "${REDIS_PASSWORD}"
ports: ports:
- 6379:6379 - "6379:6379"
networks: networks:
- novelnet - novelnet
novel-rabbitmq: novel-rabbitmq:
container_name: novel-rabbitmq container_name: novel-rabbitmq
image: rabbitmq:3-management image: rabbitmq:${RABBITMQ_VERSION}
restart: always restart: always
hostname: novel-rabbitmq hostname: novel-rabbitmq
environment: environment:
- RABBITMQ_DEFAULT_USER=xxyopen - RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER}
- RABBITMQ_DEFAULT_PASS=test123456 - RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS}
- RABBITMQ_DEFAULT_VHOST=novel - RABBITMQ_DEFAULT_VHOST=${RABBITMQ_DEFAULT_VHOST}
ports: ports:
- 15672:15672 - "15672:15672"
- 5672:5672 - "5672:5672"
networks:
- novelnet
novel-elasticsearch-setup:
container_name: novel-elasticsearch-setup
image: elasticsearch:${ELASTIC_VERSION}
hostname: novel-elasticsearch-setup
user: "0"
command: >
bash -c '
echo "Waiting for Elasticsearch availability";
until curl -s http://novel-elasticsearch:9200 | grep -q "missing authentication credentials"; do sleep 30; done;
echo "Setting kibana_system password";
until curl -s -X POST -u "elastic:${ELASTIC_PASSWORD}" -H "Content-Type: application/json" http://novel-elasticsearch:9200/_security/user/kibana_system/_password -d "{\"password\":\"${KIBANA_PASSWORD}\"}" | grep -q "^{}"; do sleep 10; done;
echo "All done!";
'
networks: networks:
- novelnet - novelnet
novel-elasticsearch: novel-elasticsearch:
container_name: novel-elasticsearch container_name: novel-elasticsearch
image: elasticsearch:8.6.2 image: elasticsearch:${ELASTIC_VERSION}
restart: always restart: always
hostname: novel-elasticsearch hostname: novel-elasticsearch
environment: environment:
# 内存不够用的话最好不要配置这个 - "ES_JAVA_OPTS=-Xms125m -Xmx512m"
# - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- discovery.type=single-node - discovery.type=single-node
# 挂载本地目录时需要修改该目录的读写权限才能正常启动 - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
# volumes: - KIBANA_PASSWORD=${KIBANA_PASSWORD}
# - /data/docker/elasticsearch/data:/usr/share/elasticsearch/data - xpack.security.http.ssl.enabled=false
# - /data/docker/elasticsearch/logs:/usr/share/elasticsearch/logs
ports: ports:
- 9200:9200 - "9200:9200"
- 9300:9300 depends_on:
- novel-elasticsearch-setup
networks: networks:
- novelnet - novelnet
novel-kibana: novel-kibana:
container_name: novel-kibana container_name: novel-kibana
image: kibana:8.6.2 image: kibana:${KIBANA_VERSION}
restart: always restart: always
hostname: novel-kibana hostname: novel-kibana
environment: environment:
ELASTICSEARCH_HOSTS: '["https://novel-elasticsearch:9200"]' - ELASTICSEARCH_HOSTS=http://novel-elasticsearch:9200
volumes: - ELASTICSEARCH_USERNAME=kibana_system
- /data/docker/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml - ELASTICSEARCH_PASSWORD=${KIBANA_PASSWORD}
# - ELASTICSEARCH_SSL_VERIFICATIONMODE=none
ports: ports:
- 5601:5601 - "5601:5601"
depends_on: depends_on:
- novel-elasticsearch - novel-elasticsearch
networks: networks:
@ -80,16 +96,16 @@ services:
novel-xxl-job-admin: novel-xxl-job-admin:
container_name: novel-xxl-job-admin container_name: novel-xxl-job-admin
image: xuxueli/xxl-job-admin:2.3.1 image: xuxueli/xxl-job-admin:${XXLJOB_VERSION}
restart: always restart: always
hostname: novel-xxl-job-admin hostname: novel-xxl-job-admin
environment: environment:
- PARAMS=--spring.datasource.url=jdbc:mysql://novel-mysql:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai --spring.datasource.username=root --spring.datasource.password=test123456 --xxl.job.accessToken=123 - PARAMS=--spring.datasource.url=jdbc:mysql://novel-mysql:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai --spring.datasource.username=root --spring.datasource.password=${MYSQL_ROOT_PASSWORD} --xxl.job.accessToken=${XXLJOB_ACCESSTOKEN}
- JAVA_OPTS=-Xmx512m - JAVA_OPTS=-Xmx512m
volumes: volumes:
- /data/docker/xxl-job-admin/data/applogs:/data/applogs - /data/docker/xxl-job-admin/data/applogs:/data/applogs
ports: ports:
- 8080:8080 - "8080:8080"
depends_on: depends_on:
- novel-mysql - novel-mysql
networks: networks:
@ -97,7 +113,7 @@ services:
novel-nacos-server: novel-nacos-server:
container_name: novel-nacos-server container_name: novel-nacos-server
image: nacos/nacos-server:v2.2.1 image: nacos/nacos-server:${NACOS_VERSION}
restart: always restart: always
hostname: novel-nacos-server hostname: novel-nacos-server
environment: environment:
@ -108,7 +124,7 @@ services:
- MYSQL_SERVICE_DB_NAME=nacos - MYSQL_SERVICE_DB_NAME=nacos
- MYSQL_SERVICE_PORT=3306 - MYSQL_SERVICE_PORT=3306
- MYSQL_SERVICE_USER=root - MYSQL_SERVICE_USER=root
- MYSQL_SERVICE_PASSWORD=test123456 - MYSQL_SERVICE_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true - MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true
- NACOS_AUTH_IDENTITY_KEY=xxyopen - NACOS_AUTH_IDENTITY_KEY=xxyopen
- NACOS_AUTH_IDENTITY_VALUE=xxyopen - NACOS_AUTH_IDENTITY_VALUE=xxyopen

View File

@ -9,16 +9,13 @@ PUT /book
"type" : "long" "type" : "long"
}, },
"authorName" : { "authorName" : {
"type" : "text", "type" : "text"
"analyzer": "ik_smart"
}, },
"bookName" : { "bookName" : {
"type" : "text", "type" : "text"
"analyzer": "ik_smart"
}, },
"bookDesc" : { "bookDesc" : {
"type" : "text", "type" : "text"
"analyzer": "ik_smart"
}, },
"bookStatus" : { "bookStatus" : {
"type" : "short" "type" : "short"
@ -27,15 +24,13 @@ PUT /book
"type" : "integer" "type" : "integer"
}, },
"categoryName" : { "categoryName" : {
"type" : "text", "type" : "text"
"analyzer": "ik_smart"
}, },
"lastChapterId" : { "lastChapterId" : {
"type" : "long" "type" : "long"
}, },
"lastChapterName" : { "lastChapterName" : {
"type" : "text", "type" : "text"
"analyzer": "ik_smart"
}, },
"lastChapterUpdateTime" : { "lastChapterUpdateTime" : {
"type": "long" "type": "long"

View File

@ -0,0 +1,4 @@
FROM java:17
ADD novel-author-service-2.0.0-SNAPSHOT.jar /root
ENV NACOS_ADDR=""
ENTRYPOINT ["sh","-c","java -Dspring.cloud.nacos.config.server-addr=${NACOS_ADDR} -Dspring.cloud.nacos.discovery.server-addr=${NACOS_ADDR} -jar novel-author-service-2.0.0-SNAPSHOT.jar"]

View File

@ -8,7 +8,6 @@ import io.github.xxyopen.novel.book.service.BookService;
import io.github.xxyopen.novel.common.constant.ApiRouterConsts; import io.github.xxyopen.novel.common.constant.ApiRouterConsts;
import io.github.xxyopen.novel.common.resp.PageRespDto; import io.github.xxyopen.novel.common.resp.PageRespDto;
import io.github.xxyopen.novel.common.resp.RestResp; import io.github.xxyopen.novel.common.resp.RestResp;
import io.github.xxyopen.novel.user.dto.resp.UserInfoRespDto;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;