码迷,mamicode.com
首页 > 编程语言 > 详细

Ubuntu批量安装离线安装python的pycrypto库

时间:2019-04-28 18:30:39      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:离线安装   http   rem   src   configure   pytho   pythonh   wget   user   

众所周知知,PyCrypto的库安装方法如下:
pip install pycrypto

因主机无法联网,造成无法使用pip install 命令,于是选择离线安装pycrypto并库。
结合ansible批量对离线主机安装pycrypto库

PyCrypto库离线安装包及依赖的源码包下载链接

$sudo apt-get install -y python-dev

wget http://www.mpir.org/mpir-2.5.1.tar.bz2
wget http://ftp.gnu.org/pub/gnu/gmp/gmp-5.0.5.tar.bz2
wget https://files.pythonhosted.org/packages/60/db/645aa9af249f059cc3a368b118de33889219e0362141e75d4eaf6f80f163/pycrypto-2.6.1.tar.gz

使用ansible-playbook进行安装
ansible-playbook install.yaml
install.yaml内容如下:

---
- hosts: ubuntu1204
  remote_user: root
    sudo: yes
    sudo_user: user
  serial: 7
  gather_facts: F
  tasks:
      - name: jianyan
        copy: src=/mnt/PyCrypto.tar.gz dest=/usr/local/src/
      - name: jianyan
        shell: python /usr/local/src/install.sh

安装脚本install.sh如下:

#!/bin/bash
cd /usr/local/src/
tar -zxvf PyCrypto.tar.gz
cd /usr/local/src/PyCrypto/
bunzip2 gmp-5.0.5.tar.bz2
tar -xvf gmp-5.0.5.tar
cd gmp-5.0.5/
./configure
make
make check
make install

cd /usr/local/src/PyCrypto/
bunzip2 mpir-2.5.1.tar.bz2
tar -xvf mpir-2.5.1.tar
cd mpir-2.5.1/
./configure
make
make check
make install

cd /usr/local/src/PyCrypto/
tar -zxvf pycrypto-2.6.1.tar.gz
cd pycrypto-2.6.1/
python setup.py build
python setup.py install

检验离线安装PyCrypto库是否成功

#!/bin/bash
#name = check.py
try:
    from Crypto.Signature import PKCS1_v1_5
    print "ok, install"
except ImportError:
    print "not found"

批量检验后执行结果如下:

$ ansible ubuntu1204 -m shell -a "python /usr/local/src/try.py" -u root
168.1.64 | SUCCESS | rc=0 >>
ok, install

168.1.68 | SUCCESS | rc=0 >>
ok, install

168.1.69 | SUCCESS | rc=0 >>
ok, install

168.1.70 | SUCCESS | rc=0 >>
ok, install

168.1.67 | SUCCESS | rc=0 >>
ok, install

Ubuntu批量安装离线安装python的pycrypto库

标签:离线安装   http   rem   src   configure   pytho   pythonh   wget   user   

原文地址:https://blog.51cto.com/mengix/2386249

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!