pypiserver 搭建

1. 通過 pip 安裝 pip server

$ pip install pypiserver

2. 安裝 周邊服務

$ pip install passlib

3. 設置密碼

$ yum install httpd-tools

# 生成密碼文件
$ htpasswd -c /root/.pypipasswd tomorrow
password:
password agin:

4. 使用 systemd 管理 pypiserver

$ tee /usr/lib/systemd/system/pypi.service <<-'EOF'
[Unit]
Description=pypi-server daemon
After=network.target

# -P 使用密碼文件,-a update,download 更新,下載都需要密碼驗證
[Service]
ExecStart=/usr/local/bin/pypi-server \
    -p 8080 \
    -P /root/.pypipasswd -a update,download \
    -r /var/www/pypi \
    --log-file /var/log/pypi/pypi.log
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target
EOF

# 創建 pypi 及 log 路徑

$ mkdir -p /var/www/pypi
$ mkdir -p /var/log/pypi

5. 啟動 pypiserver

$ systemctl daemon-reload
$ systemctl start pypi
$ systemctl status pypi
● pypi.service - pypi-server daemon
   Loaded: loaded (/etc/systemd/system/pypi.service; disabled; vendor preset: disabled)
   Active: active (running) since 二 2020-03-03 16:15:32 CST; 47min ago
  Process: 8147 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
 Main PID: 8149 (pypi-server)
    Tasks: 1
   Memory: 17.5M
   CGroup: /system.slice/pypi.service
           └─8149 /root/.pyenv/versions/3.7.2/bin/python3.7 /root/.pyenv/versions/3.7.2/bin/pypi-server -p 8080 -P /root/.pypipasswd -a update,download -r /var/www/pypi --log-file /var/log/pypi/pypi.log


3月 03 16:15:32 pro-pypi-server-200303 systemd[1]: Started pypi-server daemon.

6. 驗證 pypiserver 功能

$ cd /var/www/pypi

$ pip download pypiserver==1.3.2 --trusted-host mirrors.cloud.aliyuncs.com
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Collecting pypiserver==1.3.2
  Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/80/b1/76541cbc2bfea31e3429d9b94ea935de438d1e35bca6a8047195a9d4b2be/pypiserver-1.3.2-py2.py3-none-any.whl (75 kB)
     |████████████████████████████████| 75 kB 12.5 MB/s
  Saved ./pypiserver-1.3.2-py2.py3-none-any.whl
Successfully downloaded pypiserver

$ pip search -i http://172.19.60.23:8080 pypiserver
pypiserver (1.3.2)  - 1.3.2
  INSTALLED: 1.3.2 (latest)

$ pip search -i http://172.19.60.23:8080 pypiserver
pypiserver (1.3.2)  - 1.3.2
  INSTALLED: 1.3.2 (latest)

7. 客戶端配置

# 加上自己的內部源,配置多個 pypi 源
$ tee ~/.pip/pip.conf <<-'EOF'
[global]
index-url=https://172.19.60.23:8080/simple/
extra-index-url=
  https://pypi.xxx.xx/simple/
  http://mirrors.cloud.aliyuncs.com/pypi/simple/

[install]
trusted-host=
  mirrors.cloud.aliyuncs.com
  172.19.60.23:8080
  pypi.xxx.xxx:8080
EOF
$ tee  ~/.pypirc <<-'EOF'
[distutils]
index-servers =
  internal

[internal]
repository: http://172.19.60.23:8080
username: tomorrow
password: xxxx
EOF

8. 使用 pypi 源

## 搜索包

$ pip search -i http://172.28.70.126:8080 $package_name

## 安裝內部源的包
$ pip install -i http://172.28.70.126:8080 $package_name

## 上傳包
$ pip3 install twine
$ twine upload -r internal xxx.tar.gz

9.訪問 web 查看 package list

http://172.28.70.126:8080/simple
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容