以编程方式查找最近的 Apache Software Foundation 镜像 [英] Finding the closest Apache Software Foundation mirror programatically

查看:16
本文介绍了以编程方式查找最近的 Apache Software Foundation 镜像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的部署自动化需求,我想以动态方式和编程方式确定最近的 Apache Software Foundation 镜像,因为服务器分布在不同地理位置的位置,动态确定最佳镜像是理想的,而无需对其进行硬编码某处的知识.

For my deployment automation needs, I would like to dynamically and programatically determine the closest Apache Software Foundation mirror since the servers are distributed across geographically distinct locations and it would be ideal to dynamically determine the best mirror without having to hard-code that knowledge somewhere.

到目前为止我能想到的唯一方法是废弃 http://www.apache.org/dyn/closer.cgi 那里建议的最近镜像页面,但它似乎有点麻烦和脆弱.

The only approach I could think of so far is to scrap the http://www.apache.org/dyn/closer.cgi page for the closest mirror suggested there, but it seems a bit cumbersome and fragile.

是否有以稳定可靠的方式提供此功能的 Web API 端点?

Is there a web API endpoint that provides this functionality in a stable and reliable way?

推荐答案

页面中的镜像URL被标记为<strong>,这样你就可以抓取页面获得top推荐像这样:

The mirror URLs in the page are marked up as <strong>, so you can scrape the page to get the top recommendation like this:

curl 'https://www.apache.org/dyn/closer.cgi' |
  grep -o '<strong>[^<]*</strong>' |
  sed 's/<[^>]*>//g' |
  head -1

另外,closer.cgi 支持 ?as_json=1 查询参数 以提供与 JSON 相同的信息.结果有一个键 preferred 用于最近的镜像,以及 http 用于替代.

Additionally, closer.cgi supports an ?as_json=1 query parameter to provide the same information as JSON. The result has a key of preferred for the closest mirror, as well as http for the alternatives.

这篇关于以编程方式查找最近的 Apache Software Foundation 镜像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆