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

查看:58
本文介绍了以编程方式查找最近的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>,因此您可以抓取页面以获得如下最佳推荐:

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天全站免登陆