first commit
This commit is contained in:
commit
16894901da
329
README.md
Normal file
329
README.md
Normal file
@ -0,0 +1,329 @@
|
||||
# AWS EC2 价格计算器
|
||||
|
||||
这是一个基于Vue.js和Python FastAPI开发的AWS EC2价格计算器网站,可以帮助用户计算和比较不同EC2实例的价格。
|
||||
|
||||
## 功能特点
|
||||
|
||||
1. 价格计算器
|
||||
- 选择实例类型、区域、操作系统和购买选项
|
||||
- 实时计算价格
|
||||
- 显示详细的价格信息
|
||||
|
||||
2. 价格对比
|
||||
- 支持多个配置的价格对比
|
||||
- 表格和图表展示
|
||||
- 导出对比结果
|
||||
|
||||
3. 预算估算
|
||||
- 支持自定义和预设使用时长
|
||||
- 显示月度成本趋势
|
||||
- 详细的成本明细
|
||||
|
||||
## 技术栈
|
||||
|
||||
- 前端:Vue.js 3 + Element Plus + ECharts
|
||||
- 后端:Python FastAPI + Boto3
|
||||
- 数据源:AWS API
|
||||
|
||||
## 系统要求
|
||||
|
||||
- Docker 20.10+
|
||||
- Docker Compose 2.0+
|
||||
- Node.js 14+
|
||||
- npm 6+
|
||||
|
||||
## 快速开始
|
||||
|
||||
1. 克隆项目并进入项目目录:
|
||||
```bash
|
||||
git clone <repository-url>
|
||||
cd calc
|
||||
```
|
||||
|
||||
2. 创建环境变量文件:
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
然后编辑 `.env` 文件,填入必要的环境变量。
|
||||
|
||||
3. 运行安装脚本:
|
||||
```bash
|
||||
chmod +x install.sh
|
||||
./install.sh
|
||||
```
|
||||
|
||||
安装脚本会自动:
|
||||
- 检查必要的命令是否已安装
|
||||
- 创建必要的目录结构
|
||||
- 构建前端项目
|
||||
- 检查环境变量配置
|
||||
- 检查 SSL 证书(如果有)
|
||||
- 启动所有服务
|
||||
- 检查服务状态
|
||||
|
||||
## 访问应用
|
||||
|
||||
安装完成后,可以通过以下地址访问应用:
|
||||
- 前端界面:http://localhost
|
||||
- 后端 API:http://localhost:8000
|
||||
|
||||
## 目录结构
|
||||
|
||||
```
|
||||
.
|
||||
├── backend/ # 后端服务
|
||||
├── frontend/ # 前端项目
|
||||
├── nginx/ # Nginx 配置
|
||||
│ ├── conf.d/ # Nginx 配置文件
|
||||
│ └── ssl/ # SSL 证书目录
|
||||
├── docker-compose.yml
|
||||
├── install.sh
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## 开发说明
|
||||
|
||||
### 前端开发
|
||||
```bash
|
||||
cd frontend
|
||||
npm install
|
||||
npm run serve
|
||||
```
|
||||
|
||||
### 后端开发
|
||||
```bash
|
||||
cd backend
|
||||
pip install -r requirements.txt
|
||||
python manage.py runserver
|
||||
```
|
||||
|
||||
## 部署说明
|
||||
|
||||
### 使用 SSL 证书
|
||||
|
||||
1. 将 SSL 证书文件放在 `nginx/ssl/` 目录下:
|
||||
- `cert.pem`:SSL 证书文件
|
||||
- `key.pem`:SSL 私钥文件
|
||||
|
||||
2. 修改 `nginx/conf.d/default.conf` 中的 `server_name` 为你的域名。
|
||||
|
||||
### 环境变量
|
||||
|
||||
在 `.env` 文件中配置以下环境变量:
|
||||
```
|
||||
AWS_ACCESS_KEY_ID=your_access_key
|
||||
AWS_SECRET_ACCESS_KEY=your_secret_key
|
||||
AWS_DEFAULT_REGION=your_region
|
||||
```
|
||||
|
||||
## 常见问题
|
||||
|
||||
1. 如果遇到权限问题,请确保使用 `sudo` 运行安装脚本:
|
||||
```bash
|
||||
sudo ./install.sh
|
||||
```
|
||||
|
||||
2. 如果服务启动失败,可以查看日志:
|
||||
```bash
|
||||
docker-compose logs
|
||||
```
|
||||
|
||||
3. 如果需要重新构建前端:
|
||||
```bash
|
||||
cd frontend
|
||||
npm run build
|
||||
```
|
||||
|
||||
## 维护说明
|
||||
|
||||
### 更新应用
|
||||
```bash
|
||||
git pull
|
||||
./install.sh
|
||||
```
|
||||
|
||||
### 停止服务
|
||||
```bash
|
||||
docker-compose down
|
||||
```
|
||||
|
||||
### 查看日志
|
||||
```bash
|
||||
docker-compose logs -f
|
||||
```
|
||||
|
||||
## 安装说明
|
||||
|
||||
### 开发环境部署
|
||||
|
||||
#### 后端设置
|
||||
|
||||
1. 创建虚拟环境:
|
||||
```bash
|
||||
python -m venv venv
|
||||
source venv/bin/activate # Linux/Mac
|
||||
venv\Scripts\activate # Windows
|
||||
```
|
||||
|
||||
2. 安装依赖:
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
3. 配置AWS凭证:
|
||||
创建`.env`文件并添加以下内容:
|
||||
```
|
||||
AWS_ACCESS_KEY_ID=your_access_key
|
||||
AWS_SECRET_ACCESS_KEY=your_secret_key
|
||||
AWS_DEFAULT_REGION=your_region
|
||||
```
|
||||
|
||||
4. 运行后端服务:
|
||||
```bash
|
||||
cd backend
|
||||
uvicorn main:app --reload
|
||||
```
|
||||
|
||||
#### 前端设置
|
||||
|
||||
1. 安装依赖:
|
||||
```bash
|
||||
cd frontend
|
||||
npm install
|
||||
```
|
||||
|
||||
2. 运行开发服务器:
|
||||
```bash
|
||||
npm run serve
|
||||
```
|
||||
|
||||
### 生产环境部署
|
||||
|
||||
#### 后端部署
|
||||
|
||||
1. 安装生产环境依赖:
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
pip install gunicorn
|
||||
```
|
||||
|
||||
2. 使用 Gunicorn 启动后端服务:
|
||||
```bash
|
||||
cd backend
|
||||
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000
|
||||
```
|
||||
|
||||
3. 配置 Nginx 反向代理(可选):
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name your_domain.com;
|
||||
|
||||
location /api {
|
||||
proxy_pass http://localhost:8000;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 前端部署
|
||||
|
||||
1. 构建生产版本:
|
||||
```bash
|
||||
cd frontend
|
||||
npm run build
|
||||
```
|
||||
|
||||
2. 配置 Nginx 服务静态文件:
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name your_domain.com;
|
||||
|
||||
root /path/to/frontend/dist;
|
||||
index index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location /api {
|
||||
proxy_pass http://localhost:8000;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Docker 部署
|
||||
|
||||
1. 构建后端镜像:
|
||||
```bash
|
||||
cd backend
|
||||
docker build -t aws-calc-backend .
|
||||
```
|
||||
|
||||
2. 构建前端镜像:
|
||||
```bash
|
||||
cd frontend
|
||||
docker build -t aws-calc-frontend .
|
||||
```
|
||||
|
||||
3. 使用 Docker Compose 启动服务:
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
4. 查看服务状态:
|
||||
```bash
|
||||
docker-compose ps
|
||||
```
|
||||
|
||||
## 环境变量配置
|
||||
|
||||
### 后端环境变量
|
||||
```env
|
||||
AWS_ACCESS_KEY_ID=your_access_key
|
||||
AWS_SECRET_ACCESS_KEY=your_secret_key
|
||||
AWS_DEFAULT_REGION=your_region
|
||||
CORS_ORIGINS=http://localhost:8080,https://your_domain.com
|
||||
ENVIRONMENT=production
|
||||
```
|
||||
|
||||
### 前端环境变量
|
||||
```env
|
||||
VUE_APP_API_URL=http://localhost:8000
|
||||
VUE_APP_ENV=production
|
||||
```
|
||||
|
||||
## 使用说明
|
||||
|
||||
1. 访问 http://localhost:8080 打开应用
|
||||
2. 使用导航菜单切换不同的功能页面
|
||||
3. 在表单中选择所需的配置
|
||||
4. 点击计算按钮查看结果
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 确保已配置有效的AWS凭证
|
||||
- 后端服务默认运行在 http://localhost:8000
|
||||
- 前端开发服务器默认运行在 http://localhost:8080
|
||||
- 生产环境部署时请确保:
|
||||
- 使用 HTTPS
|
||||
- 配置适当的安全头部
|
||||
- 启用 CORS 保护
|
||||
- 设置适当的缓存策略
|
||||
- 配置错误监控和日志记录
|
||||
|
||||
## 贡献指南
|
||||
|
||||
1. Fork 项目
|
||||
2. 创建特性分支
|
||||
3. 提交更改
|
||||
4. 推送到分支
|
||||
5. 创建 Pull Request
|
||||
|
||||
## 许可证
|
||||
|
||||
MIT License
|
||||
Loading…
x
Reference in New Issue
Block a user