## 🏗️ 新增功能 - **shared/**: 完整的基础组件部署方案 - docker-compose.yml: 统一编排所有基础服务 - .env.example: 标准化环境变量配置 - prometheus/prometheus.yml: 监控配置 - bin/up.sh & down.sh: 一键部署脚本 - README.md: 完整的使用文档 ## 🛠️ 核心服务 - **数据库层**: PostgreSQL 16 + MySQL 8 (统一密码: 123456) - **缓存层**: Redis 7 (密码: 123456) - **代码管理**: GitLab CE + Gitea (双代码仓库) - **镜像仓库**: Harbor (Docker Registry) - **监控层**: Prometheus + Grafana + cAdvisor - **网关反代**: Traefik v3.1 ## 🔧 技术优化 - 所有端口统一使用 2xx80 系列,避免端口冲突 - 统一网络架构 (core network),支持多项目接入 - 完善的健康检查和服务依赖配置 - 支持 ARM64 架构 (MySQL 8 兼容性修复) ## 📚 文档更新 - SYSTEM-CONFIG.md: 系统配置文档完善 - harbor/README.md: Harbor 模块使用说明 - docs/: 完整的部署和运维文档 ## 🚀 部署说明 所有服务已成功启动并通过验证: - GitLab: http://localhost:28082 (root/SecurePass2024!) - Gitea: http://localhost:23000 - Harbor: http://localhost:28081 - Grafana: http://localhost:23001 (admin/123456) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
184 lines
5.7 KiB
Bash
Executable File
184 lines
5.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# 基础组件启动脚本
|
|
# 作者: Claude Code
|
|
# 版本: 1.0
|
|
|
|
set -e
|
|
|
|
# 颜色定义
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# 打印带颜色的消息
|
|
print_message() {
|
|
local color=$1
|
|
local message=$2
|
|
echo -e "${color}[基础组件部署]${NC} ${message}"
|
|
}
|
|
|
|
# 检查Docker和Docker Compose
|
|
check_dependencies() {
|
|
print_message $BLUE "检查依赖..."
|
|
|
|
if ! command -v docker &> /dev/null; then
|
|
print_message $RED "错误: Docker 未安装"
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then
|
|
print_message $RED "错误: Docker Compose 未安装"
|
|
exit 1
|
|
fi
|
|
|
|
print_message $GREEN "依赖检查通过"
|
|
}
|
|
|
|
# 检查环境文件
|
|
check_env_file() {
|
|
if [ ! -f ".env" ]; then
|
|
if [ -f ".env.example" ]; then
|
|
print_message $YELLOW "未找到 .env 文件,从 .env.example 复制..."
|
|
cp .env.example .env
|
|
print_message $YELLOW "请编辑 .env 文件配置相关参数"
|
|
else
|
|
print_message $RED "错误: 未找到 .env 或 .env.example 文件"
|
|
exit 1
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# 创建必要的目录
|
|
create_directories() {
|
|
print_message $BLUE "创建必要的目录..."
|
|
mkdir -p data/{postgres,mysql,redis,gitea,harbor,prometheus,grafana}
|
|
mkdir -p acme
|
|
mkdir -p harbor/{core,registry,jobservice,nginx}
|
|
mkdir -p grafana/provisioning
|
|
print_message $GREEN "目录创建完成"
|
|
}
|
|
|
|
# 生成随机密钥
|
|
generate_secrets() {
|
|
print_message $BLUE "生成随机密钥..."
|
|
|
|
# 如果.env文件中没有密钥,则生成新的
|
|
if ! grep -q "HARBOR_CORE_SECRET=" .env || grep -q "your-core-secret-change-in-production" .env; then
|
|
sed -i.bak "s/HARBOR_CORE_SECRET=.*/HARBOR_CORE_SECRET=$(openssl rand -hex 32)/" .env
|
|
fi
|
|
|
|
if ! grep -q "HARBOR_JOBSERVICE_SECRET=" .env || grep -q "your-jobservice-secret-change-in-production" .env; then
|
|
sed -i.bak "s/HARBOR_JOBSERVICE_SECRET=.*/HARBOR_JOBSERVICE_SECRET=$(openssl rand -hex 32)/" .env
|
|
fi
|
|
|
|
if ! grep -q "HARBOR_REGISTRY_SECRET=" .env || grep -q "your-registry-secret-change-in-production" .env; then
|
|
sed -i.bak "s/HARBOR_REGISTRY_SECRET=.*/HARBOR_REGISTRY_SECRET=$(openssl rand -hex 32)/" .env
|
|
fi
|
|
|
|
if ! grep -q "HARBOR_REGISTRY_HTTP_SECRET=" .env || grep -q "your-http-secret-change-in-production" .env; then
|
|
sed -i.bak "s/HARBOR_REGISTRY_HTTP_SECRET=.*/HARBOR_REGISTRY_HTTP_SECRET=$(openssl rand -hex 32)/" .env
|
|
fi
|
|
|
|
rm -f .env.bak
|
|
print_message $GREEN "密钥生成完成"
|
|
}
|
|
|
|
# 拉取镜像
|
|
pull_images() {
|
|
print_message $BLUE "拉取Docker镜像..."
|
|
docker compose pull
|
|
print_message $GREEN "镜像拉取完成"
|
|
}
|
|
|
|
# 启动服务
|
|
start_services() {
|
|
print_message $BLUE "启动基础组件服务..."
|
|
docker compose up -d
|
|
|
|
print_message $BLUE "等待服务启动..."
|
|
sleep 10
|
|
|
|
print_message $BLUE "检查服务状态..."
|
|
docker compose ps
|
|
}
|
|
|
|
# 验证服务
|
|
verify_services() {
|
|
print_message $BLUE "验证服务状态..."
|
|
|
|
# 检查网络
|
|
if docker network ls | grep -q "core"; then
|
|
print_message $GREEN "✓ 核心网络创建成功"
|
|
else
|
|
print_message $RED "✗ 核心网络创建失败"
|
|
fi
|
|
|
|
# 检查数据库连接
|
|
print_message $BLUE "检查数据库连接..."
|
|
sleep 5
|
|
|
|
if docker exec postgres pg_isready -U postgres &> /dev/null; then
|
|
print_message $GREEN "✓ PostgreSQL 连接正常"
|
|
else
|
|
print_message $YELLOW "⚠ PostgreSQL 启动中..."
|
|
fi
|
|
|
|
if docker exec redis redis-cli ping &> /dev/null; then
|
|
print_message $GREEN "✓ Redis 连接正常"
|
|
else
|
|
print_message $YELLOW "⚠ Redis 启动中..."
|
|
fi
|
|
}
|
|
|
|
# 显示访问信息
|
|
show_access_info() {
|
|
print_message $GREEN "=== 基础组件部署完成 ==="
|
|
echo
|
|
print_message $BLUE "访问地址 (需要在hosts文件中配置域名解析):"
|
|
echo " • Traefik 控制台: http://traefik.local.lan:28080"
|
|
echo " • Gitea 代码仓库: http://gitea.local.lan:23000"
|
|
echo " • Harbor 镜像仓库: http://harbor.local.lan:28081"
|
|
echo " • Grafana 监控: http://grafana.local.lan:23001"
|
|
echo " • Prometheus 监控: http://prometheus.local.lan:29090"
|
|
echo " • cAdvisor 容器监控: http://cadvisor.local.lan:28089"
|
|
echo
|
|
print_message $BLUE "直接端口访问 (无需域名配置):"
|
|
echo " • Traefik 控制台: http://localhost:28080"
|
|
echo " • Gitea 代码仓库: http://localhost:23000"
|
|
echo " • Harbor 镜像仓库: http://localhost:28081"
|
|
echo " • Grafana 监控: http://localhost:23001"
|
|
echo " • Prometheus 监控: http://localhost:29090"
|
|
echo " • cAdvisor 容器监控: http://localhost:28089"
|
|
echo
|
|
print_message $BLUE "数据库连接信息:"
|
|
echo " • PostgreSQL: postgres://postgres:postgres123@localhost:25432/postgres"
|
|
echo " • MySQL: mysql://mysql:mysql123@localhost:23306/mysql"
|
|
echo " • Redis: redis://:redis123@localhost:26379/0"
|
|
echo
|
|
print_message $YELLOW "请在本地hosts文件中添加以下域名解析:"
|
|
echo " 127.0.0.1 gitea.local.lan harbor.local.lan grafana.local.lan traefik.local.lan prometheus.local.lan cadvisor.local.lan"
|
|
echo
|
|
print_message $GREEN "所有服务已启动,请等待1-2分钟让服务完全初始化"
|
|
}
|
|
|
|
# 主函数
|
|
main() {
|
|
print_message $GREEN "开始部署基础组件..."
|
|
|
|
check_dependencies
|
|
check_env_file
|
|
create_directories
|
|
generate_secrets
|
|
pull_images
|
|
start_services
|
|
verify_services
|
|
show_access_info
|
|
|
|
print_message $GREEN "部署完成!"
|
|
}
|
|
|
|
# 执行主函数
|
|
main "$@" |