Auth: jin
Date: 20140314
OS:
CentOS release 5.5 (Final)
默认2.4版本
莫
1.download
wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
2.install python
tar -zxvf Python-2.7.6.tgz && cd Python-2.7.6
./configure --prefix=/usr/local/python27/
make && make install
PIPY
wget https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz
由于下载pip是基于https协议的,故需要在wget url后面加上--no-check-certificate,否则不能下载:
tar -zxvf pip-1.5.4.tar.gz && cd pip-1.5.4
[root@ZJ-mnt-host-1 pip-1.5.4]# /usr/local/python27/bin/python setup.py build
Traceback (most recent call last):
File "setup.py", line 6, in <module>
from setuptools import setup, find_packages
ImportError: No module named setuptools
3.install setuptools
wget https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg --no-check-certificate
# chmod +x setuptools-0.6c11-py2.7.egg
# sh setuptools-0.6c11-py2.7.egg
setuptools-0.6c11-py2.7.egg: line 3: exec: python2.7: not found
ln -s /usr/local/python27/bin/python2.7 /usr/bin/python2.7
# sh setuptools-0.6c11-py2.7.egg
Processing setuptools-0.6c11-py2.7.egg
Copying setuptools-0.6c11-py2.7.egg to /usr/local/python27/lib/python2.7/site-packages
Adding setuptools 0.6c11 to easy-install.pth file
Installing easy_install script to /usr/local/python27/bin
Installing easy_install-2.7 script to /usr/local/python27/bin
Installed /usr/local/python27/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11
4.install pyp
#cd pip-1.5.4
/usr/local/python27/bin/python setup.py build
/usr/local/python27/bin/python setup.py install
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying pip.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pip.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pip.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pip.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pip.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pip.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pip.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
creating dist
creating 'dist/pip-1.5.4-py2.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing pip-1.5.4-py2.7.egg
creating /usr/local/python27/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg
Extracting pip-1.5.4-py2.7.egg to /usr/local/python27/lib/python2.7/site-packages
Adding pip 1.5.4 to easy-install.pth file
Installing pip script to /usr/local/python27/bin
Installing pip2.7 script to /usr/local/python27/bin
Installing pip2 script to /usr/local/python27/bin
Installed /usr/local/python27/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg
Processing dependencies for pip==1.5.4
Finished processing dependencies for pip==1.5.4
Successfully installed paramiko pycrypto ecdsa
Cleaning up...
5.通过pypi安装paramiko
pip search paramiko
pip install paramiko
6、代码
### ssh config sship = '127.0.0.1' sshport = 22 sshuser = 'jin' sshpassword = 'passwd' def sshRemoteCMD(): client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: client.connect(sship,sshport,sshuser,sshpassword) except Exception,e: print 'error %s' % e else: stdin, stdout, stderr = client.exec_command('/bin/hostname') if stdout: print "OutPut:%s" % stdout.readlines() if stderr: print "StdError:%s" % stderr.readlines() finally: client.close() if __name__ == '__main__': sshRemoteCMD()
测试
OutPut:['linux-gzy1.site
']
StdError:[]
包管理软件安装
1、opensuse
[root@MyOpenSUSE ~]# zypper install python-pip
(1/2) Installing: python-setuptools-0.9.8-3.1.2 ........................................................................[done]
Additional rpm output:
update-alternatives: using /usr/bin/easy_install-2.7 to provide /usr/bin/easy_install (easy_install) in auto mode
(2/2) Installing: python-pip-1.4.1-2.2.1 ...............................................................................[done]
Additional rpm output:
update-alternatives: using /usr/bin/pip-2.7 to provide /usr/bin/pip (pip) in auto mode
[root@MyOpenSUSE ~]# pip install paramiko