1、 知识准备

1、1 为什么要搭建Pypi镜像站


1、2 如何搭建Pypi开源镜像站




2、1 环境准备

2、1、1 硬件准备


2、1、2 安装bandersnatch

本次教程在Debian 9下测试通过



apt install virtualenv


virtualenv --python=python3.5 bandersantch


cd bandersantch && bin/pip install bandersantch

* 如果安装出错,考虑是否需要升级pipsetuptools。升级命令pip install -U pip && pip install -U setuptools

2、1、3 修改配置文件

一般,安装之后不会出现配置文件。运行bin/bandersnatch mirror(在虚拟环境目录下)就会在/etc目录下生成bandersnatch.conf文件。这是,我们需要修改一下此文件。

; The directory where the mirror data will be stored.
directory = /srv/pypi

; The PyPI server which will be mirrored.
; master =
; scheme for PyPI server MUST be https
master =
;master =
;master =
;master =

; The network socket timeout to use for all connections. This is set to a
; somewhat aggressively low value: rather fail quickly temporarily and re-run
; the client soon instead of having a process hang infinitely and have TCP not
; catching up for ages.
timeout = 10

; Number of worker threads to use for parallel downloads.
; Recommendations for worker thread setting:
; - leave the default of 3 to avoid overloading the pypi master
; - official servers located in data centers could run 10 workers
; - anything beyond 10 is probably unreasonable and avoided by bandersnatch
workers = 3

; Whether to hash package indexes
; Note that package index directory hashing is incompatible with pip, and so
; this should only be used in an environment where it is behind an application
; that can translate URIs to filesystem locations.  For example, with the
; following Apache RewriteRule:
;     RewriteRule ^([^/])([^/]*)/$ /mirror/pypi/web/simple/$1/$1$2/
;     RewriteRule ^([^/])([^/]*)/([^/]+)$/ /mirror/pypi/web/simple/$1/$1$2/$3
; Setting this to true would put the package 'abc' index in simple/a/abc.
; Recommended setting: the default of false for full pip/pypi compatability.
hash-index = false

; Whether to stop a sync quickly after an error is found or whether to continue
; syncing but not marking the sync as successful. Value s; Whether or not files that have been deleted on the master should be deleted
; on the mirror, too.
; IMPORTANT: if you are running an official mirror than you *need* to leave
; this on.
delete-packages = true

; Advanced logging configuration. Uncomment and set to the location of a
; python logging format logging config file.
; log-config = /etc/bandersnatch-log.conf

; vim: set ft=cfg:
hould be "true" or
; "false".
stop-on-error = false


2、1、4 同步镜像

切换到bandersnatch虚拟环境目录,重新运行bin/bandersnatch mirror命令,即可开始Pypi的同步。