1. 下载依赖
pip install pypiserver # 命令安装 pypiserver 库
pip install passlib # passlib 包来读取 Apache htpasswd 文件
apt-get install -y apache2-utils
2. 生成密码
使用htpasswd库在指定路径/path/to/.pypipasswd
生成密码文件
htpasswd -c /path/to/.pypipasswd root
New password: [输入密码]
Re-type new password: [再次输入密码]
Adding password for user root
3. 启动仓库
pypi-server run -P /path/to/.pypipasswd --fallback-url https://mirrors.aliyun.com/pypi/simple/ /opt/pypi/package_directory /opt/pypi/packages -p 8989
启动PyPI服务器,可以通过浏览器访问 http://localhost:8080/
以打开PyPI服务器的默认欢迎页。
- -P:指定密码文件
- –fallback-url:本pypi-server找不到包时,到此源寻找
- -p:启动端口
4. 服务化
首先编写启动脚本run-pypi.sh
#!/bin/bash
pypi-server run -P /path/to/.pypipasswd --fallback-url https://mirrors.aliyun.com/pypi/simple/ /opt/pypi/package_directory /opt/pypi/packages -p 8989
在/etc/systemd/system路径下新增文件 pypi-server.service3
[Unit]
Description=Pypi server
Requires=network-online.target
After=network-online.target[Service]
Type=simple
User=root
Group=root
ExecStart=/opt/pypi/run-pypi.sh[Install]
WantedBy=multi-user.target
启动、开机自启
systemctl start pypi-server.service
systemctl enable pypi-server.service
查看状态
systemctl status pypi-server.service
● pypi-server.service - Pypi serverLoaded: loaded (/etc/systemd/system/pypi-server.service; enabled; vendor preset: enabled)Active: active (running) since Mon 2024-05-27 12:10:47 CST; 2min 37s agoMain PID: 2406608 (run-pypi.sh)Tasks: 7 (limit: 464205)Memory: 61.8MCGroup: /system.slice/pypi-server.service├─2406608 /bin/bash /opt/pypi/run-pypi.sh└─2406614 /usr/bin/python3 /usr/local/bin/pypi-server run -P /path/to/.pypipasswd --fallback-url https://mirrors.aliyun.com/pypi/simple/ /opt/pypi/package_directory /opt/pypi/packages -p 8989May 27 12:10:47 tool-pnb-105-112 systemd[1]: Started Pypi server.