TLDR:有没有办法运行 git 克隆 [url]
,并且 URL 仅为 git 命令临时硬编码?
我遇到了这样一种情况:云中的托管环境(Azure、AWS 等)可以被销毁,然后在短时间内(例如 10 分钟内)使用相同的名称重新创建。这会导致重复使用 DNS 名称(即 mycoolwebsite.azurewebsites.com)。
指向该 DNS 名称执行 git clone/git push 的命令不可避免地会导致失败,因为计算机上缓存的 DNS 条目现已过时,因为重新创建的环境可能位于不同的外部 IP 后面。
通过云托管提供商工具,我可以查询外部 IP 并对 /etc/hosts
进行注入(inject)/pop 。这是一个有效的解决方法,但由于多种原因,它是一个“坏主意”。我无法轻松地将 IP 指向端点,因为服务器不会响应裸 IP,而只会响应主机名(根据我收集到的信息)。
我想很多人在云中打开和销毁开发实例时都遇到过这种情况 - 有没有更好的方法来处理基本上是 DNS 缓存问题?
最佳答案
@david说,在AWS中,你可以选择弹性IP。在 Azure 上,您可以关联 static Public IP到虚拟机。
根据您的情况,您可以取消 IP 到原始 VM 的映射,并将 IP 关联到新 VM。 IP地址不会改变。
更新:
您可以使用Azure Cli 2.0取消公共(public) IP 的关联或将公共(public) IP 与虚拟机关联。您可以引用下面的例子:
##chang publci from dynamic to Static
az network public-ip update -g shuitest -n shui-ip --allocation-method Static
##disassoicat PublicIP from a VM
az network nic ip-config update --resource-group shuitest --nic-name shui7 --name ipconfig1 --public-ip ""
##add the Publci IP to new VM
az network nic ip-config update --resource-group shuitest --nic-name shui7 --name ipconfig1 --public-ip "shui-ip"
您可以使用-h
来获取帮助。
[root@localhost .ssh]# az network nic ip-config update -h
Command
az network nic ip-config update: Update an IP configuration.
关于linux - 使用自定义 DNS 运行 `git clone`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43748372/