Install and use pssh under CentOS7

Check the installation environment

pssh requires python2.4 or above. First, check the python version in CentOS. The query command is as follows:

[root@hadoop-master ~]# python --version
Python 2.7.5

If you have not installed python, you can install it by yourself "Basic Installation of Python for Beginners under Linux"

Install pssh

wget https://pypi.python.org/packages/60/9a/8035af3a7d3d1617ae2c7c174efa4f154e5bf9c24b36b623413b38be8e4a/pssh-2.3.1.tar.gz
tar xf pssh-2.3.1.tar.gz -C /usr/local/pssh/
cd /usr/local/pssh/pssh-2.3.1/
python setup.py install

View installation

[root@hadoop-master pssh-2.3.1]# pssh --help
Usage: pssh [OPTIONS] command [...]

Options:
  --version             show program's version number and exit
  --help                show this help message and exit
  -h HOST_FILE, --hosts=HOST_FILE
                        hosts file (each line "[user@]host[:port]")
  -H HOST_STRING, --host=HOST_STRING
                        additional host entries ("[user@]host[:port]")
  -l USER, --user=USER  username (OPTIONAL)
  -p PAR, --par=PAR     max number of parallel threads (OPTIONAL)
  -o OUTDIR, --outdir=OUTDIR
                        output directory for stdout files (OPTIONAL)
  -e ERRDIR, --errdir=ERRDIR
                        output directory for stderr files (OPTIONAL)
  -t TIMEOUT, --timeout=TIMEOUT
                        timeout (secs) (0 = no timeout) per host (OPTIONAL)
  -O OPTION, --option=OPTION
                        SSH option (OPTIONAL)
  -v, --verbose         turn on warning and diagnostic messages (OPTIONAL)
  -A, --askpass         Ask for a password (OPTIONAL)
  -x ARGS, --extra-args=ARGS
                        Extra command-line arguments, with processing for
                        spaces, quotes, and backslashes
  -X ARG, --extra-arg=ARG
                        Extra command-line argument
  -i, --inline          inline aggregated output and error for each server
  --inline-stdout       inline standard output for each server
  -I, --send-input      read from standard input and send as input to ssh
  -P, --print           print output as we get it

Example: pssh -h hosts.txt -l irb2 -o /tmp/foo uptime

pssh command package

Command package Features
pssh Run commands in parallel on multiple hosts
pscp Transfer files to multiple hosts, its characteristics are similar to scp
prsync Use rsync protocol from local computer to remote host
pslurp Copy files from remote host to local
pnuke kill the process of the remote machine

Parameter Description:

parameter Parameter explanation
-h The list of remote hosts to execute the command is a text file, and the host ip or host name is separated by a carriage return.
-l Username of the remote machine
-p Maximum number of connections allowed at one time (lowercase)
-The Redirect the output to a file (lowercase)
-e Execution error redirected to a file
-t Set the timeout period for command execution
-A Prompt for password and pass the password to ssh
-THE Set the specific configuration of ssh parameters, refer to the ssh_config configuration file (uppercase)
-x Pass multiple SSH commands, separate multiple commands with spaces and enclose them in quotation marks
-X Same as -x but only one command can be passed at a time
-i Display standard output and standard error after each host is executed
-I Read each input command and pass it to the ssh process to allow the command script to be passed to standard input
-P Printout (uppercase)

Command specific use

It is best to set up password-free login between servers. Refer to "Setting up password-free login between CentOS7 virtual machines".
First, edit a hosts.txt file to record the address of the host to be operated. The following is the configuration of my host. hadoop-slave2 and
hadoop-slave3 are off

[root@hadoop-master pssh]# cat hosts.text 
hadoop-slave1
hadoop-slave2
hadoop-slave3

pssh remote batch execution of commands

#-h  后面接主机ip文件,文件数据格式[user@]host[:port]
#-P  显示输出内容

Specific use

[root@hadoop-master pssh]# pssh -P -h hosts.text uptime
hadoop-slave1:  13:55:14 up 1 day,  4:03,  0 users,  load average: 0.00, 0.01, 0.05
[1] 13:55:31 [SUCCESS] hadoop-slave1
[2] 13:55:33 [FAILURE] hadoop-slave2 Exited with error code 255
[3] 13:55:33 [FAILURE] hadoop-slave3 Exited with error code 255

If you want to enter a password, you can use the following command:

[root@hadoop-master pssh]# pssh -A -h hosts.text uptime

If it is 执行长shell命令, it can be similar to the following

[root@hadoop-master pssh]# pssh -h hosts.text "source /etc/profile"
[1] 21:01:46 [SUCCESS] hadoop-slave3
[2] 21:01:46 [SUCCESS] hadoop-slave2
[3] 21:01:46 [SUCCESS] hadoop-slave1

pscp parallel transfer files to remote

Transfer files, but does not support remote new directory creation

[root@hadoop-master pssh]# pscp -r -h hosts.text ./* /usr/local
[1] 14:10:31 [SUCCESS] hadoop-slave1
[2] 14:10:34 [FAILURE] hadoop-slave2 Exited with error code 1
[3] 14:10:34 [FAILURE] hadoop-slave3 Exited with error code 1

prsync transfers files to remote in parallel

Transfer files and support remote new directory creation

[root@hadoop-master pssh]# pscp -r -h hosts.text hosts.text  /usr/local/pssh/
[1] 14:17:18 [FAILURE] hadoop-slave1 Exited with error code 1
[2] 14:17:21 [FAILURE] hadoop-slave2 Exited with error code 1
[3] 14:17:21 [FAILURE] hadoop-slave3 Exited with error code 1

Compared

[root@hadoop-master pssh]# prsync -r -h hosts.text hosts.text  /usr/local/pssh/
[1] 14:18:08 [SUCCESS] hadoop-slave1
[2] 14:18:11 [FAILURE] hadoop-slave2 Exited with error code 255
[3] 14:18:11 [FAILURE] hadoop-slave3 Exited with error code 255

pslurp pulls from remote to local

Pslurp pulls files from remote to local, automatically creates a directory named remote host ip locally, and puts the pulled files in the corresponding host IP directory
Format: pslurp -h ip.txt -L <local directory> <remote Directory/File> <local rename>

[root@hadoop-master pssh]# pslurp -h hosts.text -L /usr/local/test /usr/local/pssh/hosts.text psshtest
[1] 14:26:49 [SUCCESS] hadoop-slave1
[2] 14:26:52 [FAILURE] hadoop-slave2 Exited with error code 1
[3] 14:26:52 [FAILURE] hadoop-slave3 Exited with error code 1

This will create a folder directory based on the configured ip or host

drwxr-xr-x. 2 root root        22 8月  11 14:26 hadoop-slave1
drwxr-xr-x. 2 root root         6 8月  11 14:24 hadoop-slave2
drwxr-xr-x. 2 root root         6 8月  11 14:24 hadoop-slave3

pnuke remote batch killall

[root@hadoop-master pssh]# pnuke -h hosts.text java
[1] 14:32:04 [SUCCESS] hadoop-slave1
[2] 14:32:06 [FAILURE] hadoop-slave2 Exited with error code 255
[3] 14:32:06 [FAILURE] hadoop-slave3 Exited with error code 255

Guess you like

Origin blog.csdn.net/u011047968/article/details/107937572