Linux Bulk management tool PSSH usage record

Source: Internet
Author: User
Tags pscp ssh port

Pssh is an open source software, using Python implementation, for bulk SSH operation of large-volume machines, PSSH is a tool that can execute commands on multiple servers, while supporting the copying of files, is excellent in the same kind of tool, I would recommend using the pssh! The prerequisite for using PSSH is that the key authentication access (that is, the SSH trust relationship) must be configured on the native and other servers.

Here's a record of using PSSH for bulk operations:

1) Install Pssh
You can install Yum directly:
[email protected] ~]# Yum install-y pssh

2) pssh usage
[[email protected] ~]# pssh--help
-h The remote host list file that executes the command  
-h [email protected]:p ort file content format [[email protected]] host[:p ort] 
-l remote machine user name  
-p the maximum number of connections allowed at a time  < BR data-filtered= "Filtered" >-o output redirect to a file  
-e execution error redirected to a file  
-t set the timeout for the command execution  
-a prompt for password and pass the password to SSH (note that this parameter is added only to prompt action, You can enter or not enter directly into the &NBSP;
-o set the specific configuration of the SSH parameters, refer to the Ssh_config profile  
-x pass multiple SSH commands, multiple commands separated by spaces, enclosed in quotation marks  
-x with-X but only one command at a time &NBSP;
-i display standard output and standard error after each host executes &NBSP;
-i reads each input command, and passed to the SSH process allows the command script to be routed to standard input

3) Pssh Instance description
[[email protected] ~]# cat hosts.txt//list file in the information format is "IP: Port", if the local and remote machine using the same SSH port, you can save the port, directly with the IP line. However, it is advisable to bring the ports as well.
192.168.1.101:22
192.168.1.109:22
192.168.1.118:25791
192.168.1.105:25791
such as the above four machines placed in a list file Hosts.txt, the machine has been and these four machines did SSH login trust relationship without password
Note: The machine in the list file must be in advance and the local SSH trust relationship, if not done, then pssh batch execution, the turn of the machine without a trust relationship will not be executed.

A) batch execution of commands
[Email protected] ~]# pssh-h hosts.txt-l root-i ' uptime '
[1] 16:05:48 [SUCCESS] 192.168.1.105
03:03:25 up + days, 13:44, 0 users, load average:0.04, 0.01, 0.00
[2] 16:05:48 [SUCCESS] 192.168.1.118
03:03:32 up, 15:27, 4 users, Load average:0.96, 0.74, 0.45
Stderr:address 192.168.1.118 maps to localhost, it is does not map back to the address-possible break-in attempt!
[3] 16:05:48 [SUCCESS] 192.168.1.109
03:03:25 up-Days, 21:56, 2 users, load average:0.02, 0.06, 0.18
Stderr:address 192.168.1.102 maps to localhost, it is does not map back to the address-possible break-in attempt!
[4] 16:05:48 [SUCCESS] 192.168.1.101
16:03:17 up + days, 23:45, 1 user, load average:0.03, 0.04, 0.01
Stderr:address 192.168.1.101 maps to localhost, it is does not map back to the address-possible break-in attempt!

b) Bulk upload of files or directories (PSCP.PSSH command)
Bulk upload local file/mnt/test.file to the/tmp directory on the remote server:
[Email protected] ~]# pscp.pssh-l root-h hosts.txt/mnt/test.file/tmp/
[1] 16:18:05 [SUCCESS] 192.168.1.105
[2] 16:18:05 [SUCCESS] 192.168.1.109
[3] 16:18:05 [SUCCESS] 192.168.1.101
[4] 16:18:05 [SUCCESS] 192.168.1.118

C) Bulk download files or directories (pslurp command)
bulk download a file on the server to the local, do not worry about the name of the problem, Because PSSH has established a directory with the name of the IP in the file list to hold the downloaded file:
[[email protected] ~]# pslurp-l root-h hosts.txt/etc/hosts .
[1] 16:32:01 [SUCCESS] 192.168.1.109
[2] 16:32:01 [SUCCESS ] 192.168.1.105
[3] 16:32:01 [SUCCESS] 192.168.1.101
[4] 16:32:01 [SUCCESS] 192.168.1.118
[[email protected] ~]# ll

d) bulk sync (prsync command)
Synchronizing files or directories in the native/mnt/test directory to the/mnt/test path of the remote machine
[Email protected] ~]# prsync-l root-h hosts.txt-r/mnt/test//mnt/test/
[1] 16:46:41 [SUCCESS] 192.168.1.109
[2] 16:46:41 [SUCCESS] 192.168.1.105
[3] 16:46:41 [SUCCESS] 192.168.1.118
[4] 16:46:41 [SUCCESS] 192.168.1.101

e) batch kill process on remote machine (Pnuke command)
Like batch kill the Nginx process on the remote machine
[Email protected] ~]# pnuke-h hosts.txt-l root Nginx
[1] 17:09:14 [SUCCESS] 192.168.1.109
[2] 17:09:14 [SUCCESS] 192.168.1.105
[3] 17:09:15 [SUCCESS] 192.168.1.118
[4] 17:09:15 [SUCCESS] 192.168.1.101

Linux Bulk management tool PSSH usage record

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.