cat > /etc/apt/sources.list << EOF
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse
EOF
apt update
apt install python-pip -y
pip install --upgrade pip==20.0.1
pip install pip2pi
pip install pypiserver
# 上传需要密码
pip install passlib
apt install apache2-utils -y
# 创建用户deepwise 密码deepwise
htpasswd -b -c /root/.pypipasswd deepwise deepwise
# 创建文件夹
mkdir -p /var/pip-deepwise/
# 启动
# 当请求的Python包, 在本地 *pypiserver* 上没有找到时, 它会将请求转发到外部PyPI源, 默认为 https://pypi.doubanio.com/simple . 对于国内使用来说, 可以通过 `--fallback-url` 参数将转发目的地址设置为豆瓣源
nohup pypi-server -p 9898 -P /root/.pypipasswd --fallback-url https://pypi.doubanio.com/simple /var/pip-deepwise/ &
# nohup pypi-server -p 9898 -P /root/.pypipasswd --fallback-url https://pypi.tuna.tsinghua.edu.cn/simple /var/pip-deepwise/ &
单独下载指定版本的routes包
pip2tgz /var/pip-deepwise/ routes==1.12.3
批量下载软件包
# 会下载到/var/pip-deepwise/
pip2tgz /var/pip-deepwise/ -r list/requirements.txt
建立索引
# 建立索引后会/var/pip-deepwise/simple下显示
dir2pi /var/pip-deepwise/
更新索引
pip2acmeco uliweb=0.2.6
pip2acmeco -r list/requirements.txt
apt install nginx -y
cat > /etc/nginx/sites-enabled/default << EOF
server {
listen 80;
server_name localhost;
root /var/pip-deepwise;
# root /pip-link;
location / {
autoindex on;
autoindex_exact_size off; #显示文件的大小
autoindex_localtime on; #显示文件时间
#limit_rate_after 5m; #5分钟后下载速度限制为200k
limit_rate 200k;
}
access_log /var/log/nginx/pip-deepwise.log ;
}
EOF
nginx -t
nginx -s reload
# 避免autoindex首页显示tar.gz包
# mkdir -p /pip-link
#ln -s /var/pip-deepwise/simple /pip-link/
安装
pip install -i http://192.168.10.84:9898/ routes --trusted-host 192.168.10.84
客户端pip设置
cat .pip/pip.conf
[global]
trusted-host = 172.16.1.1
index-url = http://172.16.1.1:8080/simple
客户端配置,不存在则新建
vim ~/.pypirc
添加如下内容(填入正确的地址和帐号密码,假设服务器地址为192.168.0.2)
[distutils]
index-servers =
local
[local]
repository: http://192.168.0.2:9898
username: username
password: passwd
开机启动
cat /etc/rc.local |egrep -v "^#|^$"
pypi-server /python-packages &>/var/log/pypi-server.log &
exit 0