这篇文章主要介绍“Centos7中如何部署pssh”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Centos7中如何部署pssh”文章能帮助大家解决问题。

pssh是python写的可以并发在多台机器上批量执行命令的工具,它的用法可以媲美ansible的一些简单用法,执行起来速度比ansible快它支持文件并行复制,远程命令执行,杀掉远程主机上的进程等等。

下载pssh安装包

[root@localhost~]#wgethttps://files.pythonhosted.org/packages/60/9a/8035af3a7d3d1617ae2c7c174efa4f154e5bf9c24b36b623413b38be8e4a/pssh-2.3.1.tar.gz安装依赖包

[root@localhost~]#yuminstall-ymakegccgcc++python-develpython-pip安装pssh

[root@localhost~]#tarxfpssh-2.3.1.tar.gz[root@localhost~]#cdpssh-2.3.1[root@localhost~]#pythonsetup.pyinstall配置免密登录

[root@localhost~]#ssh-keygenGeneratingpublic/privatersakeypair.Enterfileinwhichtosavethekey(/root/.ssh/id_rsa):Enterpassphrase(emptyfornopassphrase):Entersamepassphraseagain:Youridentificationhasbeensavedin/root/.ssh/id_rsa.Yourpublickeyhasbeensavedin/root/.ssh/id_rsa.pub.Thekeyfingerprintis:SHA256:3antaxjGw+hdgfSlrXLYhUe5vgHe9b0ehh/gUY9E8Egroot@localhost.localdomainThekey'srandomartimageis:+---[RSA2048]----+|E...||..++||.o.*oo||...*o*.o||S+.+o@..+||.OoBBo||.o.B.o*.||.o..+.o||.o..o|+----[SHA256]-----+[root@localhost~]#cd/root/.ssh/[root@localhost.ssh]#lsid_rsaid_rsa.pub[root@localhost.ssh]#ssh-copy-id172.16.1.112/usr/bin/ssh-copy-id:INFO:Sourceofkey(s)tobeinstalled:"/root/.ssh/id_rsa.pub"Theauthenticityofhost'172.16.1.112(172.16.1.112)'can'tbeestablished.ECDSAkeyfingerprintisSHA256:yFvaxR1x5YDhhe+6xR/Ou6Sm+YPYvPAoiLVKt9mAnXA.ECDSAkeyfingerprintisMD5:0d:c4:79:bc:36:7a:a4:82:95:4f:d5:d0:a3:c8:7d:2e.Areyousureyouwanttocontinueconnecting(yes/no)?yes/usr/bin/ssh-copy-id:INFO:attemptingtologinwiththenewkey(s),tofilteroutanythatarealreadyinstalled/usr/bin/ssh-copy-id:INFO:1key(s)remaintobeinstalled--ifyouarepromptednowitistoinstallthenewkeysroot@172.16.1.112'spassword:Numberofkey(s)added:1Nowtryloggingintothemachine,with:"ssh'172.16.1.112'"andchecktomakesurethatonlythekey(s)youwantedwereadded.[root@localhost.ssh]#ssh-copy-id172.16.1.16/usr/bin/ssh-copy-id:INFO:Sourceofkey(s)tobeinstalled:"/root/.ssh/id_rsa.pub"Theauthenticityofhost'172.16.1.16(172.16.1.16)'can'tbeestablished.ECDSAkeyfingerprintisSHA256:ANzlXzrGA87YLI2vzkPJ/iNPiSQ5JStJc95948jE8aw.ECDSAkeyfingerprintisMD5:f9:f1:1b:5a:99:64:d8:d8:e9:9b:e6:bb:c3:d5:bd:e7.Areyousureyouwanttocontinueconnecting(yes/no)?yes/usr/bin/ssh-copy-id:INFO:attemptingtologinwiththenewkey(s),tofilteroutanythatarealreadyinstalled/usr/bin/ssh-copy-id:INFO:1key(s)remaintobeinstalled--ifyouarepromptednowitistoinstallthenewkeysroot@172.16.1.16'spassword:Numberofkey(s)added:1Nowtryloggingintothemachine,with:"ssh'172.16.1.16'"andchecktomakesurethatonlythekey(s)youwantedwereadded.测试免密登录

[root@localhost~]#ssh172.16.1.112Lastlogin:TueJun209:44:242020from172.16.1.16[root@localhost~]#ssh172.16.1.16Lastlogin:TueJun209:30:472020from172.16.1.100测试pssh

创建aaa文件存放ip地址

[root@localhost~]#cataaa172.16.1.16172.16.1.112

批量执行date命令

[root@localhost~]#pssh-haaa-lroot-P"date"172.16.1.16:2020年06月02日星期二09:59:48CST[1]09:59:48[SUCCESS]172.16.1.16172.16.1.112:2020年06月02日星期二09:59:48CST[2]09:59:48[SUCCESS]172.16.1.112

查看磁盘

[root@localhost~]#pssh-haaa-lroot-P"lsblk"172.16.1.16:NAMEMAJ:MINRMSIZEROTYPEMOUNTPOINTsda8:0020G0disk├─sda18:101G0part/boot└─sda28:2019G0part├─centos-root253:0017G0lvm/└─centos-swap253:102G0lvm[SWAP]sr011:014.2G0rom[1]10:13:02[SUCCESS]172.16.1.16172.16.1.112:NAMEMAJ:MINRMSIZEROTYPEMOUNTPOINTsda8:0020G0disk├─sda18:101G0part/boot└─sda28:2019G0part├─centos-root253:0017G0lvm/└─centos-swap253:102G0lvm[SWAP]sr011:014.2G0rom[2]10:13:03[SUCCESS]172.16.1.112

pssh部署完毕!

关于“Centos7中如何部署pssh”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。