91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

paramiko 遠程遠程部署軟件腳本案例

發布時間:2020-07-26 17:01:20 來源:網絡 閱讀:225 作者:dengwang123 欄目:系統運維


paramiko 遠程遠程部署軟件腳本案例


#?-*-?coding:?utf-8?-*-

import?paramiko
import?sys,?os
import?datetime
import?subprocess
import?time
import?re
import?hashlib

reload(sys)
sys.setdefaultencoding("utf-8")
os.environ["PATH"]?=?"/usr/local/jdk18/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
os.environ["LANG"]?=?"en_US.UTF-8"

ip_list?=?["10.110.189.217","10.110.193.106"]


class?pub_filebeat():

????def?__init__(self):
????????self.username?=?"redis"
????????self.passwd?=?"123456"
????????self.client_ssh?=?None
????????self.sftpcliet?=?None
????????self.port?=?22
????????self.chan?=?None
????????self.result?=?None


????#?創建一個ssh?鏈接
????def?create_ssh(self,ip):
????????self.client_ssh?=?paramiko.SSHClient()
????????self.client_ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
????????self.client_ssh.connect(ip,?self.port,?self.username,?self.passwd,?timeout=5)
????????self.chan?=?self.client_ssh.invoke_shell()
????????self.flag=None
????????'''?
????????在現有的ssh鏈接的基礎上獲取一個ftp鏈接
????????方式一???:
????????transport?=?self.client_ssh.get_transport()
????????self.sftpcliet?=?paramiko.SFTPClient.from_transport(transport)
????????
????????方式二?:
????????self.sftpcliet?=?self.client_ssh.open_sftp()
????????'''
????????#
????????#?transport?=?self.client_ssh.get_transport()
????????#?self.sftpcliet?=?paramiko.SFTPClient.from_transport(transport)
????????self.sftpcliet?=?self.client_ssh.open_sftp()

????def?execute(self,ip):
????????try:
????????????self.sendcmd("?sudo?su?-?")
????????????if?self.flag?==?1:
????????????????self.sendcmd("redis@yto369")
????????????self.sendcmd("?cd?/home/redis?")
????????????self.sendcmd("?tar??-zxvf?filebeat623.tar.gz?")
????????????self.sendcmd("?sed?-i?'s/hostip:?10.1.241.99/hostip:?%s/g'?filebeat623/filebeat.yml?;?"?%?(ip))
????????????self.sendcmd("?nohup?filebeat623/filebeat?-e??-c?filebeat623/filebeat.yml?>?info.log?2>&1?&?")
????????????print?"%s?filebeat?部署完成"?%?(ip)
????????except?Exception,e:
????????????print?e.message


????def?tranfile(self):
????????try:
????????????self.sftpcliet.put("F:\dwchaoyue\ELK\/filebeat623.tar.gz",?'/home/redis/filebeat623.tar.gz')
????????except?Exception,e:
????????????print?e.message
????????????self.sftpcliet.close()


????def?sendcmd(self,cmd):
????????cmd?=?cmd?+?'\r'
????????p?=?re.compile(r'\[root@.+\s.*\]')
????????self.result?=?""
????????self.chan.send(cmd)
????????while?True:
????????????time.sleep(0.5)
????????????ret?=?self.chan.recv(65535).decode("utf-8")
????????????self.result?=?self.result?+?ret
????????????if??'password'?in?self.result.split("?"):
????????????????self.flag?=?1
????????????????break
????????????if?p.search(ret):
????????????????break


????#?遍歷ip?列表
????def?bianli(self,ip_list):
????????for?ip?in?ip_list:
????????????self.create_ssh(ip)
????????????if?self.check_result()?>=?1?:
????????????????print?"%s?filebeat?已部署,無需重新部署"?%?(ip)
????????????????continue
????????????????pass
????????????self.tranfile()
????????????self.execute(ip)
????????????if?self.check_result()?<?1:
????????????????print?"%s?filebeat?部署失敗?,請重試"?%?(ip)
????????????self.client_ssh.close()
????????????self.sftpcliet.close()


????def?check_result(self):
????????std_in,std_out,std_err?=?self.client_ssh.exec_command("ps??-ef??|?grep??-i?filebeat?|?grep??-v??'grep'?|?wc??-l")
????????return?int(std_out.read())


if?__name__?==?"__main__":
????try:
????????pb?=?pub_filebeat()
????????pb.bianli(ip_list)
????except?Exception,?e:
????????print?e


paramiko 遠程執行命令和上傳下載代碼案例

Phttps://www.cnblogs.com/haigege/p/5513759.html

phttps://blog.csdn.net/a382486075/article/details/78658165


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

宁津县| 灌南县| 桐乡市| 巫溪县| 乌兰浩特市| 高邑县| 岚皋县| 遵义市| 淳安县| 肃北| 洪雅县| 米易县| 木兰县| 莫力| 漳浦县| 门头沟区| 德化县| 宜州市| 屏东市| 屏南县| 云林县| 英吉沙县| 奈曼旗| 威宁| 安西县| 蒲城县| 安多县| 瑞丽市| 阳东县| 贵州省| 德化县| 孟连| 沈丘县| 双鸭山市| 阿合奇县| 象州县| 长春市| 临澧县| 辽源市| 衡阳市| 灵台县|