简体   繁体   English

有没有办法通过 Azure 从 web 应用程序在 VM 上运行脚本?

[英]Is there a way to run a script on a VM from a web app with Azure?

I have a web app that is hosted on one account, and another account which has a VM.我有一个托管在一个帐户上的 web 应用程序,以及另一个具有 VM 的帐户。 I want to be able to run the script on that VM by clicking on a button on the web app and return its output.我希望能够通过单击 web 应用程序上的按钮并返回其 output 来在该 VM 上运行脚本。 I'm confused as to whether or not I'll need Vnet-Vnet gateway connection or how to approach this problem?我对是否需要 Vnet-Vnet 网关连接或如何解决此问题感到困惑?

There can be multiple ways to approach the problem depending upon what kind of environment the webapp is hosted on.根据 webapp 所在的环境,可以有多种方法来解决问题。

Approach One:方法一:

If you are willing to move the webapp to a docker container then we can install infrastructure orchestration tool like ansible in the container which will be the host machine.如果您愿意将 webapp 移动到 docker 容器,那么我们可以在将作为主机的容器中安装基础架构编排工具,例如ansible So now, when you click the button on the webapp you can run a process in the container.ie ansible playbook and run the script on the remote machine.所以现在,当您单击 webapp 上的按钮时,您可以在容器中运行一个进程。即 ansible 剧本并在远程机器上运行脚本。

Approach Two:方法二:

On the virtual machine we write a webapp which can provide an api or socket connection to trigger the script.在虚拟机上,我们编写了一个 webapp,它可以提供一个 api 或套接字连接来触发脚本。 From the webapp you hit that api.从您点击 api 的 web 应用程序。

Networking Aspect:网络方面:

Whether you write follow approach one or two you need to have a mechanism to communicate between the two services.无论您编写遵循方法一还是二,您都需要有一种机制在两个服务之间进行通信。 If both machines have a public IP then you can withlist the IP:PORT you are using for communication.如果两台机器都有一个公共 IP,那么您可以列出您用于通信的 IP:PORT。 But if that's not the case and both are in two private vnet's then you have a couple of options building a VPN gateway, Vnet-Vnet peering or Using an Express Route.但如果不是这种情况,并且两者都在两个私有 vnet 中,那么您有几个选项可以构建 VPN 网关、Vnet-Vnet 对等互连或使用 Express Route。

You can also explore the option of triggering a workflow within Azure Logic apps from your web app which in turn executes an Azure dev ops pipeline.您还可以从 web 应用程序中探索在 Azure 逻辑应用程序中触发工作流的选项,该应用程序依次执行 Azure 开发操作管道。 The integration will be much easy to do as per above as all the components will be available to you natively.如上所述,集成将非常容易,因为所有组件都将在本机上提供给您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM