1
1
forked from wangqifan/calc
calc/README.md

217 lines
4.7 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.

# AWS EC2 价格计算器
这是一个基于Vue.js和Python FastAPI开发的AWS EC2价格计算器网站可以帮助用户计算和比较不同EC2实例的价格。
## 功能特点
1. **价格计算器**
- 选择实例类型、区域、操作系统和购买选项
- 实时计算价格
- 显示详细的价格信息
2. **实例搜索**
- 根据CPU、内存和其他规格查找最合适的实例
- 支持从AWS官方API和数据库两种数据源查询
- 显示完整规格和价格信息
3. **价格比较**
- 支持多个实例配置的并排比较
- 生成标准化的报价单
- 支持导出Excel格式报价单
## 技术栈
- **前端**Vue.js 3 + Element Plus
- **后端**Python FastAPI
- **数据源**AWS Pricing API + MySQL数据库
## 系统要求
- Python 3.9+
- Node.js 14+
- npm 6+
- MySQL 5.7+
## 项目结构
```
.
├── backend/ # 后端项目
│ ├── app/ # 应用代码
│ │ ├── api/ # API路由
│ │ ├── core/ # 核心配置
│ │ ├── models/ # 数据模型
│ │ └── services/ # 服务层
│ ├── main.py # 入口文件
│ └── requirements.txt # 依赖包
└── frontend/ # 前端项目
├── public/ # 静态资源
├── src/ # 源代码
│ ├── api/ # API调用
│ ├── assets/ # 资源文件
│ ├── components/ # 组件
│ └── views/ # 页面
└── package.json # 依赖配置
```
## 安装与部署
### 后端部署
1. **创建并激活虚拟环境**
```bash
# 创建虚拟环境
conda create -n calc python=3.10
conda activate calc
```
2. **安装依赖**
```bash
cd backend
pip install -r requirements.txt
```
3. **配置环境变量**
创建`.env`文件在backend目录下添加以下内容
```
# AWS凭证
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_DEFAULT_REGION=us-east-1
# MySQL数据库配置
MYSQL_HOST=localhost
MYSQL_USER=your_username
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=aws_price
```
4. **启动开发服务器**
```bash
# 开发环境
uvicorn main:app --reload --host 0.0.0.0 --port 8000
# 生产环境
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000
```
### 前端部署
1. **安装依赖**
```bash
cd frontend
npm install
```
2. **启动开发服务器**
```bash
npm run serve
```
3. **构建生产版本**
```bash
npm run build
```
4. **前端生产环境部署**
`frontend/dist`目录下的文件部署到Web服务器的根目录。
### Nginx配置示例
```nginx
server {
listen 80;
server_name your_domain.com;
# 前端静态文件
location / {
root /path/to/frontend/dist;
index index.html;
try_files $uri $uri/ /index.html;
}
# 后端API代理
location /api {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
```
## API接口说明
### 主要API端点
- `GET /api/regions` - 获取所有可用区域
- `GET /api/instance-types` - 获取所有实例类型
- `POST /api/search-instances` - 搜索符合条件的实例AWS API方式
- `POST /api/search-instances-v2` - 搜索符合条件的实例(数据库方式)
- `POST /api/compare-prices` - 对比多个配置的价格
### 示例请求
```json
// 搜索实例示例请求
POST /api/search-instances-v2
{
"cpu_cores": 4,
"memory_gb": 16,
"disk_gb": 100,
"region": "us-east-1",
"operating_system": "Linux"
}
```
## 数据库说明
该应用使用MySQL数据库存储AWS实例价格数据主要表结构如下
**aws_price表**
- `id` - 唯一标识符
- `locations` - 区域类型
- `area_en` - 区域英文名称
- `area_cn` - 区域中文名称
- `instance_type` - 实例类型
- `price` - 小时价格
- `operating_system` - 操作系统
- `vcpu` - CPU核心数
- `memory` - 内存大小(GB)
- `updatetime` - 更新时间
## 常见问题解答
1. **价格计算不准确?**
- 确保已配置正确的AWS凭证
- 价格可能因区域和时间而变化
2. **无法连接数据库?**
- 检查数据库连接配置
- 确保MySQL服务已启动
- 验证用户权限
3. **API返回错误**
- 检查日志获取详细错误信息
- 验证请求格式是否正确
## 贡献指南
1. Fork 项目
2. 创建特性分支 (`git checkout -b feature/amazing-feature`)
3. 提交更改 (`git commit -m 'Add some amazing feature'`)
4. 推送到分支 (`git push origin feature/amazing-feature`)
5. 创建Pull Request
## 许可证
MIT License