linux-command
  • Introduction
  • linux-command
    • ab.md
    • accept.md
    • ack.md
    • alias.md
    • apachectl.md
    • apk.md
    • apropos.md
    • apt-get.md
    • aptitude.md
    • apt-key.md
    • apt-sortpkgs.md
    • ar.md
    • arch.md
    • arj.md
    • arp.md
    • arpd.md
    • arping.md
    • arptables.md
    • arpwatch.md
    • as.md
    • at.md
    • atop.md
    • atq.md
    • atrm.md
    • awk.md
    • axel.md
    • badblocks.md
    • basename.md
    • batch.md
    • bc.md
    • bg.md
    • bind.md
    • blkid.md
    • blockdev.md
    • bmodinfo.md
    • builtin.md
    • bunzip2.md
    • bye.md
    • bzcat.md
    • bzcmp.md
    • bzdiff.md
    • bzgrep.md
    • bzip2.md
    • bzip2recover.md
    • bzless.md
    • bzmore.md
    • cal.md
    • cancel.md
    • cat.md
    • cd.md
    • cdrecord.md
    • chage.md
    • chattr.md
    • chcon.md
    • chfn.md
    • chgrp.md
    • chkconfig.md
    • chmod.md
    • chown.md
    • chpasswd.md
    • chroot.md
    • chsh.md
    • cksum.md
    • clear.md
    • clock.md
    • clockdiff.md
    • cmp.md
    • col.md
    • colrm.md
    • comm.md
    • command.md
    • compress.md
    • consoletype.md
    • convertquota.md
    • cp.md
    • cpio.md
    • crontab.md
    • csplit.md
    • cu.md
    • cupsdisable.md
    • cupsenable.md
    • curl.md
    • cut.md
    • date.md
    • dd.md
    • declare.md
    • depmod.md
    • df.md
    • dhclient.md
    • dhcpd.md
    • dhcrelay.md
    • diff.md
    • diff3.md
    • diffstat.md
    • dig.md
    • dircolors.md
    • dirname.md
    • dirs.md
    • dmesg.md
    • dmidecode.md
    • dnf.md
    • dnsdomainname.md
    • domainname.md
    • dos2unix.md
    • dpkg.md
    • dpkg-deb.md
    • dpkg-divert.md
    • dpkg-preconfigure.md
    • dpkg-query.md
    • dpkg-reconfigure.md
    • dpkg-split.md
    • dpkg-statoverride.md
    • dpkg-trigger.md
    • dris.md
    • dstat.md
    • du.md
    • dump.md
    • e2fsck.md
    • e2label.md
    • echo.md
    • ed.md
    • edquota.md
    • egrep.md
    • eject.md
    • elinks.md
    • elm.md
    • emacs.md
    • enable.md
    • env.md
    • ethtool.md
    • ex.md
    • exec.md
    • exit.md
    • expand.md
    • export.md
    • exportfs.md
    • expr.md
    • fc.md
    • fdisk.md
    • fg.md
    • fgrep.md
    • file.md
    • find.md
    • findfs.md
    • finger.md
    • firewall-cmd.md
    • fishshell.md
    • fmt.md
    • fold.md
    • free.md
    • fsck.md
    • ftp.md
    • ftpcount.md
    • ftpshut.md
    • ftptop.md
    • ftpwho.md
    • fuser.md
    • gcc.md
    • gcov.md
    • gdb.md
    • get_module.md
    • getenforce.md
    • getsebool.md
    • git.md
    • gpasswd.md
    • gpm.md
    • grep.md
    • groupadd.md
    • groupdel.md
    • groupmod.md
    • groups.md
    • grpck.md
    • grpconv.md
    • grpunconv.md
    • grub.md
    • gunzip.md
    • gzexe.md
    • gzip.md
    • halt.md
    • hdparm.md
    • head.md
    • help.md
    • hexdump.md
    • history.md
    • host.md
    • hostid.md
    • hostname.md
    • hping3.md
    • htdigest.md
    • htop.md
    • htpasswd.md
    • hwclock.md
    • iconv.md
    • id.md
    • ifcfg.md
    • ifconfig.md
    • ifdown.md
    • ifstat.md
    • iftop.md
    • ifup.md
    • indent.md
    • info.md
    • init.md
    • inotifywait.md
    • insmod.md
    • install.md
    • iostat.md
    • iotop.md
    • ip.md
    • ip6tables.md
    • ip6tables-restore.md
    • ip6tables-save.md
    • ipcalc.md
    • ipcrm.md
    • ipcs.md
    • iperf.md
    • iptables.md
    • iptables-restore.md
    • iptables-save.md
    • iptraf.md
    • iptstate.md
    • ispell.md
    • jed.md
    • jobs.md
    • joe.md
    • join.md
    • jwhois.md
    • kernelversion.md
    • kexec.md
    • kill.md
    • killall.md
    • last.md
    • lastb.md
    • lastlog.md
    • ld.md
    • ldconfig.md
    • ldd.md
    • less.md
    • let.md
    • lftp.md
    • lftpget.md
    • lha.md
    • lilo.md
    • ln.md
    • lnstat.md
    • locate.md
    • logger.md
    • login.md
    • logname.md
    • logout.md
    • logrotate.md
    • logsave.md
    • logwatch.md
    • look.md
    • losetup.md
    • lp.md
    • lpadmin.md
    • lpc.md
    • lpq.md
    • lpr.md
    • lprm.md
    • lpstat.md
    • ls.md
    • lsattr.md
    • lsb_release.md
    • lsblk.md
    • lscpu.md
    • lsmod.md
    • lsof.md
    • lspci.md
    • lsusb.md
    • ltrace.md
    • lvcreate.md
    • lvdisplay.md
    • lvextend.md
    • lvreduce.md
    • lvremove.md
    • lvresize.md
    • lvscan.md
    • lynx.md
    • mail.md
    • mailq.md
    • mailstat.md
    • make.md
    • man.md
    • md5sum.md
    • mesg.md
    • mii-tool.md
    • mkbootdisk.md
    • mkdir.md
    • mke2fs.md
    • mkfs.md
    • mkinitrd.md
    • mkisofs.md
    • mknod.md
    • mkswap.md
    • mktemp.md
    • modprobe.md
    • more.md
    • mount.md
    • mpstat.md
    • mtools.md
    • mv.md
    • mysql.md
    • mysqladmin.md
    • mysqldump.md
    • mysqlimport.md
    • mysqlshow.md
    • named-checkzone.md
    • nano.md
    • nc.md
    • ncftp.md
    • nethogs.md
    • netstat.md
    • newusers.md
    • nfsstat.md
    • ngrep.md
    • nice.md
    • nisdomainname.md
    • nl.md
    • nm.md
    • nmap.md
    • nmcli.md
    • nohup.md
    • nologin.md
    • nslookup.md
    • ntpdate.md
    • ntsysv.md
    • objdump.md
    • od.md
    • openssl.md
    • parted.md
    • partprobe.md
    • passwd.md
    • paste.md
    • patch.md
    • pathchk.md
    • perl.md
    • pfctl.md
    • pgrep.md
    • php.md
    • pico.md
    • pidof.md
    • pigz.md
    • ping.md
    • pkill.md
    • pmap.md
    • popd.md
    • poweroff.md
    • ppp-off.md
    • pr.md
    • printf.md
    • protoize.md
    • ps.md
    • pssh.md
    • pstack.md
    • pstree.md
    • pushd.md
    • pv.md
    • pvchange.md
    • pvck.md
    • pvcreate.md
    • pvdisplay.md
    • pvremove.md
    • pvs.md
    • pvscan.md
    • pwck.md
    • pwconv.md
    • pwd.md
    • pwunconv.md
    • quota.md
    • quotacheck.md
    • quotaoff.md
    • quotaon.md
    • rcconf.md
    • rcp.md
    • read.md
    • readelf.md
    • readonly.md
    • reboot.md
    • reject.md
    • rename.md
    • renice.md
    • repquota.md
    • resize.md
    • restore.md
    • restorecon.md
    • rev.md
    • rexec.md
    • rlogin.md
    • rm.md
    • rmdir.md
    • rmmod.md
    • route.md
    • rpm.md
    • rpm2cpio.md
    • rpmbuild.md
    • rpmdb.md
    • rpmquery.md
    • rpmsign.md
    • rpmverify.md
    • rsh.md
    • rsync.md
    • runlevel.md
    • sar.md
    • scp.md
    • screen.md
    • sed.md
    • seinfo.md
    • semanage.md
    • sendmail.md
    • seq.md
    • service.md
    • ss.md
Powered by GitBook
On this page
  • 补充说明
  • 安装pssh
  • 选项
  • 实例

Was this helpful?

  1. linux-command

pssh.md

批量管理执行

补充说明

pssh命令 是一个python编写可以在多台服务器上执行命令的工具,同时支持拷贝文件,是同类工具中很出色的,类似pdsh,个人认为相对pdsh更为简便,使用必须在各个服务器上配置好密钥认证访问。

安装pssh

在CentOS系统环境下,介绍yum的安装和源码安装的方式:

yum方法

yum install pssh

编译安装

wget http://parallel-ssh.googlecode.com/files/pssh-2.3.1.tar.gz
tar xf pssh-2.3.1.tar.gz
cd pssh-2.3.1/
python setup.py install

选项

--version:查看版本
--help:查看帮助,即此信息
-h:主机文件列表,内容格式”[user@]host[:port]”
-H:主机字符串,内容格式”[user@]host[:port]”
-:登录使用的用户名
-p:并发的线程数【可选】
-o:输出的文件目录【可选】
-e:错误输入文件【可选】
-t:TIMEOUT 超时时间设置,0无限制【可选】
-O:SSH的选项
-v:详细模式
-A:手动输入密码模式
-x:额外的命令行参数使用空白符号,引号,反斜线处理
-X:额外的命令行参数,单个参数模式,同-x
-i:每个服务器内部处理信息输出
-P:打印出服务器返回信息

实例

获取每台服务器的uptime:

# pssh -h ip.txt -i uptime
[1] 11:15:03 [SUCCESS] Mar.mars.he
11:15:11 up 4 days, 16:25,  1 user,  load average: 0.00, 0.00, 0.00
[2] 11:15:03 [SUCCESS] Jan.mars.he
11:15:12 up 3 days, 23:26,  0 users,  load average: 0.00, 0.00, 0.00
[3] 11:15:03 [SUCCESS] Feb.mars.he
11:15:12 up 4 days, 16:26,  2 users,  load average: 0.08, 0.02, 0.01

查看每台服务器上mysql复制IO/SQL线程运行状态信息:

# pssh -h IP.txt -i "/usr/local/mysql/bin/mysql -e 'show slave status \G'"|grep Running:
             Slave_IO_Running: yes
            Slave_SQL_Running: Yes
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

保存每台服务器运行的结果:

# pssh -h IP.txt -i -o /tmp/pssh/ uptime
[1] 11:19:47 [SUCCESS] Feb.mars.he
11:19:55 up 4 days, 16:31,  2 users,  load average: 0.02, 0.03, 0.00
[2] 11:19:47 [SUCCESS] Jan.mars.he
11:19:56 up 3 days, 23:30,  0 users,  load average: 0.01, 0.00, 0.00
[3] 11:19:47 [SUCCESS] Mar.mars.he
11:19:56 up 4 days, 16:30,  1 user,  load average: 0.00, 0.00, 0.00

我们来看一下/tmp/pssh/下的文件及其内容

# ll /tmp/pssh/
总用量 12
-rw-r--r--. 1 root root 70 12月  1 11:19 Feb.mars.he
-rw-r--r--. 1 root root 70 12月  1 11:19 Jan.mars.he
-rw-r--r--. 1 root root 69 12月  1 11:19 Mar.mars.he

# cat /tmp/pssh/*
11:19:55 up 4 days, 16:31,  2 users,  load average: 0.02, 0.03, 0.00
11:19:56 up 3 days, 23:30,  0 users,  load average: 0.01, 0.00, 0.00
11:19:56 up 4 days, 16:30,  1 user,  load average: 0.00, 0.00, 0.00

上面介绍的是pssh命令很少的一部分,大家可以将其用到适合自己的场景,发挥它的最大功效。

Previousps.mdNextpstack.md

Last updated 5 years ago

Was this helpful?