# 安装步骤
# 使用 Docker Compose 一键安装开发环境
- Docker Compose 安装。(除了第一步需要根据自己的平台去安装 Docker Compose 以外,其它步骤都一样)
在 Ubuntu 下执行如下的安装命令:
sudo apt install docker-compose -y
查看 Docker Compose 和 Docker 的版本信息:
docker-compose version
docker --version
docker version
- 创建
.env
文件,用来设置容器编排的环境变量。
# 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
- 创建 Docker Compose 的容器编排文件
docker-compose.yml
。
version: '3.9'
services:
novel-mysql:
container_name: novel-mysql
image: mysql:${MYSQL_VERSION}
restart: always
hostname: novel-mysql
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
volumes:
- "/data/docker/mysql/data:/var/lib/mysql"
- "/data/docker/mysql/init.sql:/docker-entrypoint-initdb.d/init.sql"
command: mysqld --max_allowed_packet=100M
ports:
- "3306:3306"
networks:
- novelnet
novel-redis:
container_name: novel-redis
image: redis:${REDIS_VERSION}
restart: always
hostname: novel-redis
command: redis-server --save 60 1 --loglevel warning --requirepass "${REDIS_PASSWORD}"
ports:
- "6379:6379"
networks:
- novelnet
novel-rabbitmq:
container_name: novel-rabbitmq
image: rabbitmq:${RABBITMQ_VERSION}
restart: always
hostname: novel-rabbitmq
environment:
- RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER}
- RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS}
- RABBITMQ_DEFAULT_VHOST=${RABBITMQ_DEFAULT_VHOST}
ports:
- "15672:15672"
- "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:
- novelnet
novel-elasticsearch:
container_name: novel-elasticsearch
image: elasticsearch:${ELASTIC_VERSION}
restart: always
hostname: novel-elasticsearch
environment:
- "ES_JAVA_OPTS=-Xms125m -Xmx512m"
- discovery.type=single-node
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
- KIBANA_PASSWORD=${KIBANA_PASSWORD}
- xpack.security.http.ssl.enabled=false
ports:
- "9200:9200"
depends_on:
- novel-elasticsearch-setup
networks:
- novelnet
novel-kibana:
container_name: novel-kibana
image: kibana:${KIBANA_VERSION}
restart: always
hostname: novel-kibana
environment:
- ELASTICSEARCH_HOSTS=http://novel-elasticsearch:9200
- ELASTICSEARCH_USERNAME=kibana_system
- ELASTICSEARCH_PASSWORD=${KIBANA_PASSWORD}
ports:
- "5601:5601"
depends_on:
- novel-elasticsearch
networks:
- novelnet
novel-xxl-job-admin:
container_name: novel-xxl-job-admin
image: xuxueli/xxl-job-admin:${XXLJOB_VERSION}
restart: always
hostname: novel-xxl-job-admin
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=${MYSQL_ROOT_PASSWORD} --xxl.job.accessToken=${XXLJOB_ACCESSTOKEN}
- JAVA_OPTS=-Xmx512m
volumes:
- /data/docker/xxl-job-admin/data/applogs:/data/applogs
ports:
- "8080:8080"
depends_on:
- novel-mysql
networks:
- novelnet
novel-nacos-server:
container_name: novel-nacos-server
image: nacos/nacos-server:${NACOS_VERSION}
restart: always
hostname: novel-nacos-server
environment:
- PREFER_HOST_MODE=hostname
- MODE=standalone
- SPRING_DATASOURCE_PLATFORM=mysql
- MYSQL_SERVICE_HOST=novel-mysql
- MYSQL_SERVICE_DB_NAME=nacos
- MYSQL_SERVICE_PORT=3306
- MYSQL_SERVICE_USER=root
- MYSQL_SERVICE_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true
- NACOS_AUTH_IDENTITY_KEY=xxyopen
- NACOS_AUTH_IDENTITY_VALUE=xxyopen
- NACOS_AUTH_TOKEN=SecretKey012345678901234567890123456789012345678901234567890123456789
- JVM_XMS=125M
- JVM_XMX=125M
- JVM_XMN=50M
- JVM_MS=50M
- JVM_MMS=50M
ports:
- "8848:8848"
- "9848:9848"
depends_on:
- novel-mysql
networks:
- novelnet
networks:
novelnet:
driver: bridge
注意:Elasticsearch 容器挂载本地目录或文件时,需要修改目录或文件的读写权限,否则启动不成功。官方原文如下:
If you are bind-mounting a local directory or file, it must be readable by the elasticsearch user. In addition, this user must have write access to the data and log dirs. A good strategy is to grant group access to gid 1000 or 0 for the local directory.
For example, to prepare a local directory for storing data through a bind-mount:
mkdir esdatadir chmod g+rwx esdatadir chgrp 1000 esdatadir
上传数据库初始化文件
novel-cloud/doc/init.sql
到/data/docker/mysql
目录下。在后台运行所有编排文件中的容器。
sudo docker-compose up -d
- 使用
.env
环境文件中配置的elastic
账号密码来登录 kibana 控制台。
elastic
Fy2JWjJ1hcO2mi1USFL1
注意:MySQL 需要先执行 xxl-job 和 nacos 的初始化 SQL 脚本(
https://github.com/xuxueli/xxl-job/blob/2.3.1/doc/db/tables_xxl_job.sql
和https://github.com/alibaba/nacos/releases/download/2.2.1/nacos-server-2.2.1.zip!/conf/nacos-mysql.sql
)后,xxl-job-admin 和 nacos-server 才能正常启动。SQL 脚本一定要去下载容器版本对应的才行,本项目已经将全部的初始化脚本都放到了novel-cloud/doc/init.sql
文件中。
# 后端服务启动
- 小说数据导入。
novel-cloud 数据库中导入 https://gitee.com/novel_dev_team/novel/blob/master/doc/sql/novel.sql.zip
压缩包中的 novel_data.sql
脚本文件(导入前需要:set names utf8mb4
)。
登录 Kibana,执行
https://github.com/201206030/novel/blob/master/doc/es/book.http
文件中的小说索引创建语句。导入 novel-cloud/doc/nacos 目录下的 nacos 配置文件到 nacos 服务中,并修改 novel-mysql.yml、novel-redis.yml、novel-rabbitmq.yml、novel-search-service.yml 中的配置。
修改
novel-cloud/novel-core/novel-config/src/main/resources/bootstrap-common.yml
、novel-cloud/novel-gateway/src/main/resources/bootstrap.yml
中的 Nacos 配置中心地址和novel-cloud/novel-core/novel-config/src/main/resources/application-common.yml
、novel-cloud/novel-monitor/src/main/resources/application.yml
、novel-cloud/novel-gateway/src/main/resources/application.yml
中的 Nacos 注册中心地址。启动各个微服务。
登录 xxl-job 控制台,点击任务管理菜单,执行同步小说数据到 Elasticsearch 的任务导入 MySQL 中的小说数据到 Elasticsearch。
# 前端服务启动
- 下载源码。
git clone https://gitee.com/novel_dev_team/novel-front-web.git
yarn
安装。
npm install -g yarn
- 项目根目录下运行如下命令来安装项目依赖。
yarn install
- 项目根目录下运行如下命令启动。
yarn serve
- 浏览器通过
http://localhost:1024
来访问。
# 安装说明
安装遇到困难可以请求作者
远程协助
👉 了解详情 (opens new window)