基于Bandersnatch搭建本地pypi源

1、安装python3

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

# 将/usr/local/python3/bin加入PATH

# 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

按ESC,输入:wq回车退出。

修改完记得执行行下面的命令,让上一步的修改生效:

# source ~/.bash_profile

检查Python3及pip3是否正常可用:

# 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)

2、安装Bandersnatch

Bandersnatch 是一个用于同步 pypi 源的工具,采用它下载和同步官网所有 package 到本地,最后由 nginx 发布

# 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
根据实际情况,重点修改以下两个配置,directory 指 package 在本地存放的位置(要保证该目录空间足够,预留300G以上),master 指被同步的源。

# 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

下载所有 package 至本地(更新本地的 pacakge也用这个命令)

bandersnatch -c /etc/bandersnatch.conf mirror

3、安装 nginx

yum install nginx -y

更改nginx.conf的配置文件

server {
    listen *:80;
    server_name locahost;
    root /srv/pypi/web;
    autoindex on;
    charset utf-8;
}

打开网页查看是否正常:

http://172.28.88.102/simple/

4、测试客户端

在另一台服务器配置pip的地址

# 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)
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值