使用 Docker Compose 一键安装 novel 项目的开发环境

背景
novel 项目的技术栈比较多,很多同学都曾经向我反映过安装完全部环境需要花大量时间,甚至有的小伙伴可能嫌麻烦就直接放弃了,为了解决这个问题,今天花了好几个小时整了个一键安装的教程,不仅可以一键安装所有 novel 项目技术栈所需的环境,而且也可以直接用于其它的项目中 。为什么搞了这么长时间呢?主要是在 Elasticsearch 8 上面踩了一些坑,下面先看下效果:

使用 Docker Compose 一键安装 novel 项目的开发环境

文章插图
 
安装步骤
1.Docker Compose 安装(除了第一步要根据自己的系统来安装,其它步骤全都一样)
如果是 Ubuntu 系统,执行如下的安装命令:
sudo apt install docker-compose -y查看 Docker Compose 和 Docker 的版本信息:
docker-compose versiondocker --versiondocker version2.准备 Docker Compose 的服务编排文件
【使用 Docker Compose 一键安装 novel 项目的开发环境】version: '3.9'services:novel-MySQL:container_name: novel-mysqlimage: mysql:8.0restart: alwayshostname: novel-mysqlenvironment:- MYSQL_ROOT_PASSword=test123456volumes:- "/data/docker/mysql/data:/var/lib/mysql"- "/data/docker/mysql/init.sql:/docker-entrypoint-initdb.d/init.sql"command: mysqld --max_allowed_packet=100Mports:- 3306:3306.NETworks:- novelnetnovel-redis:container_name: novel-redisimage: redis:7.0restart: alwayshostname: novel-rediscommand: redis-server --save 60 1 --loglevel warningports:- 6379:6379networks:- novelnetnovel-rabbitmq:container_name: novel-rabbitmqimage: rabbitmq:3-managementrestart: alwayshostname: novel-rabbitmqenvironment:- RABBITMQ_DEFAULT_USER=xxyopen- RABBITMQ_DEFAULT_PASS=test123456ports:- 15672:15672- 5672:5672networks:- novelnetnovel-elasticsearch:container_name: novel-elasticsearchimage: elasticsearch:8.6.2restart: alwayshostname: novel-elasticsearchenvironment:# 内存不够用的话最好不要配置这个# - "ES_JAVA_OPTS=-Xms512m -Xmx512m"- discovery.type=single-node# 挂载本地目录时需要修改该目录的读写权限才能正常启动# volumes:#- /data/docker/elasticsearch/data:/usr/share/elasticsearch/data#- /data/docker/elasticsearch/logs:/usr/share/elasticsearch/logsports:- 9200:9200- 9300:9300networks:- novelnetnovel-kibana:container_name: novel-kibanaimage: kibana:8.6.2restart: alwayshostname: novel-kibanaenvironment:ELASTICSEARCH_HOSTS: '["https://novel-elasticsearch:9200"]'volumes:- /data/docker/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.ymlports:- 5601:5601depends_on:- novel-elasticsearchnetworks:- novelnetnovel-xxl-job-admin:container_name: novel-xxl-job-adminimage: xuxueli/xxl-job-admin:2.3.1restart: alwayshostname: novel-xxl-job-adminenvironment:- 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- JAVA_OPTS=-Xmx512mvolumes:- /data/docker/xxl-job-admin/data/Applogs:/data/applogsports:- 8080:8080depends_on:- novel-mysqlnetworks:- novelnetnetworks: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
3.在后台运行所有编排文件中的容器
sudo docker-compose up -d4.重设 kibana_system 账户的密码,kibana_system 是用于连接到 Elasticsearch 的内置角色,它不能用于登录 kibana 控制台
sudo docker exec -it novel-elasticsearch bin/elasticsearch-reset-password --username kibana_system5.创建 kibana.yml 配置文件,填入上一步重置的 kibana_system 账户和密码
sudo mkdir -p /data/docker/kibana/config && sudo touch /data/docker/kibana/config/kibana.yml && sudo chmod 666 /data/docker/kibana/config/kibana.yml && sudo echo 'server.host: "0.0.0.0"server.shutdownTimeout: "5s"elasticsearch.hosts: [ "https://novel-elasticsearch:9200" ]elasticsearch.ssl.verificationMode: "none"elasticsearch.username: "kibana_system"elasticsearch.password: "=5Jbb-VsW9TkY*cJu9Y4"' > /data/docker/kibana/config/kibana.yml6.单独启动 kibana 容器
sudo docker start novel-kibana7.重设 elastic 账户密码,用来登录 kibana 控制台


推荐阅读