Use pssh for parallel batch operations

Source: Internet
Author: User
Tags pscp

Original article: http://liang3391.blog.51cto.com/178205/732100

Reference: http://www.ibm.com/developerworks/cn/aix/library/au-spunix_remoteserver/index.html

If you want to execute a command to thousands of servers simultaneously, copy a file, and kill a process, what tools can be used to simplify O & M management? In small-scale use, I use for loop, which has a large quantity. On the one hand, I am not sure whether the operation is successful. On the other hand, the for loop statement has poor performance estimation and whether it is synchronous and parallel execution ., such tools include pdsh, mussh, cssh, and dsh, as well as pssh mentioned here:
1 installation:
# Wget http://peak.telecommunity.com/dist/ez_setup.py
Python ez_setup.py
# Wget http://parallel-ssh.googlecode.com/files/pssh-2.2.2.tar.gz
# Tar zxvf pssh-2.2.2.tar.gz
# Cd pssh-2.2.2
# Python setup. py install 2. Use Pssh. (For SSH Trust, see SSH command research and SSH trust details)
Pssh toolkit consists of five Program :
1 pssh multi-host Parallel Running command [ Root @ Pssh-2.2.2 ] # Pssh-p-h test.txt uptime
192.168.9.102: 14:04:58 up 26 days, 0 Users , Load average: 0.07, 0.02, 0.00
192.168.9.102: [ 1 ] 14:04:58 [ Success ] 192.168.9.102 9922
192.168.8.171: 14:04:59 up 35 days, 6 Users , Load average: 0.00, 0.00, 0.00
192.168.8.171: [ 2 ] 14:04:59 [ Success ] 192.168.8.171 22
192.168.9.104: 14:04:59 up 7 days, 0 Users , Load average: 0.10 , 0.04 , 0.01
192.168.9.104: [ 3 ] 14 : 04: 59 [ Success ] 192.168.9.104 9922
[ Root @ Pssh-2.2.2 ] # Cat test.txt
192.168.9.102: 9922
192.168.9.104: 9922
192.168.8.171: 22 // Note that my port number is not only the default 22
If you want to redirect the output to a file and add-o File Option 2 pscp Copies files to multiple hosts in parallel
Note the following: [ Root @ Pssh-2.2.2 ] # Pscp-H test.txt/etc/sysconfig/Network/tmp/network // indicates that the local/etc/sysconfig/network is uploaded to the/tmp/network of the target server 3. prsync uses the rsync protocol to synchronize data from a local computer to a remote host. [ Root @ Server ~ ] # Pssh-H test.txt-P mkdir/tmp/etc
[ Root @ Server ~ ] # Prsync-H test.txt-l dongwm-a-r/etc/sysconfig/tmp/etc // indicates recursively synchronizing the local/etc/sysconfig directory to/tmp/of the target server/ etc directory, and keep the original timestamp, use the user dongwm 4. pslurp Copies files from the remote host to the local machine, which is in the opposite direction of pscp: [ Root @ Server ~ ] # Pslurp-H test.txt-L/tmp/test-l root/tmp/network test // indicates copying the/tmp/network file of the target server to the local/tmp/test directory, and renamed it test.
[ 1 ] 14 : 53 : 54 [ Success ] 192.168.9.102 9922
[ 2 ] 14 : 53 : 54 [ Success ] 192.168.9.104 9922
[ Root @ Server ~ ] # Ll/tmp/test/192.168.9.10
192.168.9.102 / 192.168.9.104 /
[ Root @ Server ~ ] # Ll/tmp/test/192.168.9.102/
Total 4.0 K
-RW-r -- 1 Root 60 Test
[ Root @ Server ~ ] # Ll/tmp/test/192.168.9.104/
Total 4.0 K
-RW-r -- 1 Root 60 Test 5 pnuke concurrent killing processes on a remote host: [ Root @ Server ~ ] # Pnuke-H test.txt syslog // kills the syslog process of the target server, as long as the related words in the PS process can be killed
[ 1 ] 15 : 05: 14 [ Success ] 192.168.9.102 9922
[ 2 ] 15 : 05: 14 [ Success ] 192.168.9.104 9922

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.