python自動化運維之讀書筆記(一)

2021-09-20 23:50:39 字數 1657 閱讀 4200

第一章:系統基礎資訊模組:

wget 

那我們是怎麼去找到這些需要的包呢?當然是官網

直接在這裡搜尋包名稱即可

root@localhost psutil-2.0.0]# python setup.py install

running install

running build

running build_py

running build_ext

building '_psutil_linux' extension

gcc -pthread -fno-strict-aliasing -o2 -g -pipe -wall -wp,-d_fortify_source=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -d_gnu_source -fpic -fwrapv -dndebug -o2 -g -pipe -wall -wp,-d_fortify_source=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -d_gnu_source -fpic -fwrapv -fpic -i/usr/include/python2.7 -c psutil/_psutil_linux.c -o build/temp.linux-x86_64-2.7/psutil/_psutil_linux.o

psutil/_psutil_linux.c:12:20: fatal error: python.h: no such file or directory

#include

^compilation terminated.

error: command 'gcc' failed with exit status 1

解決方法:安裝python開發靜態庫:

yum install python-devel

#!/usr/bin/env python

import psutil

mem=psutil.virtual_memory()

mem1=psutil.virtual_memory

print mem.total,mem.used

print 'memory information:',mem.free

print 'cpu information:',psutil.cpu_times(percpu=true)

print 'cpu idle information:',psutil.cpu_times(percpu=true)

print 'cpu logical count:',psutil.cpu_count()

print 'cpu physical count:',psutil.cpu_count(logical=false)

print 'disk information:',psutil.disk_partitions()

print 'disk usage:',psutil.disk_usage('/')

print 'network io:',psutil.net_io_counters(pernic=true)

python之自動化運維 Paramiko

使用開源的paramiko,我們就可以用python 中通過ssh協議對遠端伺服器執行操作,不需要手敲ssh命令,從而實現自動化運維。ssh是乙個協議,openssh是其中乙個開源實現,paramiko庫,實現了sshv2協議 底層使用cryptography 專案文件 點我跳轉 擴充套件 ssh協...

運維自動化

1,cobbler安裝環境準備 安裝epel epel release 6 8.noarch.rpm x86 64 epel release 6 8.noarch.rpm x86 安裝系列依賴環境 要是區域網用,建議關閉iptables 或是放行25151 80 69埠 和關閉selinux 檢視狀...

自動化運維

考慮的因素 源 打包為映象 發布到映象庫 利用k8s發布到物理機器執行,以服務的形式對外提供服務 目前的做法 0 建立乙個執行遠端命令的框架 1 每個應用建立乙個部署檔案指令碼 a 指定元 位址 c 同步源 到目標主機 d 接受指令碼引數 vername 2 版本號,映象tag fromport 3...