您的位置:首页 > 编程语言 > Go语言

gcp vm实例 拷贝_将旧式整体应用程序从任何提供商的VM移至Google Cloud Platform(GCP),计算引擎

2020-08-21 11:30 1341 查看

gcp vm实例 拷贝

As the title has heavily hinted, the premise of this topic is as follows: How do I migrate any legacy un-containerized applications and workflows, from any Virtual Machines (VMs) to Google Cloud Platform (GCP)? My tale was that of a legacy and monolithic application, which had a MongoDB database instance in the same disk, and I had to look at moving both the application and database over to GCP.

正如标题所暗示的那样,该主题的前提如下: 如何将任何未包含容器的旧应用程序和工作流程从任何虚拟机(VM)迁移到Google Cloud Platform(GCP)? 我的故事是一个遗留的,整体的应用程序,该应用程序在同一磁盘上有一个MongoDB数据库实例,我不得不考虑将应用程序和数据库都移到GCP上。

为什么 (The WHYs)

In most cases, technical decisions should be backed by data or at least strong reasons that could explain the benefits in the absence of data. In my case, it was more of the later, where the effort to maintain the system was no longer sustainable on our older provider. There were other smaller reasons, such as the familiarity I had with using Google Cloud, which was also a valid reason to encourage buy-in to this technical choice.

在大多数情况下,技术决策应有数据支持,或者至少要有强有力的理由可以解释缺乏数据的好处。 就我而言,更多的是后来的情况,维护系统的努力在我们较早的提供商上不再可持续。 还有其他一些较小的原因,例如我对使用Google Cloud的熟悉程度,这也是鼓励购买这种技术选择的正当理由。

In the following, I will detail the entire thought process. For the actual steps on how to migrate a legacy application to a VM in GCP’s Compute Engine, skip to “Executing the migration”

在下文中,我将详细介绍整个思考过程。 有关如何在GCP的Compute Engine中将旧版应用程序迁移到VM的实际步骤,请跳至“执行迁移”

规划迁移 (Planning the migration)

As the saying goes, “If you fail to plan, you plan to fail”. The first step of any migration, big or small, is always going to be making the plan.

俗话说:“如果没有计划,就计划失败”。 无论大小,任何迁移的第一步总是要制定计划。

Kipling’s Method of the 5 Ws and 1 H is one of the great methods I have learned about breaking down the process for the planning. It may be simplistic, but by brainstorming with your team, you can come up with something good.

5 W和1 H的Kipling方法是我学到的关于分解计划过程的绝佳方法之一。 这可能很简单,但是通过与您的团队进行头脑风暴,您可以提出一些好的建议。

pixabay, author: 摄影 ,作者: geralt杰拉特

Let’s use the 5 Ws and 1 H to show how it would be like:

让我们使用5 W和1 H来显示效果:

  • Why are we doing this migration? As explained earlier.

    我们为什么要进行此迁移? 如前所述。

  • Where will we move it to? Google Compute Engine for a similar virtual machine interface.

    我们将其移动到哪里? Google Compute Engine,用于类似的虚拟机界面。

  • How are we doing it? This should be more drawn out, but in a gist — basically, lift and shift the entire application and constituent components into GCP.

    我们如何做? 应该更明确地指出这一点,但要旨-基本上,将整个应用程序和组成组件提升并转移到GCP中。

  • What do we need to migrate? A Node application, configuration, and database dump.

    我们需要迁移什么? 节点应用程序,配置和数据库转储。

  • Who is doing the migration (and are they free to do it)? Me

    谁在进行迁移(他们有空做迁移)?

  • When do we make these changes (and is there enough capacity in the sprint)? ASAP

    我们什么时候进行这些更改(冲刺中是否有足够的容量)? 尽快

From the above, we can already work out some of the tasks required for the migration. Two important notes here are that you can definitely note down more questions to guide the thought process, and it is also good to ask questions where the answers are still uncertain (which would indicate the need for a preliminary investigation).

通过以上内容,我们已经可以算出迁移所需的一些任务。 这里有两个重要的注意事项,您绝对可以记下更多问题以指导思考过程,也可以在答案仍然不确定的地方提出问题(这表明需要进行初步调查)。

解释升降和换挡 (Explaining the lift and shift)

At this point, some of your sentiments less tools, containerizing an application can also simplify the migration process between VMs.

此时,您可以减少一些工具的使用,对应用程序进行容器化还可以简化VM之间的迁移过程。

  • Why not use something like Anthos, which has been pitched as a tool for helping organizations migrate legacy applications to the cloud?

    为什么不使用Anthos之类的东西,它已被用作帮助组织将旧版应用程序迁移到云的工具?

For the first question of containerizing — containerizing and Docker have been a pretty popular concept and tool respectively. In fact, that was one of the first thoughts that ran through my mind, so that we could somewhat modernize the application, isolate the environment, and simplify future setup and deployment processes. This didn’t work out in the end for two reasons — a strict time constraint to migrate the project, and that a rewrite was in the works, making any further improvements temporary and unnecessary.

对于容器化的第一个问题-容器化和Docker分别是非常流行的概念和工具。 实际上,这是我脑海中想到的第一个想法,以便我们可以对应用程序进行某种程度的现代化,隔离环境并简化将来的设置和部署过程。 最终没有解决这个问题有两个原因-迁移项目的严格时间限制,以及正在进行重写,这使得任何进一步的改进都是暂时的和不必要的。

For the second question — Anthos, we were simply not in the targetted group — the subscription service for Anthos was priced for enterprise-grade customers with services with huge resource requirements. There is a pay-as-you-go payment model coming on 1st September 2020, but it is still geared towards huge legacy applications, and migrating ourselves with a VM was a simpler process, by comparison.

对于第二个问题-Anthos,我们根本不在目标群体之内-Anthos的订阅服务是为具有大量资源需求的服务的企业级客户定价的。 2020年9月1日 ,有一种现收现付的付款模式,但是它仍然适用于庞大的旧应用程序,相比之下,使用VM进行迁移是一个更简单的过程。

Before moving on to the migration, I would also like to explain about something I learned from a “Cloud OnBoard”, which can be characterized in the image below:

在继续进行迁移之前,我还想解释一下我从“ Cloud OnBoard”中学到的知识,可以在下图中进行描述:

The Journey In Google Cloud Platform, an image taken from my notes — source: Google Google Cloud Platform之旅,摘自我的笔记的图片-来源:Google

Essentially, this image explains the right “stepping stones” for migration, focusing on legacy applications not hosted on GCP.

本质上,此图说明了迁移的正确“垫脚石”,着重于未托管在GCP上的旧版应用程序。

Instead of skipping right into serverless tools like App Engine and Cloud Functions, steady steps can first be taken to move your applications into VMs with Compute Engine, incrementally shifting it to Kubernetes over time, and then managed with serverless tools if it is desired. This allows any organization to migrate in the most seamless fashion while minimizing the occurrences of any potential outages from shifting the infrastructure too quickly.

与其直接跳到诸如App Engine和Cloud Functions之类的无服务器工具中,不如先采取稳定的步骤将您的应用程序通过Compute Engine移入VM,随着时间的推移将其逐步转移到Kubernetes,然后根据需要使用无服务器工具进行管理。 这使任何组织都可以以最无缝的方式进行迁移,同时最大程度地减少因过快迁移基础架构而引起的任何潜在中断的发生。

执行迁移 (Executing the migration)

The first in the list of things to do is to make a database dump of your database, and then restore this dump using managed database tools like Cloud SQL. For MongoDB in GCP, you can also check out this tool, Another advice I have is to save your application’s configuration to a secure location, which may not be required if you already have tools for config and secrets management (secrets-manager in GCP is a good candidate for this if you need one).

要做的事情首先是对数据库进行数据库转储,然后使用 Cloud SQL之 类的托管数据库工具还原此转储 对于GCP中的MongoDB,您还可以签出此工具 ,我的另一条建议是将应用程序的配置保存到一个安全的位置,如果您已经具有用于配置和秘密管理的工具(GCP中的secrets-manager是如果需要的话,是一个很好的候选人)。

Following that, since we already had the setup process documented for the application (for all installation instructions), we could quickly start the provisioning process. If you don’t have an installation guide or documentation, this would be a good time to start the documentation as you install your dependencies on the VM.

然后,由于我们已经为应用程序记录了安装过程(包括所有安装说明),因此我们可以快速开始配置过程。 如果您没有安装指南或文档,那么这是在将依赖项安装到VM上时开始阅读文档的好时机。

Let’s begin!

让我们开始!

1.创建虚拟机 (1. Creating The Virtual Machine)

Go to the Navigation Menu, click into

Compute Engine > VM instances
. Select the option to create a new instance, and you should see the following:

转到导航菜单,单击进入

Compute Engine > VM instances
。 选择创建新实例的选项,您应该看到以下内容:

In the instance creation menu, there are six important points to note:

在实例创建菜单中,有六点要注意:

  • (In Red) Select the correct region for your VM. The closer it is to the majority of your targetted audience, the better it is for latency. For zone, choose any of them — note that the choice doesn’t matter for now until you use multiple VMs, where each can serve from different zones and act as failovers when downtime is experienced in isolated zones.

    (红色) 为您的VM选择正确的区域。 距离大多数目标受众越近,延迟就越好。 对于区域,请选择它们中的任何一个-请注意,在使用多个VM之前,选择并不重要,在这些VM中,每个VM可以从不同的区域提供服务,并且当在孤立的区域中遇到停机时,可以充当故障转移。

  • (In Blue) Choose the appropriate machine family (General-purpose|Memory-optimized|Compute-optimized). Most use cases would fall under General-purpose, but you can also take a look at this recommendation by GCP on what use cases would fall under which family. Then, choose the machine type, which should be similar to your last VM’s allocated resources. I highly recommend checking out the pricing calculator for an estimation to staying on course with your budget.

    (以蓝色显示) 选择适当的计算机系列 (“通用” |“内存优化” |“计算优化”)。 大多数使用情况将属于通用型,但你也可以看看这个建议什么的用例将其家庭落入下通过GCP。 然后,选择机器类型,该机器类型应与上一个VM分配的资源相似。 我强烈建议您查看价格计算器 以便估算您的预算。

  • (In Yellow) Choose the right Operating System (OS) for your use case. Nothing hurts more than choosing the wrong OS and having to redo this process again.

    (黄色) 为您的用例选择正确的操作系统(OS)。 选择错误的操作系统并再次重做此过程,没有什么比没有伤害的多了。

  • (In Green) If you are not intending to use any Google Cloud APIs, I would suggest selecting the highlighted option, and check what you want to restrict on. The default would work as well if no changes have to be made. These options can be changed later on, where you can vary the service account with assigned permissions (think of this as a machine account and not bound to a user identity).

    (绿色) 如果您不打算使用任何Google Cloud API,建议您选择突出显示的选项,然后检查要限制的内容。 如果不必进行任何更改,则默认设置也将起作用。 这些选项可以在以后更改,您可以在其中更改具有分配的权限的服务帐户(将其视为计算机帐户,而不是绑定到用户身份)。

  • (In Grey) If you are migrating a web application, make sure you select these two options.

    (在灰色中) 如果要迁移Web应用程序,请确保选择这两个选项

  • (In Brown) Click into the highlighted option, and check out “Networking”. Note the default values for VPC networks and subnetworks. While we didn’t cover the creation of new VPC networks and subnetworks (using the default), knowing where to set these values can be useful when you start exploring these areas. Under

    Network Interfaces
    , click the network interface highlighted as default, and you should see the following:

    (以棕色显示)单击突出显示的选项,然后检出“网络”。 请注意VPC网络和子网的默认值。 尽管我们没有介绍如何创建新的VPC网络和子网(使用默认值),但是当您开始探索这些领域时,了解在何处设置这些值会很有用。 在“

    Network Interfaces
    ,单击突出显示为默认值的网络接口,您应该看到以下内容:

  • If you are migrating a web application, click into the

    External IP
    dropdown, where you should see the same in the following image, and reserve a standard static IP address for your application. Once the process is done, you’ll see that in the same
    External IP
    dropdown, the newly reserved static IP address is featured. This should be used for setting up an
    A Record
    from your DNS registrar later on.

    如果要迁移Web应用程序,请单击“

    External IP
    下拉列表,在下图中应该会看到相同的内容,并为应用程序保留标准的静态IP地址。 完成该过程后,您将看到在同一“
    External IP
    下拉列表中,具有新保留的静态IP地址。 稍后,这将用于从DNS注册商处设置
    A Record

Once the above is done, click

Create
at the bottom of the page, to create the instance, and we are done with this first step! If you had reserved a static IP address, and using Ubuntu, you can also visit the IP address directly where you should see the following:

一旦上述完成后,单击

Create
在页面的底部,创建实例,我们正在与这第一步完成! 如果您已经保留了静态IP地址,并且使用Ubuntu,还可以直接访问该IP地址,在该地址中应看到以下内容:

2.安装依赖项 (2. Installing your dependencies)

Going back to Compute Engine, and under VM instances, you should see your new VM instance. To shell into the instance, simply select the corresponding

SSH
option.

回到Compute Engine,在VM实例下,您应该看到新的VM实例。 要封装到实例中,只需选择相应的

SSH
选项。

A shell environment should appear in a new browser pop-up. From here, you can directly run any shell commands or scripts, to retrieve your application code, and for installing your various application’s dependencies. I was able to set up my web application, and even installed the Let’s Encrypt certbot, with a cron job to renew the certificates periodically.

Shell环境应出现在新的浏览器弹出窗口中。 从这里,您可以直接运行任何Shell命令或脚本,以检索您的应用程序代码,以及安装各种应用程序的依赖项。 我能够设置自己的Web应用程序,甚至安装了Let's Encrypt certbot ,并执行了cron作业来定期更新证书。

3.删除不需要的防火墙规则 (3. Removing unneeded firewall rules)

From the Navigation Menu, click into

VPC network > Firewall
. After creating your VM instance, you should see the following:

在导航菜单中,单击进入

VPC network > Firewall
。 创建虚拟机实例后,应该看到以下内容:

If you’re using the different protocols, as seen above, you can ignore the above. However, if you’re not using the Internet Control Message Protocol (ICMP) and Remote Desktop Protocol (RDP), you can delete these firewall rules.

如果您使用的是上述不同的协议,则可以忽略上述内容。 但是,如果您不使用Internet控制消息协议(ICMP)和远程桌面协议(RDP),则可以删除这些防火墙规则。

That’s all, if the above three steps are performed successfully, you should have an application working like mine, as seen in the following chapter.

就是这样,如果成功完成了上述三个步骤,则您的应用程序将像我的一样工作,如下一章所示。

结论 (Conclusion)

After performing the above (and also get the hostname and A-record from my DNS registrar), I was able to get my site working again!

完成上述操作(并从DNS注册商处获得主机名和A记录)后,我就可以使我的网站再次正常工作!

The above was just the first step to move an equivalent application from one VM to another VM in GCP. There are so many more ways to improve the application — for example, performance, try using a managed instance group instead, for features such as load balancing and autoscaling.

以上只是在GCP中将等效应用程序从一个VM迁移到另一个VM的第一步。 有许多改进应用程序的方法-例如,性能,请 尝试使用托管实例组 来实现诸如负载平衡和自动缩放的功能。

On a separate note, if you would like to get familiar with using Google Cloud Platform, without having to pay the price of exploring other tools, I would very much recommend Qwiklabs. It has been a fantastic tool for allowing me to learn a lot more about using GCP — here are some tips on how to supercharge your experience with Qwiklabs and also for getting free access.

另外,如果您想熟悉Google Cloud Platform的使用,而不必付出探索其他工具的代价,那么我非常推荐 Qwiklabs 。 这是一个了不起的工具,它使我可以学习更多有关使用GCP的信息-这里有一些技巧 ,可帮助您充分利用Qwiklabs的经验并获得免费使用权。

This is the first in my “lonely island” series, which I will be updating often on the new, old, and weird stuff I learn along this migration process (along with the rewrite and other tools I am aiming to use). I hope that you have picked up something new, and let me know if there are any parts in this process that I should do better.

这是我的“孤岛”系列文章中的第一篇,我将经常在迁移过程中学习到的新知识,老知识和怪异知识(以及重写和我打算使用的其他工具)上进行更新。 我希望您学到了一些新知识,并让我知道在此过程中是否有任何部分我应该做得更好。

翻译自: https://medium.com/swlh/moving-a-legacy-monolithic-application-from-any-providers-vm-to-google-cloud-platform-gcp-9ff12c22b89b

gcp vm实例 拷贝

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: