搭建pip本地源

2021-07-25 13:32:22 字數 3007 閱讀 2650

環境: 系統ubuntu14.04.5

eth0: 192.168.10.18   可訪問外網 

eth1: 172.16.1.1          不可訪問外網

一:搭建pip本地源

root@ubuntu:~# mkdir /python-packages

root@ubuntu:~# cd /python-packages

root@ubuntu:/python-packages# pip download -r ~/pip-requires 

root@ubuntu:/python-packages# cat ~/pip-requires 

# keystone dependencies

pam>=0.1.4

webob==1.2.3

eventlet

greenlet

pastedeploy

paste

routes

sqlalchemy>=0.7.8,<=0.7.9

sqlalchemy-migrate>=0.7.2

passlib

lxml

iso8601>=0.1.4

python-keystoneclient>=0.2.1,<0.3

oslo.config>=1.1.0

root@ubuntu:~# mkdir ~/.pip

root@ubuntu:~# cat ~/.pip/pip.conf 

[global]

trusted-host = mirrors.aliyun.com

index-url =

2.執行指令碼init_local_pip.sh /python-packages ,指令碼如下

#!/bin/bash  

# set -x

if [ $# -ne 1 ]; then

echo "usage: $0 packages_dir"

exit 1

fi

[ ! -d $1 ] && echo "error: you should provide a directory." && exit 1

dest=$1

dest=$

if ! echo $dest |grep -q "^/"; then

echo "error: please use the absolute path."

exit 1

fi

if ! ls $dest | egrep -q "(gz|zip)$"; then

echo "note: nothing need to do."

exit 0

fi

#---------------------------------------------

topdir=$(cd $(dirname "$0") && pwd)

tmpdir=`mktemp -d`

#---------------------------------------------

for i in `ls $/ 2>/dev/null`

do

rm -rf $tmpdir/*

cp $i $tmpdir

cd $tmpdir

package_arch_name=`ls`

if echo $package_arch_name | grep -q "gz$"; then

tar xf $package_arch_name

gz_suffix=1

else

unzip $package_arch_name

gz_suffix=0

fi

rm -rf $package_arch_name

package_name=`ls`

cd $package_name

if ls |grep -q "egg-info"; then

python setup.py egg_info

python setup.py build

cd ..

if [ $gz_suffix -eq 1 ]; then

tar czf $package_arch_name $package_name

else

zip -r $package_arch_name $package_name

fi

rm -rf $i

cp $package_arch_name $dest/

fi

cd $topdir

done

rm -rf $tmpdir

3.安裝pypiserver

root@ubuntu:~# pip install pypiserver

4.為了讓在系統啟動的時候同時啟動pypiserver,修改/etc/rc.local

root@ubuntu:~# cat /etc/rc.local |egrep -v "^#|^$"

pypi-server /python-packages &>/var/log/pypi-server.log &

exit 0

6.啟動pypiserver

root@ubuntu:~# bash /etc/rc.local 

二:測試

1.再開啟乙個虛擬機器,ip設定為172.16.1.2,並指定pip源為172.16.1.1

root@ubuntu:~# cat .pip/pip.conf 

[global]

trusted-host = 172.16.1.1

index-url =

2.用pip安裝所需python包即可

root@ubuntu:~# pip install -r pip-requires 

搭建pip本地庫

1.安裝 python 可以原始碼安裝 yum install python 3.安裝pip 如安裝 pip 1.5.4.tar.gz pip install pip2pi 4.配置要同步的 pypi 源,比如以官網的 pypi 源同步為例 vim pip pip.conf 自己建立 global ...

搭建本地 yum 源

1 在 yum 源伺服器 上修改 etc yum.repo.d 目錄 mv centos base.repo centos base.repo.bak 2 安裝 createrepo yum y install createrepo 3 建立 本地 repo vim local.repo local...

搭建本地yum源

1,掛載光碟 mkdir mnt cdrom mount dev cdrom mnt cdrom 注意這裡可能出現掛載錯誤 mount block device dev sr0 is write protected,mounting read only 顯示只有讀和寫的許可權,再輸入 mount o...