背景
novel 項目的技術棧比較多,很多同學都曾經向我反映過安裝完全部環境需要花大量時間,甚至有的小伙伴可能嫌麻煩就直接放棄了,為了解決這個問題,今天花了好幾個小時整了個一鍵安裝的教程,不僅可以一鍵安裝所有 novel 項目技術棧所需的環境,而且也可以直接用于其它的項目中。為什么搞了這么長時間呢?主要是在 Elasticsearch 8 上面踩了一些坑,下面先看下效果:
安裝步驟
1.Docker Compose 安裝(除了第一步要根據自己的系統來安裝,其它步驟全都一樣)
如果是 Ubuntu 系統,執行如下的安裝命令:
sudo apt install docker-compose -y
查看 Docker Compose 和 Docker 的版本信息:
docker-compose version
docker --version
docker version
2.準備 Docker Compose 的服務編排文件
version: '3.9'
services:
novel-MySQL:
container_name: novel-mysql
image: mysql:8.0
restart: always
hostname: novel-mysql
environment:
- MYSQL_ROOT_PASSword=test123456
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:7.0
restart: always
hostname: novel-redis
command: redis-server --save 60 1 --loglevel warning
ports:
- 6379:6379
networks:
- novelnet
novel-rabbitmq:
container_name: novel-rabbitmq
image: rabbitmq:3-management
restart: always
hostname: novel-rabbitmq
environment:
- RABBITMQ_DEFAULT_USER=xxyopen
- RABBITMQ_DEFAULT_PASS=test123456
ports:
- 15672:15672
- 5672:5672
networks:
- novelnet
novel-elasticsearch:
container_name: novel-elasticsearch
image: elasticsearch:8.6.2
restart: always
hostname: novel-elasticsearch
environment:
# 內存不夠用的話最好不要配置這個
# - "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/logs
ports:
- 9200:9200
- 9300:9300
networks:
- novelnet
novel-kibana:
container_name: novel-kibana
image: kibana:8.6.2
restart: always
hostname: novel-kibana
environment:
ELASTICSEARCH_HOSTS: '["https://novel-elasticsearch:9200"]'
volumes:
- /data/docker/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml
ports:
- 5601:5601
depends_on:
- novel-elasticsearch
networks:
- novelnet
novel-xxl-job-admin:
container_name: novel-xxl-job-admin
image: xuxueli/xxl-job-admin:2.3.1
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=test123456
- JAVA_OPTS=-Xmx512m
volumes:
- /data/docker/xxl-job-admin/data/Applogs:/data/applogs
ports:
- 8080:8080
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
3.在后臺運行所有編排文件中的容器
sudo docker-compose up -d
4.重設 kibana_system 賬戶的密碼,kibana_system 是用于連接到 Elasticsearch 的內置角色,它不能用于登錄 kibana 控制臺
sudo docker exec -it novel-elasticsearch bin/elasticsearch-reset-password --username kibana_system
5.創建 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.yml
6.單獨啟動 kibana 容器
sudo docker start novel-kibana
7.重設 elastic 賬戶密碼,用來登錄 kibana 控制臺
sudo docker exec -it novel-elasticsearch bin/elasticsearch-reset-password --username elastic
8.使用上一步設置的賬戶和密碼登錄 kibana 控制臺
elastic
Fy2JWjJ1hcO2mi1USFLR
注意:需要將 xxl-job 的數據庫文件導入 MySQL 后,xxl-job-admin 才能正常訪問。
順便說下,novel-cloud 已經往 Spring Cloud 2022 的方向重構了,并且會適配 novel 項目的 Vue 前端,感興趣的同學可以持續關注。