侧边栏壁纸
博主头像
阿里灰太狼博主等级

You have to believe in yourself . That's the secret of success.

  • 累计撰写 104 篇文章
  • 累计创建 50 个标签
  • 累计收到 12 条评论

目 录CONTENT

文章目录

常见软件镜像设置

阿里灰太狼
2022-03-24 / 0 评论 / 2 点赞 / 513 阅读 / 11,134 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-03-24,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

常见软件镜像设置

用于设置常用软件的国内镜像,以便加速下载资源。国内提供的镜像站点。

测速

系统软件源测速

curl -sSL https://cdn.jsdelivr.net/gh/lework/script/shell/os_repo_speed_test.sh bash

Docker hub 测速

curl -sSL https://cdn.jsdelivr.net/gh/lework/script/shell/docker_hub_speed_test.sh bash

centos

sed -e 's!^#baseurl=!baseurl=!g' \
       -e  's!^mirrorlist=!#mirrorlist=!g' \
       -e 's!mirror.centos.org!mirrors.ustc.edu.cn!g' \
       -i  /etc/yum.repos.d/CentOS-Base.repo

yum install -y epel-release
sed -e 's!^mirrorlist=!#mirrorlist=!g' \
	-e 's!^#baseurl=!baseurl=!g' \
	-e 's!^metalink!#metalink!g' \
	-e 's!//download\.fedoraproject\.org/pub!//mirrors.ustc.edu.cn!g' \
	-e 's!http://mirrors\.ustc!https://mirrors.ustc!g' \
	-i /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo

debain

cp /etc/apt/sources.list{,-bak}
cat > /etc/apt/sources.list <<EOF
deb http://mirrors.aliyun.com/debian/ stretch main
deb-src http://mirrors.aliyun.com/debian/ stretch main
deb http://mirrors.aliyun.com/debian/ stretch-updates main
deb-src http://mirrors.aliyun.com/debian/ stretch-updates main
deb http://mirrors.aliyun.com/debian-security stretch/updates main
deb-src http://mirrors.aliyun.com/debian-security stretch/updates main
EOF
apt-get update

也可以直接替换源

sudo sed -e 's/deb.debian.org/mirrors.163.com/g' \
  -e 's#security.debian.org#mirrors.163.com/debian-security#g' \
  -i /etc/apt/sources.list

debian archive

debian 旧版本系统(2[hamm ]-7[wheezy])源都放在 debian-archive 中,

cp /etc/apt/sources.list{,-bak}
cat << EOF > /etc/apt/sources.list
deb http://mirrors.163.com/debian-archive/debian/ wheezy main non-free contrib
deb http://mirrors.163.com/debian-archive/debian/ wheezy-backports main non-free contrib
deb-src http://mirrors.163.com/debian-archive/debian/ wheezy main non-free contrib
deb-src http://mirrors.163.com/debian-archive/debian/ wheezy-backports main non-free contrib
deb http://mirrors.163.com/debian-archive/debian-security/ wheezy/updates main non-free contrib
deb-src http://mirrors.163.com/debian-archive/debian-security/ wheezy/updates main non-free contrib
EOF

apt-get -o Acquire::Check-Valid-Until=false update

ubuntu

sudo sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list

alpine

sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

freebsd

pkg 软件源

# /usr/local/etc/pkg/repos/FreeBSD.conf
FreeBSD: {
  url: "pkg+http://mirrors.ustc.edu.cn/freebsd-pkg/${ABI}/latest",
}

pkg update -f

ports 软件源

# /etc/make.conf

MASTER_SITE_OVERRIDE?=http://mirrors.ustc.edu.cn/freebsd-ports/distfiles/${DIST_SUBDIR}/

pip

使用 pip 的时候在后面加上-i 参数,指定 pip 的下载源

pip install numpy -i https://mirrors.aliyun.com/pypi/simple

上面命令每次运行需要指定网址,可进行永久修改:

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

windows 下: 在 user 目录中创建一个 pip 目录,如:C:\Users(用户)\xx\pip,新建文件 pip.ini,内容如下

[global]
index-url = https://mirrors.aliyun.com/pypi/simple

linux 下: 修改 ~/.pip/pip.conf (如果没有自己创建一个), 内容如下:

[global]
index-url = https://mirrors.aliyun.com/pypi/simple

easy_install

cat >> ~/.pydistutils.cfg  <<EOF
[easy_install]
index-url = https://mirrors.aliyun.com/pypi/simple
EOF

ruby

gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
bundle config mirror.https://rubygems.org https://gems.ruby-china.com

npm

npm config set registry https://registry.npm.taobao.org
npm config list

yarn

yarn config set registry https://registry.npm.taobao.org
yarn config list

go

  1. 使用 go1.11 以上版本并开启 go module 机制
  2. 导出 GOPROXY 环境变量
export GO111MODULE=on
export GOPROXY=https://mirrors.aliyun.com/goproxy/

jenkins

游览器访问 jenkins,例如: [http://localhost:8080/pluginManager/advanced]

选择一个国内源:

docker-ce

CentOS/RHEL

curl -o /etc/yum.repos.d/docker-ce.repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
sed -i 's#download.docker.com#mirrors.ustc.edu.cn/docker-ce#g' /etc/yum.repos.d/docker-ce.repo

Debian

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
sudo add-apt-repository \
   "deb [arch=amd64] http://mirrors.ustc.edu.cn/docker-ce/linux/debian \
   $(lsb_release -cs) \
   stable"
sudo apt-get update
sudo apt-get install docker-ce

Ubuntu

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
   "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
sudo apt-get update
sudo apt-get install docker-ce

docker

docker 客户端

指定registry-mirrors

cp  /etc/docker/daemon.json{,-bak}
cat > /etc/docker/daemon.json <<EOF
{
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "100m",
        "max-file": "3"
    },
    "live-restore": true,
    "max-concurrent-downloads": 10,
    "max-concurrent-uploads": 10,
    "storage-driver": "overlay2",
    "storage-opts": [
        "overlay2.override_kernel_check=true"
    ],
    "exec-opts": ["native.cgroupdriver=systemd"],
    "registry-mirrors": [
        "http://hub-mirror.c.163.com"
    ]
}
EOF

可以通过脚本进行测速在选择镜像站点

curl -sSL https://git.io/dspeed bash

docker.io 镜像加速

dockerhub.azk8s.cn 只能内部使用了

docker pull dockerhub.azk8s.cn/library/centos

gcr.io 镜像加速

gcr.azk8s.cn 只能内部使用了

docker pull gcr.azk8s.cn/google_containers/kube-apiserver:v1.16.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.16.3

quay.io 镜像加速

quay.azk8s.cn 只能内部使用了

docker pull quay.azk8s.cn/coreos/kube-state-metrics:v1.7.2

也可以使用脚本自动下载镜像

# 下载gcr镜像
curl -sSL https://git.io/getgcr bash -s gcr.io/google_containers/kube-apiserver:v1.16.3

# 下载k8s镜像
curl -sSL https://git.io/getgcr bash -s k8s.gcr.io/pause-amd64:3.1

# 指定k8s版本,下载全套件
curl -sSL https://git.io/getgcr bash -s - -t v1.16.3

# 下载quay.io镜像
curl -sSL https://git.io/getgcr bash -s quay.io/coreos/kube-state-metrics:v1.7.2

docker HTTP/HTTPS 代理

mkdir /etc/systemd/system/docker.service.d/

cat << EOF > /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:8123/"
Environment="HTTPS_PROXY=https://127.0.0.1:8123/"
EOF

systemctl daemon-reload
systemctl restart docker

containerd

registry代理

生成默认配置

containerd config default > /etc/containerd/config.toml

将registry.mirrors替换成代理的

    [plugins.cri.registry]
      [plugins.cri.registry.mirrors]
        [plugins.cri.registry.mirrors."docker.io"]
          endpoint = ["https://registry-1.docker.io"]
sed -i 's#https://registry-1.docker.io#https://docker.mirrors.ustc.edu.cn#g' /etc/containerd/config.toml

http代理

# /usr/lib/systemd/system/containerd.service
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target

[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd
KillMode=process
Delegate=yes
LimitNOFILE=1048576
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
Environment="HTTP_PROXY=http://127.0.0.1:8123/"

[Install]
WantedBy=multi-user.target

podman

cp /etc/containers/registries.conf{,.bak}
cat > /etc/containers/registries.conf << EOF
unqualified-search-registries = ["docker.io"]

[[registry]]
prefix = "docker.io"
location = "uyah70su.mirror.aliyuncs.com"
EOF

kubernetes

Debian / Ubuntu

apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl

CentOS / RHEL / Fedora

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
setenforce 0
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet && systemctl start kubelet

google-containers

gcr hub 代理

k8sgcr.lework.workers.dev ===> k8s.gcr.io
k8sgcr.lework.workers.dev/coredns:1.7.0 === k8s.gcr.io/coredns:1.7.0 

gcr.lework.workers.dev ===> gcr.io
gcr.lework.workers.dev/google-containers/coredns:1.7.0 === gcr.io/google-containers/coredns:1.7.0 

registry.aliyuncs.com/k8sxio ===> k8s.gcr.io
registry.aliyuncs.com/k8sxio/coredns:1.7.0 === k8s.gcr.io/coredns:1.7.0

cygwin

选择 Install from Internet, 在”User URL”处输入以下地址:

https://mirrors.tuna.tsinghua.edu.cn/cygwin/

maven

maven 的 settings.xml

<mirrors>
<mirror>
    <id>aliyunmaven</id>
    <mirrorOf>*</mirrorOf>
    <name>阿里云公共仓库</name>
    <url>https://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>

maven 项目的pom.xml

<repositories>
    <repository>
        <id>nexus-163</id>
        <name>Nexus 163</name>
        <url>http://mirrors.163.com/maven/repository/maven-public/</url>
        <layout>default</layout>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>nexus-163</id>
        <name>Nexus 163</name>
        <url>http://mirrors.163.com/maven/repository/maven-public/</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </pluginRepository>
</pluginRepositories>

gradle

build.gradle 文件

allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/public/' }
        mavenLocal()
        mavenCentral()
    }
}

NuGet

选择工程-》NuGet 包管理器-》程序包管理器设置

https://nuget.cdn.azure.cn/v3/index.json
https://repo.huaweicloud.com/repository/nuget/v3/index.json

Hex

export HEX_MIRROR="https://hexpm.upyun.com"
export HEX_CDN="https://hexpm.upyun.com"

github

仅限访问和下载,请不要提交账号信息,需保护自己的隐私。

https://gh.lework.workers.dev  # 对github clone、release、archive以及项目文件进行加速

Release、Code(ZIP) 文件加速:

https://gh.con.sh | 美国 01
https://gh.api.99988866.xyz | 美国 02
https://download.fastgit.org | 日本东京
https://g.ioiox.com | 中国香港 (估计 10M 小水管,但稳定,不会动不动下载中断,算是备用
https://git.yumenaka.net | 美国洛杉矶(晚上时比前面两个美国的更快

Git Clone 加速:

https://hub.fastgit.org | 中国香港
https://gitclone.com | 中国浙江杭州
https://github.com.cnpmjs.org | 新加坡

Raw 文件加速:

https://cdn.jsdelivr.net | 中国国内
https://raw.fastgit.org | 中国香港
https://git.yumenaka.net | 美国洛杉矶

前端开源项目 CDN


Wiki 地址:常见软件镜像设置

2

评论区