Files
tyapi-server/docs/环境搭建指南.md

128 lines
2.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 🔧 环境搭建指南
## 开发环境配置
### 1. 配置环境变量
```bash
# 复制环境变量模板
cp env.example .env
# 编辑环境变量(根据需要修改)
vim .env
```
### 2. 启动基础服务
```bash
# 启动 PostgreSQL 和 Redis
docker-compose -f docker-compose.dev.yml up -d postgres redis
# 查看服务状态
docker-compose -f docker-compose.dev.yml ps
```
### 3. 数据库初始化
```bash
# 创建数据库表
make migrate
# 或手动执行SQL
psql -h localhost -U postgres -d tyapi_dev -f scripts/init.sql
```
### 4. 依赖安装
```bash
# 安装Go依赖
go mod download
# 验证依赖
go mod verify
```
## 生产环境配置
### 1. 配置文件准备
```bash
# 复制生产配置模板
cp config.prod.yaml config.yaml
# 修改生产配置
vim config.yaml
```
### 2. 环境变量设置
```bash
export APP_ENV=production
export DB_HOST=your-db-host
export DB_PASSWORD=your-secure-password
export JWT_SECRET=your-jwt-secret
export REDIS_HOST=your-redis-host
```
## 服务配置说明
### PostgreSQL 配置
默认配置:
- 端口5432
- 数据库tyapi_dev
- 用户名postgres
- 密码Pg9mX4kL8nW2rT5y开发环境
### Redis 配置
默认配置:
- 端口6379
- 无密码(开发环境)
- 数据库0
### 监控服务配置
- **Prometheus**: http://localhost:9090
- **Grafana**: http://localhost:3000 (admin/Gf7nB3xM9cV6pQ2w)
- **Jaeger**: http://localhost:16686
### 存储服务配置
- **MinIO**: http://localhost:9000 (minioadmin/Mn5oH8yK3bR7vX1z)
- **对象存储控制台**: http://localhost:9001
## 常见配置问题
### 端口冲突
如果遇到端口冲突,可以修改 `docker-compose.dev.yml` 中的端口映射:
```yaml
ports:
- "15432:5432" # 将 PostgreSQL 映射到本地 15432 端口
```
### 权限问题
在 Linux/macOS 系统中,可能需要调整文件权限:
```bash
# 给予脚本执行权限
chmod +x scripts/*.sh
# 修复数据目录权限
sudo chown -R $(whoami) ./data/
```
### 内存不足
如果系统内存不足,可以减少启动的服务:
```bash
# 只启动核心服务
docker-compose -f docker-compose.dev.yml up -d postgres redis
```