企业内网利用devpi搭建pypi私服

安装devpi

概述

devpi包含三个组件:

  • devpi-server: 提供镜像与缓存功能,在企业DMZ区部署,提高下载python package的效率
  • devpi-web: 提供web界面与查询功能
  • devpi-client: 命令行工具, 提供包上传等功能

devpi-server

# 若devpi-server与互联网不通,可通过设置代理来安装
# pip --proxy http://proxy_server:3128 install -q -U devpi-server

pip install -q -U devpi-server
devpi-server --version

初始化与初次启动

devpi-server --init
devpi-server --start

测试

pip install -i http://localhost:3141/root/pypi/ simplejson
pip uninstall -y simplejson
easy_install -i http://localhost:3141/root/pypi/+simple/ simplejson
pip uninstall -y simplejson

devpi-web

pip install -q -U devpi-web
devpi-server --stop
devpi-server --recreate-search-index
devpi-server --start
pip search --index http://localhost:3141/root/pypi/ devpi-client

常用命令

devpi-server --init
devpi-server --start
devpi-server --stop
devpi-server --status
devpi-server --log

devpi behind proxy

export http_proxy="http://proxy_server:3128"
export https_proxy="http://proxy_server:3128"
export no_proxy="localhost,10.0.0.0/8,172.16.0.0/12"
devpi-server --start

nginx reverse proxy

# http block
upstream pypi.example.com {
    server 127.0.0.1:3141;
    keepalive 16;
}

# server block
location ~ /(root|\+search) {
        proxy_pass http://pypi.example.com;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

客户端设置

pip

# Linux:       $HOME/.pip/pip.conf
# Windows 7:   C:\ProgramData\pip\pip.ini
# windows xp:  C:\Documents and Settings\All Users\Application Data\pip\pip.ini
# or use environment variable PIP_CONFIG_FILE to specify location

# please replace example.com to your REAL domain name

[global]
index-url = http://pypi.example.com/root/pypi/+simple/

[install]
trusted-host=pypi.example.com

[search]
index = http://pypi.example.com/root/pypi/

easy_install

# $HOME/.pydistutils.cfg:
[easy_install]
index_url = http://pypi.example.com/root/pypi/+simple/

参考

    原文作者:田园牧歌w
    原文地址: https://www.jianshu.com/p/cc600c36e549
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞