一、paramiko子產品有什麼用?
paramiko是用python語言寫的一個子產品,遵循SSH2協定,支援以加密和認證的方式,進行遠端伺服器的連接配接。由于使用的是python這樣的能夠跨平台運作的語言,是以所有python支援的平台,如Linux, Solaris, BSD, MacOS X, Windows等,paramiko都可以支援,是以,如果需要使用SSH從一個平台連接配接到另外一個平台,進行一系列的操作時,比如:批量執行指令,批量上傳檔案等操作,paramiko是最佳工具之一。
目前新的版本,官網在此:
https://github.com/paramiko/paramiko
舊版本在此:
http://www.lag.net/paramiko/legacy.html
要安裝新版本paramiko子產品需要做以下準備:
1.Python2.5+ 版本(Linux, Unix, Windows都可以),這裡就直接安裝Python2.7
下載下傳位址:http://www.python.org
2.PyCrypto 2.1+ 子產品(PyCrypto是使用Python編寫的加密工具包)
下載下傳位址:https://www.dlitz.net/software/pycrypto/
3.easy_install 工具(是Python安裝子產品的一個工具,像yum,可以自動解決依賴)
下載下傳位址: http://peak.telecommunity.com/dist/ez_setup.py
如果大家感覺安裝paramiko還是略有麻煩的話,當使用到paramiko提供的友善時便會覺得這是十分值得的。
二、Linux上安裝paramiko(以CentOS 5.8 32位 為例)
1.檢視Python的版本,是否滿足要求
1 [[email protected] ~]# python -V
2 Python 2.4.3
3 [[email protected] ~]#
Windows上亦是此指令,注意是大寫V
是2.4.3版本,需要更新
2.下載下傳安裝python2.7
1 [[email protected] ~]# wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2
2 [[email protected] ~]# tar jxf Python-2.7.5.tar.bz2
3 [[email protected] ~]# cd Python-2.7.5
4 [[email protected] Python-2.7.5]# ./configure --prefix=/usr/local/python2.7
5 [[email protected] Python-2.7.5]# make && make install
6 [[email protected] Python-2.7.5]# echo "PATH=/usr/local/python2.7/bin:$PATH" >> /etc/profile
7 [[email protected] Python-2.7.5]# source /etc/profile
8 [[email protected] Python-2.7.5]# python -V
9 Python 2.7.5
10 [[email protected] Python-2.7.5]# python
11 Python 2.7.5 (default, Aug 16 2013, 07:56:41)
12 [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
13 Type "help", "copyright", "credits" or "license" for more information.
14 >>>
3.安裝easy_install 工具
1 [[email protected] ~]# wget http://peak.telecommunity.com/dist/ez_setup.py
2 [[email protected] ~]# python ez_setup.py
3 Downloading http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
4 Processing setuptools-0.6c11-py2.7.egg
5 Copying setuptools-0.6c11-py2.7.egg to /usr/local/python2.7/lib/python2.7/site-packages
6 Adding setuptools 0.6c11 to easy-install.pth file
7 Installing easy_install script to /usr/local/python2.7/bin
8 Installing easy_install-2.7 script to /usr/local/python2.7/bin
9 Installed /usr/local/python2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
10 Processing dependencies for setuptools==0.6c11
11 Finished processing dependencies for setuptools==0.6c11
隻需要執行以上指令,即可安裝好easy_install 工具
4.安裝paramiko子產品
使用以下指令,即可安裝好paramiko子產品
1 [[email protected] ~]# easy_install paramiko
進入Python導入paramiko一下試試
1 [[email protected] ~]# python
2 Python 2.7.5 (default, Aug 16 2013, 07:56:41)
3 [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
4 Type "help", "copyright", "credits" or "license" for more information.
5 >>> import paramiko
6 /usr/local/python2.7/lib/python2.7/site-packages/pycrypto-2.6-py2.7-linux-i686.egg/Crypto/Util/number.py:57: PowmInsecureWarning: Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.
7 >>>
導入子產品時,如果遇到以上問題,可能是由于gmp版本比較低造成的,gmp是啥,看官網的解釋:
GMP is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating point numbers.
看樣子是跟精度有關系
可以用以下方法解決:
先解除安裝低版本
1 [email protected] ~]# rpm -qa | grep gmp
2 gmp-devel-4.1.4-10.el5
3 gmp-4.1.4-10.el5
4 [[email protected] ~]# rpm -e gmp-devel-4.1.4-10.el5.i386
5 [[email protected] ~]# rpm -e gcc-gfortran-4.1.2-52.el5.i386
6 [[email protected] ~]# rpm -e gmp-4.1.4-10.el5
7 [[email protected] ~]# ldconfig
8 [[email protected] ~]#
然後安裝高版本的gmp
1 [[email protected] ~]# wget http://ftp.gnu.org/gnu/gmp/gmp-5.1.2.tar.bz2
2 [[email protected] ~]# tar jxf gmp-5.1.2.tar.bz2
3 [[email protected] ~]# cd gmp-5.1.2
4 [[email protected] gmp-5.1.2]# ./configure && make && make install
5 [[email protected] gmp-5.1.2]# echo "/usr/local/lib" >> /etc/ld.so.conf
6 [[email protected] gmp-5.1.2]# ldconfig
再次嘗試導入paramiko子產品:
1 2 3 4 5 6 7 8 | |
一切正常,至此paramiko子產品在Linux上安裝完成
原文連結:http://www.cnblogs.com/shangzekai/p/5212305.html
安裝過程中可能遇到的問題以及解決方法,請參考:
1》linux中pip安裝步驟與使用詳解
2》python下setuptools安裝( No module named setuptools 解決方案)
3》【centos】 error command 'gcc' failed with exit status 1
4》 CentOS 5.8(x86_64)中,Python-2.7.5互動模式下方向鍵、倒退鍵等出現亂碼。