1. 通過(guò) pip 安裝 pip server
$ pip install pypiserver
2. 安裝 周邊服務(wù)
$ pip install passlib
3. 設(shè)置密碼
$ 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 更新,下載都需要密碼驗(yàn)證
[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
# 創(chuàng)建 pypi 及 log 路徑
$ mkdir -p /var/www/pypi
$ mkdir -p /var/log/pypi
5. 啟動(dòng) 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. 驗(yàn)證 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. 客戶(hù)端配置
# 加上自己的內(nèi)部源,配置多個(gè) 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
## 安裝內(nèi)部源的包
$ pip install -i http://172.28.70.126:8080 $package_name
## 上傳包
$ pip3 install twine
$ twine upload -r internal xxx.tar.gz
9.訪問(wèn) web 查看 package list
http://172.28.70.126:8080/simple
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。