镜像站

配置方法

CentOS

  • CentOS 7 通过默认配置自动选择镜像源,一般不需要再手动配置
  • 如果系统更新了 centos-release 包,已做的修改会被覆盖,需要重新配置
    1. cd /etc/yum.repos.d && mkdir -p bak
    2. mv -f *.repo bak
    3. curl -so /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tencent.com/repo/centos7_base.repo
    4. yum clean all
    5. yum makecache
    ```bash

    挂载镜像文件

    mount -t iso9660 -o ro /dev/sr0 /media

新建 cdrom.repo 文件

cat > /etc/yum.repo.d/cdrom.repo << EOF [cdrom] name=cdrom baseurl=file:///media gpgcheck=0 EOF

yum clean all yum makecache

  1. ```bash
  2. cd /etc/yum.repos.d && mkdir -p bak
  3. mv -f *.repo bak
  4. # 定界符 EOF 加引号以关闭文本中的变量扩展
  5. cat > local.repo << 'EOF'
  6. [local-base]
  7. name=local-$releasever - Base
  8. baseurl=http://192.168.88.45/centos/$releasever/os/$basearch/
  9. gpgcheck=0
  10. [local-updates]
  11. name=local-$releasever - Updates
  12. baseurl=http://192.168.88.45/centos/$releasever/updates/$basearch/
  13. gpgcheck=0
  14. [local-extras]
  15. name=local-$releasever - Extras
  16. baseurl=http://192.168.88.45/centos/$releasever/extras/$basearch/
  17. gpgcheck=0
  18. [local-centosplus]
  19. name=local-$releasever - Plus
  20. baseurl=http://192.168.88.45/centos/$releasever/centosplus/$basearch/
  21. gpgcheck=0
  22. EOF
  23. yum clean all
  24. yum makecache
  25. # 切换镜像源
  26. sed -i 's#//[^/]*/#//192.168.88.45/#' /etc/yum.repos.d/local.repo
  27. sed -i 's#//[^/]*/#//mirrors.aliyun.com/#' /etc/yum.repos.d/local.repo

Ubuntu

  1. sudo cp /etc/apt/sources.list{,.orig}
  2. sudo sed -i.bak "s#//.*/ubuntu#//mirrors.ustc.edu.cn/ubuntu#" /etc/apt/sources.list
  3. sudo apt-get clean all
  4. sudo apt-get update

Docker

更换 Docker Hub 镜像源

  1. mkdir -p /etc/docker
  2. cat > /etc/docker/daemon.json << EOF
  3. {
  4. "registry-mirrors": [
  5. "https://hub-mirror.c.163.com",
  6. "https://mirror.baidubce.com"
  7. ]
  8. }
  9. EOF

重启服务

  1. systemctl daemon-reload
  2. systemctl restart docker

Homebrew

TODO