21

国内开发资源镜像一览 - DTeam 团队日志

 4 years ago
source link: https://blog.dteam.top/mirrors.html?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

本页面记录我们团队开发环境中的使用国内镜像站加速的配置参考,便于快速配置开发环境使用的镜像站,一些相关的详细参考内容会以参考资料形式给出。

本文以全局镜像配置为主,即配置在全局的路径下,所有的项目均受影响。像 Maven, Gradle 之类的工具支持项目单独定义镜像仓库,并不在本文涉及的内容中。

镜像配置列表:

Gradle

创建目录~/.gradle/init.d(Unix/Linux 环境)或%USERPROFILE%\.gradle\init.d(Windows 环境),写入以下两个文件:

  • repo.gradle:

    allprojects {
        buildscript {
            repositories {
                maven { url "https://repo.huaweicloud.com/repository/maven" }
            }
        }
    
        repositories {
            maven { url "https://repo.huaweicloud.com/repository/maven" }
        }
    
        gradle.projectsEvaluated {
            tasks.withType(JavaCompile) {
                options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
            }
            tasks.withType(GroovyCompile) {
                options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
            }
        }
    }
    
  • pluginManagement.gradle (只对Gradle 2.1及以上版本使用新的plugins {}DSL 部分有效):

    settingsEvaluated { settings ->
        settings.pluginManagement {
            repositories {
                maven { url "https://repo.huaweicloud.com/repository/maven" }
                gradlePluginPortal()
            }
        }
    }
    

: gradle 使用镜像站下载依赖的时候可能会出现镜像站还未缓存完毕依赖,从而下载依赖的时候出错,导致 task 失败退出的情况。如果遇到这种情况,等待镜像站缓存完毕,加上--refresh-dependencies参数重新运行一次 task 即可,如:

./gradlew --refresh-dependencies build

参考资料:

Maven

创建~/.m2/settings.xml(Linux/Unix 环境)或%USERPROFILE%\.m2\settings.xml(Windows 环境)文件,写入以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <mirrors>
    <mirror>
      <id>huaweicloud</id>
      <mirrorOf>*</mirrorOf>
      <url>https://repo.huaweicloud.com/repository/maven</url>
    </mirror>
  </mirrors>
</settings>

参考资料:

Groovy Grape

创建~/.groovy/grapeConfig.xml(Linux/Unix 环境)或%USERPROFILE%\.groovy\grapeConfig.xml(Windows 环境)文件,写入以下内容:

<ivysettings>
  <settings defaultResolver="downloadGrapes"/>
  <resolvers>
    <chain name="downloadGrapes" returnFirst="true">
      <filesystem name="cachedGrapes">
        <ivy pattern="${user.home}/.groovy/grapes/[organisation]/[module]/ivy-[revision].xml"/>
        <artifact pattern="${user.home}/.groovy/grapes/[organisation]/[module]/[type]s/[artifact]-[revision](-[classifier]).[ext]"/>
      </filesystem>
      <ibiblio name="localm2" root="${user.home.url}/.m2/repository/" checkmodified="true" changingPattern=".*" changingMatcher="regexp" m2compatible="true"/>
      <ibiblio name="huawei" root="https://mirrors.huaweicloud.com/repository/maven" m2compatible="true"/>
    </chain>
  </resolvers>
</ivysettings>

参考资料:

配置环境变量:

  • NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node
  • NVM_IOJS_ORG_MIRROR=http://npm.taobao.org/mirrors/iojs

参考资料:

执行命令:

npm config set registry https://registry.npm.taobao.org
npm config set disturl https://npm.taobao.org/dist
npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass
npm config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs
npm config set chromedriver_cdnurl https://npm.taobao.org/mirrors/chromedriver
npm config set operadriver_cdnurl https://npm.taobao.org/mirrors/operadriver
npm config set electron_mirror https://npm.taobao.org/mirrors/electron/
npm config set python_mirror https://npm.taobao.org/mirrors/python
npm config set electron_builder_binaries_mirror https://npm.taobao.org/mirrors/electron-builder-binaries/
npm config set node_sqlite3_binary_host_mirror https://npm.taobao.org/mirrors

手改~/.npmrc或设置等效的环境变量均有效。

特别注意,如果想要发布 npm 包到中央仓库,必须先取消设置registry,发布完毕之后再改回来:

# 发布中央仓库之前必须取消registry镜像设置
npm config delete registry

# 发布完毕再把registry镜像加回来
npm config set registry https://registry.npm.taobao.org

参考资料:

执行命令:

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

参考资料:

Anaconda

执行命令:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --set show_channel_urls yes

修改.condarc配置文件可以达成同样的效果,参考下方参考资料。

参考资料:

Vagrant

通过镜像站安装插件:

vagrant plugin install --plugin-clean-sources --plugin-source https://gems.ruby-china.com/ <plugin>...

vagrant-vbguest下载 VBoxGuestAdditions 镜像(修改Vagrantfile):

config.vbguest.iso_path = "https://mirrors.tuna.tsinghua.edu.cn/virtualbox/%{version}/VBoxGuestAdditions_%{version}.iso"

通过镜像站下载 box:

# Ubuntu镜像
vagrant init ubuntu-bionic https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/bionic/current/bionic-server-cloudimg-amd64-vagrant.box

# Centos镜像
vagrant init centos7 https://mirrors.ustc.edu.cn/centos-cloud/centos/7/vagrant/x86_64/images/CentOS-7.box

也可以修改Vagrantfileconfig.vm.box_url = "box文件的url"

参考资料:

rustup

设置环境变量:

  • RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup

crates.io 索引镜像

写入配置文件~/.cargo/config:

[source.crates-io]
replace-with = 'ustc'

[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

参考资料:

注意:如果在 cargo build 时报下面的错误:

warning: spurious network error (2 tries remaining): [6] Couldn’t resolve host name (Could not resolve host: crates)

那么,添加环境变量:CARGO_HTTP_MULTIPLEXING=false(要 export)。

Docker Hub

中科大提供了公开的 Docker Hub 仓库镜像,以下配置以中科大为例。其他国内的云厂商如阿里云华为云等等都提供了 Docker Hub 镜像,需要用户自行注册账号,并且手工开通,使用是免费的。如果期望使用云厂商免费的 Docker Hub 镜像,替换下面的镜像地址为云厂商分配给用户的加速地址即可。

Linux

/etc/docker/daemon.json中加入:

{
  "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/"]
}

重启服务即可。

MacOS

  1. 打开 “Docker.app”
  2. 进入偏好设置页面(快捷键 ⌘, )
  3. 打开 “Daemon” 选项卡
  4. 在 “Registry mirrors” 中添加 https://docker.mirrors.ustc.edu.cn/
  5. 点击下方的 “Apply & Restart” 按钮

Windows

在系统右下角托盘 Docker 图标内右键菜单选择 Settings ,打开配置窗口后左侧导航菜单选择 Daemon 。在 Registry mirrors 一栏中填写地址 https://docker.mirrors.ustc.edu.cn/ ,之后点击 Apply 保存后 Docker 就会重启并应用配置的镜像地址了。

参考资料:

Julia

创建 ~/.julia/config/startup.jl 文件,写入以下内容:

using Pkg
pkg"activate ."
pkg"registry add https://mirrors.ustc.edu.cn/julia/registries/General.git"
pkg"instantiate"

参考资料:

github

使用Fast Git镜像,可安装此油猴脚本获取最新地址。

以 spaCy 的 en_core_web_lg model (模型没有 pip 镜像)安装为例,使用镜像下载的例子如下:

pip install https://download.fastgit.org/explosion/spacy-models/releases/download/en_core_web_lg-2.2.5/en_core_web_lg-2.2.5.tar.gz

作为对比,试试官方文档中的安装命令:

python -m spacy download en_core_web_lg

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK