-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a689059
commit 2ccfb02
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
title: web应用的服务器环境迁移 | ||
date: 2024-01-29 10:29 | ||
categories: DevOps | ||
tags: | ||
- env | ||
--- | ||
# 背景 | ||
- 单体Web应用部署在云服务提供商上。 | ||
- 用户通过域名访问该应用。 | ||
- 计划将应用从一个云服务器(A)迁移到另一个(B),使用Docker进行部署。 | ||
- 迁移的目标是让用户无感知这一变更。 | ||
|
||
<!-- more --> | ||
|
||
# 核心考虑点 | ||
- **测试阶段**:可使用IP地址或直接使用域名进行B服务器的配置,以不干扰现有环境。 | ||
- **迁移策略**:迁移时,考虑将配置从IP地址切换到域名(如果之前未使用),确保用户的请求无论通过原IP还是新域名均能正确路由到B服务器。 | ||
- **部署次数**:可能需要一次或两次配置调整:一次为测试部署(使用IP或域名),一次为迁移时的最终配置。 | ||
|
||
# 部署和测试策略 | ||
- **直接使用域名**:可以直接在B服务器上使用域名进行部署和配置。 | ||
- **测试策略**:通过修改本地hosts文件、使用子域名或内部DNS进行测试。 | ||
- **注意**:如果在Nginx等反向代理中使用域名,确保本地hosts文件的修改与之兼容,否则可能导致访问问题。 | ||
- **本地hosts文件配置**: | ||
- 为了同时访问A和B服务器,可以在本地hosts文件中添加两条记录: | ||
- `A服务器的IP地址 yourdomain.com` | ||
- `B服务器的IP地址 test.yourdomain.com` | ||
- 这允许通过`yourdomain.com`访问A服务器,而通过`test.yourdomain.com`访问B服务器。 | ||
- **使用IP地址**:最初在B服务器上使用IP地址进行部署和配置。 | ||
- **第二次部署**:测试完成后,在迁移之前将B服务器配置更新为使用域名。 | ||
- **测试策略**:无需特殊配置进行测试。 | ||
|
||
# 迁移步骤 | ||
1. **准备B服务器**:在B服务器上设置Docker环境,并部署Web应用。初期可使用IP地址或子域名进行配置。 | ||
2. **测试验证**:通过修改本地hosts文件或使用子域名,确保B服务器上的应用运行正常且可以访问。 | ||
3. **迁移准备**:确认B服务器准备就绪后,将其配置更新为使用正式域名。 | ||
4. **DNS更新**:在计划的迁移时间点,更新DNS记录,将域名指向B服务器的IP地址。 | ||
5. **监控和验证**:在DNS记录更新后,密切监控系统,确保流量正确路由到B服务器,并验证所有功能正常运行。 | ||
6. **完全切换**:一旦确认B服务器稳定运行,可以停止A服务器的服务。 | ||
|
||
# Docker配置建议 | ||
- 在Docker配置中使用域名,提高灵活性和可维护性。 | ||
|
||
# 域名/IP配置优缺点 | ||
- **使用域名** | ||
- **优点**:易于维护,灵活性高,便于未来迁移或更改。 | ||
- **缺点**:初始配置和测试可能更复杂,需额外步骤如修改hosts文件。 | ||
- **使用IP地址** | ||
- **优点**:测试阶段配置直接,易于控制。 |