基於Bandersnatch搭建本地pypi源


基於Bandersnatch搭建本地pypi源

准備工作

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum install libffi-devel -y
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
tar -xvJf Python-3.7.3.tar.xz
cd Python-3.7.3
./configure prefix=/usr/local/python3
make && make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if[ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
source ~/.bash_profile
# 測試
python3 -V
	Python 3.7.3
# pip3 -V
   pip 19.0.3 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)

安裝bandersnatch

# pip3 install bandersnatch
# find / -name master.py
/usr/local/python3/lib/python3.7/site-packages/bandersnatch/master.py
# cp /usr/local/python3/lib/python3.7/site-packages/bandersnatch/master.py{,.bak}
# vim /usr/local/python3/lib/python3.7/site-packages/bandersnatch/master.py
## 生成配置文件
# bandersnatch mirror
2019-05-06 10:30:17,555 WARNING: Config file '/etc/bandersnatch.conf' missing, creating default config.
2019-05-06 10:30:17,555 WARNING: Please review the config file, then run 'bandersnatch' again.
## 修改配置文件/etc/bandersnatch.conf,根據自己的情況修改;
# vim /etc/bandersnatch.conf
[mirror]
; The directory where the mirror data will be stored.
directory = /srv/pypi
; Save JSON metadata into the web tree:
; URL/pypi/PKG_NAME/json (Symlink) -> URL/json/PKG_NAME
json = false

; The PyPI server which will be mirrored.
; master = https://pypi.python.org
; scheme for PyPI server MUST be https
master = https://pypi.python.org
timeout = 30

根據實際情況,重點修改以下兩個配置,directory 指 package 在本地存放的位置(要保證該目錄空間足夠,預留300G以上),master 指被同步的源。

## 下載所有 package 至本地(更新本地的 pacakge也用這個命令)
bandersnatch -c /etc/bandersnatch.conf mirror

通過nginx發布

yum install nginx -y
vim nginx.conf
server {
    listen *:80;
    server_name locahost;
    root /srv/pypi/web;
    autoindex on;
    charset utf-8;
}

測試:http://172.28.88.102/simple/

客戶端測試

# cat ~/.pip/pip.conf
[global]
trusted-host=172.28.88.102
index-url=http://172.28.88.102/simple

# pip install baker
# pip list  | grep Baker
Baker (1.3)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM